
    Mhz              	       D   d Z ddlZddlZddlZddlmZ ddlZddlZddl	Z	ddl	m
Z
 ddlmZ ddlZddlZddlmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZ 	 ddlZn# e$ r dZY nw xY wddlZdd
lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ej*        rddlm+Z+m,Z,m-Z-m.Z.  ej/        d          Z0e de&e#e&         e'e!e&f         ej1        j        f         Z2 G d de3          Z4 G d de3          Z5 G d de3          Z6 G d de3          Z7 G d de3          Z8de e9df         de!fdZ:defdZ;de"de0f         de!de!de0fd Z<e)d!e"d"         de"d#         fd$            Z=e)d!e"de0f         de"d#         fd%            Z=d!e e"d"         e"de0f         f         de"d#         fd&Z=d!e!de>fd'Z? G d( de3          Z@ G d) d*          ZA	 dCd,e e(e2         ee!e2f         f         d-d.dd/fd0ZBeBZC	 dCd,e e(e2         ee!e2f         f         d-d.dd/fd1ZDd2e!defd3ZE	 dCd4e eFejG        f         d5e2d-d.defd6ZHd7eFdd8fd9ZI G d: d;          ZJ ejK        e eJ                      ZL ejK        e eJ                      ZMd<eM_          G d= d>          ZNd?e&defd@ZOdAe2defdBZP e
eP          ZPdS )Da*	  ``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 Zd ZdS )KeyReuseErrorN__name__
__module____qualname__     K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/gen.pyr    r    v           Dr&   r    c                       e Zd ZdS )UnknownKeyErrorNr!   r%   r&   r'   r*   r*   z   r(   r&   r*   c                       e Zd ZdS )LeakedCallbackErrorNr!   r%   r&   r'   r,   r,   ~   r(   r&   r,   c                       e Zd ZdS )BadYieldErrorNr!   r%   r&   r'   r.   r.      r(   r&   r.   c                       e Zd ZdS )ReturnValueIgnoredErrorNr!   r%   r&   r'   r0   r0      r(   r&   r0   eReturnreturnc                 ~    	 | j         S # t          $ r Y nw xY w	 | j        d         S # t          t          f$ r Y d S w xY w)Nr   )valueAttributeErrorargs
IndexError)r1   s    r'   _value_from_stopiterationr9      sj     w    vayJ'   tts   	 
' <<c                      t                      } t          | dd          }|r |d         d         }|t          k    r|d= nn| | S )N_source_tracebackr%   r   )r   getattr__file__)futuresource_tracebackfilenames      r'   _create_futurerB      sa    XXFv':B??
  $B'*x $$   Mr&   f.r7   kwc                      | |i |S Nr%   )rC   r7   rD   s      r'   _fake_ctx_runrG      s    1d>b>>r&   func).zGenerator[Any, Any, _T]).
Future[_T]c                     d S rF   r%   rH   s    r'   	coroutinerL      s	     #&#r&   c                     d S rF   r%   rK   s    r'   rL   rL      s    GJsr&   c                 b     t          j                    fd            } |_        d|_        |S )a>  Decorator for asynchronous generators.

    For compatibility with older versions of Python, coroutines may
    also "return" by raising the special exception `Return(value)
    <Return>`.

    Functions with this decorator return a `.Future`.

    .. warning::

       When exceptions occur inside a coroutine, the exception
       information will be stored in the `.Future` object. You must
       examine the result of the `.Future` object, or the exception
       may go unnoticed by your code. This means yielding the function
       if called from another coroutine, using something like
       `.IOLoop.run_sync` for top-level calls, or passing the `.Future`
       to `.IOLoop.add_future`.

    .. versionchanged:: 6.0

       The ``callback`` argument was removed. Use the returned
       awaitable object instead.

    c                     t                      }t          t          j                    j        }nt          }	  |g| R i |}t          |t                    r	  |t          |          }t          ||||          |	                    fd           ng# t          t          f$ r'}t          |t          |                     Y d }~n4d }~wt          $ r$ t          |t!          j                               Y nw xY wd }	 |d }S # d }w xY wne# t          t          f$ r}t          |          }Y d }~n@d }~wt          $ r0 t          |t!          j                               	 |d }cY S # d }w xY ww xY wt          ||           |S )Nc                     S rF   r%   )_runners    r'   <lambda>z,coroutine.<locals>.wrapper.<locals>.<lambda>   s    v r&   )rB   contextvarscopy_contextrunrG   
