File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/ext/tornado/__pycache__/gen.cpython-310.pyc
o
�N�g�� � @ s� d Z ddlmZmZmZ ddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
m mZ ddlmZmZmZmZ ddlmZ ddlmZ ddl
mZ ddlmZmZ zzdd lmZ W n eys dd lmZ Y nw W n ey� d
ejvr�� dZY nw z2zddl m!Z" W n ey� ddl#m!Z" Y nw zddl$m%Z% W n ey� ddl#m%Z% Y nw W n ey� d
ejvrƂ dd
lm"Z" dd� Z%Y nw er�ddl&Z&nddl'Z&G dd� de(�Z)G dd� de(�Z*G dd� de(�Z+G dd� de(�Z,G dd� de(�Z-G dd� de(�Z.dd� Z/dd� Z0dTd!d"�Z1e�2� Z3d#d$� Z4d%d&� Z5G d'd(� d(e(�Z6G d)d*� d*e7�Z8G d+d,� d,e7�Z9G d-d.� d.e9�Z:G d/d0� d0e9�Z;G d1d2� d2e9�Z<d3d4� Z=G d5d6� d6e9�Z>d7d8� Z?dUd:d;�Z@e@ZAG d<d=� d=e9�ZBdUd>d?�ZCd@dA� ZDdVdBdC�ZEdDdE� ZFe� ZGeG�Hd� e� ZIdFeI_ eI�Hd� G dGdH� dHe7�ZJe�KdIdJdKg�ZLdLdM� ZMe jNdNk�r�eOe
�PdO�� ne1dPdQ� �ZQdRdS� ZRedu�r�eeR�ZRzddlSZTW n e�y� Y dS w e dS dS )Wa� ``tornado.gen`` is a generator-based interface to make it easier to
work in an asynchronous environment. Code using the ``gen`` module
is technically asynchronous, but it is written as a single generator
instead of a collection of separate functions.
For example, the following asynchronous handler:
.. testcode::
class AsyncHandler(RequestHandler):
@asynchronous
def get(self):
http_client = AsyncHTTPClient()
http_client.fetch("http://example.com",
callback=self.on_fetch)
def on_fetch(self, response):
do_something_with_response(response)
self.render("template.html")
.. testoutput::
:hide:
could be written with ``gen`` as:
.. testcode::
class GenAsyncHandler(RequestHandler):
@gen.coroutine
def get(self):
http_client = AsyncHTTPClient()
response = yield http_client.fetch("http://example.com")
do_something_with_response(response)
self.render("template.html")
.. testoutput::
:hide:
Most asynchronous functions in Tornado return a `.Future`;
yielding this object returns its `~.Future.result`.
You can also yield a list or dict of ``Futures``, which will be
started at the same time and run in parallel; a list or dict of results will
be returned when they are all finished:
.. testcode::
@gen.coroutine
def get(self):
http_client = AsyncHTTPClient()
response1, response2 = yield [http_client.fetch(url1),
http_client.fetch(url2)]
response_dict = yield dict(response3=http_client.fetch(url3),
response4=http_client.fetch(url4))
response3 = response_dict['response3']
response4 = response_dict['response4']
.. testoutput::
:hide:
If the `~functools.singledispatch` library is available (standard in
Python 3.4, available via the `singledispatch
<https://pypi.python.org/pypi/singledispatch>`_ package on older
versions), additional types of objects may be yielded. Tornado includes
support for ``asyncio.Future`` and Twisted's ``Deferred`` class when
``tornado.platform.asyncio`` and ``tornado.platform.twisted`` are imported.
See the `convert_yielded` function to extend this mechanism.
.. versionchanged:: 3.2
Dict support added.
.. versionchanged:: 4.1
Support added for yielding ``asyncio`` Futures and Twisted Deferreds
via ``singledispatch``.
� )�absolute_import�division�print_functionN)�Future�TracebackFuture� is_future�chain_future)�IOLoop)�app_log)�
stack_context)�PY3�raise_exc_info)�singledispatchZAPPENGINE_RUNTIME)� Generator)�isawaitable)�
GeneratorTypec C � dS �NF� )�xr r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/ext/tornado/gen.pyr � � r c @ � e Zd ZdS )�
KeyReuseErrorN��__name__�
__module__�__qualname__r r r r r � � r c @ r )�UnknownKeyErrorNr r r r r r � r r c @ r )�LeakedCallbackErrorNr r r r r r � r r c @ r )�
BadYieldErrorNr r r r r r! � r r! c @ r )�ReturnValueIgnoredErrorNr r r r r r"