File manager - Edit - /usr/local/CyberPanel/lib/python3.10/site-packages/tornado/__pycache__/gen.cpython-310.pyc
Back
o �h�{ � @ 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' ej(r�ddlm)Z)m*Z*m+Z+m,Z,m-Z- e�.d�Z/ede%e"e% e&e e%f ej0jf Z1G d d� de2�Z3G dd� de2�Z4G dd� de2�Z5G dd� de2�Z6G dd� de2�Z7dee8df de fdd�Z9defdd�Z:de!de/f d e d!e de/fd"d#�Z;e'd$e!d% de!d& fd'd(��Z<e'd$e!de/f de!d& fd)d(��Z<d$ee!d% e!de/f f de!d& fd*d(�Z<d$e de=fd+d,�Z>G d-d� de2�Z?G d.d/� d/e@�ZA 0dOd1ee"e1 e&e e1f f d2d3dd4fd5d6�ZBeBZC 0dOd1ee"e1 e&e e1f f d2d3dd4fd7d8�ZDd9e defd:d;�ZE 0dOd<eeFejGf d=e1d2d3defd>d?�ZHd@eFddAfdBdC�ZIG dDdE� dEe@�ZJe�KeeJ� �ZLe�KeeJ� �ZMdFeM_ G dGdH� dHe@�ZNdIe%defdJdK�ZOdLe1defdMdN�ZPe eP�ZPdS )Pa` ``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") .. testoutput:: :hide: 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'] .. testoutput:: :hide: 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) �Union�Any�Callable�List�Type�Tuple� Awaitable�Dict�overload)�Sequence�Deque�Optional�Set�Iterable�_Tc @ � e Zd ZdS )� KeyReuseErrorN��__name__� __module__�__qualname__� r# r# �A/usr/local/CyberPanel/lib/python3.10/site-packages/tornado/gen.pyr p � r c @ r )�UnknownKeyErrorNr r# r# r# r$ r&