isinstancer   nextRunneradd_done_callbackStopIterationr2   r   r9   	Exceptionr	   sysexc_info)	r7   kwargsr?   ctx_runresultyieldedr1   rR   rH   s	          @r'   wrapperzcoroutine.<locals>.wrapper   s   
  !!"!.004GG#G1	"WT3D333F33F &),, %"?%gdF33G  $GVVWEEF,,-=-=-=-=>>>>! &v.   6 9! < <        ! @ @ @'?????@ "! "FFTFMMMMK%" & 	2 	2 	2.q11FFFFFF 	 	 	777 	\ 	+66:::sY   D B C;(C

.C;:C;D D	E/D22.E/!E'"E/'E++E/T)	functoolswraps__wrapped____tornado_coroutine__)rH   rc   s   ` r'   rL   rL      sK    8 _T< < < < <| G$(G!Nr&   c                 $    t          | dd          S )zReturn whether *func* is a coroutine function, i.e. a function
    wrapped with `~.gen.coroutine`.

    .. versionadded:: 4.5
    rg   F)r=   rK   s    r'   is_coroutine_functionri     s     40%888r&   c                   .     e Zd ZdZddeddf fdZ xZS )r2   a&  Special exception to return a value from a `coroutine`.

    This exception exists for compatibility with older versions of
    Python (before 3.3). In newer code use the ``return`` statement
    instead.

    If this exception is raised, its value argument is used as the
    result of the coroutine::

        @gen.coroutine
        def fetch_json(url):
            response = yield AsyncHTTPClient().fetch(url)
            raise gen.Return(json_decode(response.body))

    By analogy with the return statement, the value argument is optional.
    Nr5   r3   c                 f    t                                                       || _        |f| _        d S rF   )super__init__r5   r7   )selfr5   	__class__s     r'   rm   zReturn.__init__1  s-    
H			r&   rF   )r"   r#   r$   __doc__r   rm   __classcell__)ro   s   @r'   r2   r2     sZ         " c T          r&   c                       e Zd ZdZi ZdededdfdZdefdZdefdZ	d	eddfd
Z
d	edefdZdej        fdZdefdZdS )WaitIteratora  Provides an iterator to yield the results of awaitables as they finish.

    Yielding a set of awaitables like this:

    ``results = yield [awaitable1, awaitable2]``

    pauses the coroutine until both ``awaitable1`` and ``awaitable2``
    return, and then restarts the coroutine with the results of both
    awaitables. If either awaitable raises an exception, the
    expression will raise that exception and all the results will be
    lost.

    If you need to get the result of each awaitable as soon as possible,
    or if you need the result of some awaitables even if others produce
    errors, you can use ``WaitIterator``::

      wait_iterator = gen.WaitIterator(awaitable1, awaitable2)
      while not wait_iterator.done():
          try:
              result = yield wait_iterator.next()
          except Exception as e:
              print("Error {} from {}".format(e, wait_iterator.current_future))
          else:
              print("Result {} received from {} at {}".format(
                  result, wait_iterator.current_future,
                  wait_iterator.current_index))

    Because results are returned as soon as they are available the
    output from the iterator *will not be in the same order as the
    input arguments*. If you need to know which future produced the
    current result, you can use the attributes
    ``WaitIterator.current_future``, or ``WaitIterator.current_index``
    to get the index of the awaitable from the input list. (if keyword
    arguments were used in the construction of the `WaitIterator`,
    ``current_index`` will use the corresponding keyword).

    `WaitIterator` implements the async iterator
    protocol, so it can be used with the ``async for`` statement (note
    that in this version the entire iteration is aborted if any value
    raises an exception, while the previous example can continue past
    individual errors)::

      async for result in gen.WaitIterator(future1, future2):
          print("Result {} received from {} at {}".format(
              result, wait_iterator.current_future,
              wait_iterator.current_index))

    .. versionadded:: 4.1

    .. versionchanged:: 4.3
       Added ``async for`` support in Python 3.5.

    r7   r_   r3   Nc                    |r|rt          d          |rEd |                                D             | _        t          |                                          }n d t          |          D             | _        |}t          j                    | _        d | _	        d | _
        d | _        |D ]}t          || j                   d S )Nz)You must provide args or kwargs, not bothc                     i | ]\  }}||	S r%   r%   ).0krC   s      r'   
<dictcomp>z)WaitIterator.__init__.<locals>.<dictcomp>v  s    BBB!Q1BBBr&   c                     i | ]\  }}||	S r%   r%   )rv   irC   s      r'   rx   z)WaitIterator.__init__.<locals>.<dictcomp>y  s    CCC!Q1CCCr&   )
ValueErroritems_unfinishedlistvalues	enumeratecollectionsdeque	_finishedcurrent_indexcurrent_future_running_futurer
   _done_callback)rn   r7   r_   futuresr?   s        r'   rm   zWaitIterator.__init__q  s     	JF 	JHIII 	BB6<<>>BBBD6==??++GGCC9T??CCCDG$*,,!"# 	B 	BF$VT-@AAAA	B 	Br&   c                 B    | j         s| j        rdS dx| _        | _        dS )z2Returns True if this iterator has no more results.FNT)r   r}   r   r   rn   s    r'   donezWaitIterator.done  s0    > 	T- 	5377T0tr&   c                     t                      | _        | j        r,|                     | j                                                  S | j        S )zReturns a `.Future` that will yield the next available result.

        Note that this `.Future` will not be the same object as any of
        the inputs.
        )r   r   r   _return_resultpopleftr   s    r'   rX   zWaitIterator.next  sF      &xx> 	A&&t~'='='?'?@@@##r&   r   c                     | j         r0| j                                         s|                     |           d S | j                            |           d S rF   )r   r   r   r   append)rn   r   s     r'   r   zWaitIterator._done_callback  sY     	((<(A(A(C(C 	(%%%%%N!!$'''''r&   c                     | j         t          d          t          || j                    | j         }d| _         || _        | j                            |          | _        |S )zCalled set the returned future's state that of the future
        we yielded, and set the current future for the iterator.
        Nzno future is running)r   r\   r   r   r}   popr   )rn   r   ress      r'   r   zWaitIterator._return_result  se     '2333T4/000"#"!-11$77
r&   c                     | S rF   r%   r   s    r'   	__aiter__zWaitIterator.__aiter__  s    r&   c                     |                                  r t          t          d                      |                                 S )NStopAsyncIteration)r   r=   builtinsrX   r   s    r'   	__anext__zWaitIterator.__anext__  s9    99;; 	<9'($899;;;yy{{r&   )r"   r#   r$   rp   r}   r   rm   boolr   rX   r   r   typingAsyncIteratorr   r   r%   r&   r'   rs   rs   8  s	       4 4l KBf B B4 B B B B&d    $f $ $ $ $(6 (d ( ( ( (6 f    6/    6      r&   rs   r%   childrenquiet_exceptionsz3Union[Type[Exception], Tuple[Type[Exception], ...]]z!Union[Future[List], Future[Dict]]c                 $    t          | |          S )a  Runs multiple asynchronous operations in parallel.

    ``children`` may either be a list or a dict whose values are
    yieldable objects. ``multi()`` returns a new yieldable
    object that resolves to a parallel structure containing their
    results. If ``children`` is a list, the result is a list of
    results in the same order; if it is a dict, the result is a dict
    with the same keys.

    That is, ``results = yield multi(list_of_futures)`` is equivalent
    to::

        results = []
        for future in list_of_futures:
            results.append(yield future)

    If any children raise exceptions, ``multi()`` will raise the first
    one. All others will be logged, unless they are of types
    contained in the ``quiet_exceptions`` argument.

    In a ``yield``-based coroutine, it is not normally necessary to
    call this function directly, since the coroutine runner will
    do it automatically when a list or dict is yielded. However,
    it is necessary in ``await``-based coroutines, or to pass
    the ``quiet_exceptions`` argument.

    This function is available under the names ``multi()`` and ``Multi()``
    for historical reasons.

    Cancelling a `.Future` returned by ``multi()`` does not cancel its
    children. `asyncio.gather` is similar to ``multi()``, but it does
    cancel its children.

    .. versionchanged:: 4.2
       If multiple yieldables fail, any exceptions after the first
       (which is raised) will be logged. Added the ``quiet_exceptions``
       argument to suppress this logging for selected exception types.

    .. versionchanged:: 4.3
       Replaced the class ``Multi`` and the function ``multi_future``
       with a unified function ``multi``. Added support for yieldables
       other than ``YieldPoint`` and `.Future`.

    )r   )multi_future)r   r   s     r'   multir     s    ` 3CDDDDr&   c                 ,  	 t          | t                    r6t          |                                           |                                 }nd| }t          t          t          |                    t          d D                       sJ t                    	t                      st          i ng            dt          ddf	fd}t                      }D ]+}||vr%|                    |           t          ||           ,S )a  Wait for multiple asynchronous futures in parallel.

    Since Tornado 6.0, this function is exactly the same as `multi`.

    .. versionadded:: 4.0

    .. versionchanged:: 4.2
       If multiple ``Futures`` fail, any exceptions after the first (which is
       raised) will be logged. Added the ``quiet_exceptions``
       argument to suppress this logging for selected exception types.

    .. deprecated:: 4.3
       Use `multi` instead.
    Nc              3   ^   K   | ](}t          |          pt          |t                    V  )d S rF   )r   rW   _NullFuture)rv   rz   s     r'   	<genexpr>zmulti_future.<locals>.<genexpr>  s7      QQay||9z![99QQQQQQr&   futr3   c           	      (                        |            sg }D ]}	 |                    |                                           +# t          $ rf}                                r't          |          st          j        dd           n!t          t          j
                               Y d }~d }~ww xY w                                sC-t          t          t          |                               d S t          |           d S d S d S )Nz!Multiple exceptions in yield listTr^   )remover   ra   r\   r   rW   r   errorr	   r]   r^   r   dictzip)	r   result_listrC   r1   children_futsr?   keysr   unfinished_childrens	       r'   callbackzmulti_future.<locals>.callback  sZ   ""3'''" 	LK" 
