File: //opt/saltstack/salt/lib/python3.10/site-packages/tornado/__pycache__/gen.cpython-310.pyc
o
;j| �
@ s$ d Z ddlZddlZddlZddlmZ ddlZddlZddl Z ddl m
Z
ddlmZ ddl
Z
ddlZddlmZmZmZmZmZmZ ddlmZ ddlmZ dd lmZ zddlZW n eyg dZY nw ddlZdd
lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ej*r�ddlm+Z+m,Z,m-Z-m.Z. e�/d�Z0e de&e#e& e'e!e&f ej1jf Z2G d
d� de3�Z4G dd� de3�Z5G dd� de3�Z6G dd� de3�Z7G dd� de3�Z8de e9df de!fdd�Z:defdd�Z;de"de0f d e!d!e!de0fd"d#�Z<e)d$e"d% de"d& fd'd(��Z=e)d$e"de0f de"d& fd)d(��Z=d$e e"d% e"de0f f de"d& fd*d(�Z=d$e!de>fd+d,�Z?G d-d� de3�Z@G d.d/� d/�ZAe) 0dQd1e(e2 d2e e$e3 e%e$e3 df f dee# fd3d4��ZBe) 0dQd1ee!e2f d2e e$e3 e%e$e3 df f dee' fd5d4��ZB 0dQd1e e(e2 ee!e2f f d2d6dd7fd8d4�ZBeBZC 0dQd1e e(e2 ee!e2f f d2d6dd7fd9d:�ZDd;e!defd<d=�ZE 0dQd>e eFejGf d?e2d2d6defd@dA�ZHdBeFddCfdDdE�ZIG dFdG� dG�ZJe�KeeJ� �ZLe�KeeJ� �ZMdHeM_ G dIdJ� dJ�ZNdKe&defdLdM�ZOdNe2defdOdP�ZPe
eP�ZPdS )Ra* ``tornado.gen`` implements generator-based coroutines.
.. note::
The "decorator and generator" approach in this module is a
precursor to native coroutines (using ``async def`` and ``await``)
which were introduced in Python 3.5. Applications that do not
require compatibility with older versions of Python should use
native coroutines instead. Some parts of this module are still
useful with native coroutines, notably `multi`, `sleep`,
`WaitIterator`, and `with_timeout`. Some of these functions have
counterparts in the `asyncio` module which may be used as well,
although the two may not necessarily be 100% compatible.
Coroutines provide an easier way to work in an asynchronous
environment than chaining callbacks. Code using coroutines is
technically asynchronous, but it is written as a single generator
instead of a collection of separate functions.
For example, here's a coroutine-based handler:
.. 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")
Asynchronous functions in Tornado return an ``Awaitable`` or `.Future`;
yielding this object returns its result.
You can also yield a list or dict of other yieldable objects, 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']
If ``tornado.platform.twisted`` is imported, it is also possible to
yield Twisted's ``Deferred`` objects. 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``.
� N)� Generator)�singledispatch)�isawaitable)�Future� is_future�chain_future�future_set_exc_info�future_add_done_callback�"future_set_result_unless_cancelled)�IOLoop)�app_log)�TimeoutError)�Mapping�Union�Any�Callable�List�Type�Tuple� Awaitable�Dict�Sequence�overload)�Deque�Optional�Set�Iterable�_Tc @ � e Zd ZdS )�
KeyReuseErrorN��__name__�
__module__�__qualname__� r$ r$ �?/opt/saltstack/salt/lib/python3.10/site-packages/tornado/gen.pyr v � r c @ r )�UnknownKeyErrorNr r$ r$ r$ r% r'