D 
D	D&&qxxzz2222  D D D{{}} D)!-=>> #M Cd    ,FCLNNCCCD ;;== L#6S{%;%; < <     7v{KKKKK'	L 	LL Ls   'A
B8AB33B8)rW   r   r~   r   r   mapconvert_yieldedallsetrB   r   r   addr
   )
r   r   children_seqr   	listeningrC   r   r?   r   r   s
    `    @@@@r'   r   r     sY   $ (D!!  HMMOO$$((_l;;<<MQQ=QQQQQQQQm,,F S*69I22rRRRLf L L L L L L L L L L L. I 2 2IMM!$Q111Mr&   xc                 n    t          |           r| S t                      }|                    |            |S )a  Converts ``x`` into a `.Future`.

    If ``x`` is already a `.Future`, it is simply returned; otherwise
    it is wrapped in a new `.Future`.  This is suitable for use as
    ``result = yield gen.maybe_future(f())`` when you don't know whether
    ``f()`` returns a `.Future` or not.

    .. deprecated:: 4.3
       This function only handles ``Futures``, not other yieldable objects.
       Instead of `maybe_future`, check for the non-future result types
       you expect (often just ``None``), and ``yield`` anything unknown.
    )r   rB   
set_result)r   r   s     r'   maybe_futurer   -  s9     || q
r&   timeoutr?   c                 t   t          |          t                      t                     t          j                    dt
          ddffddfd}                    | |          t          t
                    rt          fd           n	                    fd           S )	a  Wraps a `.Future` (or other yieldable object) in a timeout.

    Raises `tornado.util.TimeoutError` if the input future does not
    complete before ``timeout``, which may be specified in any form
    allowed by `.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or
    an absolute time relative to `.IOLoop.time`)

    If the wrapped `.Future` fails after it has timed out, the exception
    will be logged unless it is either of a type contained in
    ``quiet_exceptions`` (which may be an exception type or a sequence of
    types), or an ``asyncio.CancelledError``.

    The wrapped `.Future` is not canceled when the timeout expires,
    permitting it to be reused. `asyncio.wait_for` is similar to this
    function but it does cancel the wrapped `.Future` on timeout.

    .. versionadded:: 4.0

    .. versionchanged:: 4.1
       Added the ``quiet_exceptions`` argument and the logging of unhandled
       exceptions.

    .. versionchanged:: 4.4
       Added support for yieldable objects other than `.Future`.

    .. versionchanged:: 6.0.3
       ``asyncio.CancelledError`` is now always considered "quiet".

    .. versionchanged:: 6.2
       ``tornado.util.TimeoutError`` is now an alias to ``asyncio.TimeoutError``.

    r?   r3   Nc                     	 |                                   d S # t          j        $ r Y d S t          $ r8}t	          |          st          j        d| d           Y d }~d S Y d }~d S d }~ww xY w)Nz$Exception in Future %r after timeoutTr   )ra   asyncioCancelledErrorr\   rW   r   r   )r?   r1   r   s     r'   error_callbackz$with_timeout.<locals>.error_callbackq  s    	MMOOOOO% 	 	 	DD 	 	 	a!122 :FT              	s    A,	A,'A''A,c                                                       s"                    t          d                     t                      d S )NTimeout)r   set_exceptionr   r
   )r   future_convertedra   s   r'   timeout_callbackz&with_timeout.<locals>.timeout_callback|  sF    {{}} 	:  i!8!8999 !1>BBBBBr&   c                 .                                   S rF   remove_timeoutr?   io_looptimeout_handles    r'   rS   zwith_timeout.<locals>.<lambda>      W-C-CN-S-S r&   c                 .                                   S rF   r   r   s    r'   rS   zwith_timeout.<locals>.<lambda>  r   r&   r3   N)
r   rB   r   r   currentr   add_timeoutrW   r
   
add_future)	r   r?   r   r   r   r   r   ra   r   s	     ` @@@@@r'   with_timeoutr   B  s'   T 'v..F!6***nG	v 	$ 	 	 	 	 	 	C C C C C C C C ((2BCCN"F++ 
 	!SSSSS	
 	
 	
 	
 	SSSSS	
 	
 	
 Mr&   durationzFuture[None]c                 x    t                      t          j                                        | fd           S )a  Return a `.Future` that resolves after the given number of seconds.

    When used with ``yield`` in a coroutine, this is a non-blocking
    analogue to `time.sleep` (which should not be used in coroutines
    because it is blocking)::

        yield gen.sleep(0.5)

    Note that calling this function on its own does nothing; you must
    wait on the `.Future` it returns (usually by yielding it).

    .. versionadded:: 4.1
    c                  $    t           d           S rF   )r   )rC   s   r'   rS   zsleep.<locals>.<lambda>  s    <QEE r&   )rB   r   r   
call_later)r   rC   s    @r'   sleepr     sF     	A
NEEEE   Hr&   c                   &    e Zd ZdZddZdefdZdS )r   a  _NullFuture resembles a Future that finished with a result of None.

    It's not actually a `Future` to avoid depending on a particular event loop.
    Handled as a special case in the coroutine runner.

    We lie and tell the type checker that a _NullFuture is a Future so
    we don't have to leak _NullFuture into lots of public APIs. But
    this means that the type checker can't warn us when we're passing
    a _NullFuture into a code path that doesn't understand what to do
    with it.
    r3   Nc                     d S rF   r%   r   s    r'   ra   z_NullFuture.result      tr&   c                     dS )NTr%   r   s    r'   r   z_NullFuture.done  r   r&   r   )r"   r#   r$   rp   ra   r   r   r%   r&   r'   r   r     sM        
 
   d      r&   r   a  A special object which may be yielded to allow the IOLoop to run for
one iteration.

This is not needed in normal use but it can be helpful in long-running
coroutines that are likely to yield Futures that are ready instantly.

Usage: ``yield gen.moment``

In native coroutines, the equivalent of ``yield gen.moment`` is
``await asyncio.sleep(0)``.

.. versionadded:: 4.0

.. deprecated:: 4.5
   ``yield None`` (or ``yield`` with no argument) is now equivalent to
    ``yield gen.moment``.
c            
       t    e Zd ZdZdedddddedd	f
d
ZddZdedefdZ	de
e         dedej        defdZd	S )rY   zInternal implementation of `tornado.gen.coroutine`.

    Maintains information about pending callbacks and their results.

    The results of the generator are stored in ``result_future`` (a
    `.Future`)
    r`   genzGenerator[_Yieldable, Any, _T]result_futurerI   first_yieldedr3   Nc                    || _         || _        || _        t          | _        d| _        d| _        t          j                    | _	        |                      | j
        |          r"d x}x}}|                      | j                   d S d S )NF)r`   r   r   _null_futurer?   runningfinishedr   r   r   handle_yieldrV   )rn   r`   r   r   r   s        r'   rm   zRunner.__init__  s     *"~''<<)=99 	#266C6--LL"""""	# 	#r&   c                 n   | j         s| j        rdS 	 d| _         	 | j        }|t          d          |                                s
	 d| _         dS d| _        	 	 |                                }d}n# t          $ r}|}Y d}~nd}~ww xY wd}n# d}w xY w|#	 | j                            |          }~n # ~w xY w| j                            |          }n# t          t          f$ rN}d| _        t          | _        t          | j        t          |                     d| _        Y d}~d| _         dS d}~wt          $ rK d| _        t          | _        t          | j        t!          j                               d| _        Y d| _         dS w xY w|                     |          s
	 d| _         dS d}# d| _         w xY w)zkStarts or resumes the generator, running until it reaches a
        yield point that is not ready.
        NTzNo pending futureF)r   r   r?   r\   r   ra   r   throwsendr[   r2   r   r   r   r9   r	   r]   r^   r   )rn   r?   r5   excr1   rb   s         r'   rV   z
Runner.run  s2    < 	4= 	F2	!DL.>#$7888{{}} V !DLLLU #$
& & # % 5 5 5 45	5 "&$&*hnnS&9&9G !$GGGG"&(--"6"6%v.   $(DM".DK6*,Ea,H,H   *.D&FFF !DLLL !   $(DM".DK'(:CLNNKKK)-D&
 !DLLL ((11  !DLLL ].` !DL    s   4F+ F+ A0 -B 0
B:B<B BB 	C BC B2 0C 2B55C F+ F$<D- F+ -AF:F+ FF+ 'F+ +	F4rb   c                     	 t          |           _        nI# t          $ r< t                       _        t	           j        t          j                               Y nw xY w j        t          u r' j        	                     j
         j                   dS  j        t          d           j                                        s1dt          dd f fd} j                             j        |           dS dS )NFzno pending futurerC   r3   c                 @    d }                      j                   d S rF   )r`   rV   )rC   rn   s    r'   innerz"Runner.handle_yield.<locals>.inner8  s"    TX&&&&&r&   T)r   r?   r.   r   r	   r]   r^   momentr   add_callbackr`   rV   r\   r   r   r   )rn   rb   r   s   `  r'   r   zRunner.handle_yield*  s   	=)'22DKK 	= 	= 	= ((DKS\^^<<<<<	= ;&  L%%dlDH===5[ /000!!## 	' ' ' ' ' ' ' '
 L##DK7775ts    AAAtypr5   tbc                     | j         sN| j        sGt                      | _        t	          | j        |||f           |                     | j                   dS dS )NTF)r   r   r   r?   r	   r`   rV   )rn   r   r5   r   s       r'   handle_exceptionzRunner.handle_exceptionA  sY     | 	DM 	 ((DKc5"-=>>>LL"""45r&   r   )r"   r#   r$   rp   r   
_Yieldablerm   rV   r   r   r   r\   typesTracebackTyper   r%   r&   r'   rY   rY     s         ## .# $	#
 "# 
# # # #$8! 8! 8! 8!tJ 4    .		?	+4	:?:M			 	 	 	 	 	r&   rY   	awaitablec                     t          j        |           }t          j                                        |           |                    fd           |S )Nc                 .                         |           S rF   )_unregister_task)rC   loops    r'   rS   z!_wrap_awaitable.<locals>.<lambda>V  s    D$9$9!$<$< r&   )r   ensure_futurer   r   _register_taskrZ   )r   r   r   s     @r'   _wrap_awaitabler   M  sY    
 
	
*
*C>D<<<<===Jr&   rb   c                 N   | 	| t           u rt           S | t          u rt          S t          | t          t          f          rt          |           S t          |           rt          j        t          |           S t          |           rt          |           S t          d|           )a?  Convert a yielded object into a `.Future`.

    The default implementation accepts lists, dictionaries, and
    Futures. This has the side effect of starting any coroutines that
    did not start themselves, similar to `asyncio.ensure_future`.

    If the `~functools.singledispatch` library is available, this function
    may be extended to support additional types. For example::

        @convert_yielded.register(asyncio.Future)
        def _(asyncio_future):
            return tornado.platform.asyncio.to_tornado_future(asyncio_future)

    .. versionadded:: 4.1

    Nzyielded unknown object )r   r   rW   r~   r   r   r   r   castr   r   r   r.   )rb   s    r'   r   r   Z  s    " 'V++	L	 	 	GdD\	*	* CW~~	7		 C{67+++	W		 Cw'''AgAABBBr&   )r%   )Qrp   r   r   r   collections.abcr   concurrent.futures
concurrentdatetimerd   r   inspectr   r]   r   tornado.concurrentr   r   r   r	   r
   r   tornado.ioloopr   tornado.logr   tornado.utilr   rT   ImportErrorr   r   r   r   r   r   r   r   r   r   r   r   TYPE_CHECKINGr   r   r   r   TypeVarr   r   r   r\   r    r*   r,   r.   r0   r[   r9   rB   rG   rL   r   ri   r2   rs   r   Multir   r   float	timedeltar   r   r   r   r   r   rY   r   r   r%   r&   r'   <module>r     s#  = =~       % % % % % %          $ $ $ $ $ $       



                 " ! ! ! ! !       % % % % % %   KKK                           
 6555555555555V^D)T)_d3	>&:J<N<UU

	 	 	 	 	I 	 	 		 	 	 	 	i 	 	 		 	 	 	 	) 	 	 		 	 	 	 	I 	 	 		 	 	 	 	i 	 	 	}h'>!? C        Xc2g& s # "     
&
1
2& & & & 
&
 
 JHS"W% J(3D*E J J J 
 J]
78(37:KK
L] ] ] ] ]@9 9 9 9 9 9    Y   2} } } } } } } }D OQ0E 0EHZ('#z/*BBC0EK0E )0E 0E 0E 0Ef 	
 OQ< <HZ('#z/*BBC<K< )< < < <~C F    0 OQN N5(,,-NN LN 	N N N NbE n    *       . v{6;;==11	V[[]]	+	+&u u u u u u u up
y 
V 
 
 
 
CZ CF C C C C> !.11s   A A'&A'