
    h!                     r   S r SSKrSSKJr  SSKrSSKrSSKrSSKJr  SSK	r	SSK	J
r
JrJrJrJr  \	R                  " S5      r " S S\5      r\R&                  r\R&                  \4rS	\
S
\4S jr " S S\R.                  5      r\" 5       rS\
S\
S
\4S jr\" 5       rS\S   S\S   S
S4S jrSSS\S
S4S jrSSS\S
S4S jr SSS\\\!   \\   \\RD                     4   S
S4S jr#\	RH                  SSS\S/S4   S
S4S j5       r%\	RH                  SS S\S /S4   S
S4S! j5       r%SSS\S"   S
S4S# jr%g)$a  Utilities for working with ``Future`` objects.

Tornado previously provided its own ``Future`` class, but now uses
`asyncio.Future`. This module contains utility functions for working
with `asyncio.Future` in a way that is backwards-compatible with
Tornado's old ``Future`` implementation.

While this module is an important part of Tornado's internal
implementation, applications rarely need to interact with it
directly.

    N)futures)app_log)AnyCallableOptionalTupleUnion_Tc                       \ rS rSrSrg)ReturnValueIgnoredError*    N)__name__
__module____qualname____firstlineno____static_attributes__r       eC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\tornado/concurrent.pyr   r   *   s    r   r   xreturnc                 "    [        U [        5      $ N)
isinstanceFUTURES)r   s    r   	is_futurer   4   s    a!!r   c                       \ rS rSrS\S\4   S\S\SS4S jr\R                  S	:  a  SS
\
S\
SS4S jjrSrgSS
\
SS4S jjrSrg)DummyExecutor8   fn.argskwargsr   futures.Future[_T]c                     [         R                  " 5       n [        XA" U0 UD65        U$ ! [         a#    [	        U[
        R                  " 5       5         U$ f = fr   )r   Future"future_set_result_unless_cancelled	Exceptionfuture_set_exc_infosysexc_info)selfr    r!   r"   futures        r   submitDummyExecutor.submit9   sV     !	8.vr47J67JK   	87	8s   * )AA)   	   waitcancel_futuresNc                     g r   r   )r+   r1   r2   s      r   shutdownDummyExecutor.shutdownE       r   c                     g r   r   )r+   r1   s     r   r4   r5   J   r6   r   r   )TF)T)r   r   r   r   r   r
   r   r-   r)   version_infoboolr4   r   r   r   r   r   r   8   sw    37#,/;>	 6!	 	d 	t 	 	
	 	 	 	r   r   r!   r"   c                     ^ S[         S[         S[        4   4U4S jjnU (       a  T(       a  [        S5      e[        U 5      S:X  a  U" U S   5      $ [        U 5      S:w  a  [        S[        U 5      5      eU$ )	a  Decorator to run a synchronous method asynchronously on an executor.

Returns a future.

The executor to be used is determined by the ``executor``
attributes of ``self``. To use a different attribute name, pass a
keyword argument to the decorator::

    @run_on_executor(executor='_thread_pool')
    def foo(self):
        pass

This decorator should not be confused with the similarly-named
`.IOLoop.run_in_executor`. In general, using ``run_in_executor``
when *calling* a blocking method is recommended instead of using
this decorator when *defining* a method. If compatibility with older
versions of Tornado is required, consider defining an executor
and using ``executor.submit()`` at the call site.

.. versionchanged:: 4.2
   Added keyword arguments to use alternative attributes.

.. versionchanged:: 5.0
   Always uses the current IOLoop instead of ``self.io_loop``.

.. versionchanged:: 5.1
   Returns a `.Future` compatible with ``await`` instead of a
   `concurrent.futures.Future`.

.. deprecated:: 5.1

   The ``callback`` argument is deprecated and will be removed in
   6.0. The decorator itself is discouraged in new code but will
   not be removed in 6.0.

.. versionchanged:: 6.0

   The ``callback`` argument was removed.
r    r   .c           	         >^ ^ TR                  SS5      m[        R                  " T 5      S[        S[        S[        S[        4UU 4S jj5       nU$ )Nexecutorr+   r!   r"   r   c                 t   > [        5       n[        U T5      R                  " TU /UQ70 UD6n[        XC5        U$ r   )r%   getattrr-   chain_future)r+   r!   r"   async_futureconc_futurer<   r    s        r   wrapperCrun_on_executor.<locals>.run_on_executor_decorator.<locals>.wrapper   s;    !8L!$188TSDSFSK3r   )get	functoolswrapsr   r%   )r    rB   r<   r"   s   ` @r   run_on_executor_decorator2run_on_executor.<locals>.run_on_executor_decorator|   sQ    ::j*5			 # 	 c 	 S 	 V 	  
	  r   z*cannot combine positional and keyword args   r   zexpected 1 argument, got %d)r   r%   
ValueErrorlen)r!   r"   rG   s    ` r   run_on_executorrL   Q   sp    V
h 
8CK3H 
 EFF
4yA~(a11	Ta6D	BB$$r   a)
Future[_T]r#   bc                    ^ SU4S jjn[        U [        5      (       a  [        X5        gSSKJn  UR                  5       R                  X5        g)aR  Chain two futures together so that when one completes, so does the other.

The result (success or failure) of ``a`` will be copied to ``b``, unless
``b`` has already been completed or cancelled by the time ``a`` finishes.

.. versionchanged:: 5.0

   Now accepts both Tornado/asyncio `Future` objects and
   `concurrent.futures.Future`.

Nc                 4  > TR                  5       (       a  g [        U S5      (       a,  U R                  5       b  [        TU R                  5       5        g U R	                  5       nUb  TR                  U5        g TR                  U R                  5       5        g )Nr*   )donehasattrr*   r(   	exceptionset_exception
set_resultresult)rM   a_excrO   s     r   copychain_future.<locals>.copy   sh    66881j!!ajjl&>1::<0KKME &QXXZ(r   r   )IOLoop)rM   rN   r   N)r   r%   future_add_done_callbacktornado.ioloopr[   current
add_future)rM   rO   rY   r[   s    `  r   r?   r?      s9     
) !V ) 	*##A,r   r,   z%Union[futures.Future[_T], Future[_T]]valuec                 R    U R                  5       (       d  U R                  U5        gg)zSet the given ``value`` as the `Future`'s result, if not cancelled.

Avoids ``asyncio.InvalidStateError`` when calling ``set_result()`` on
a cancelled `asyncio.Future`.

.. versionadded:: 5.0
N)	cancelledrV   )r,   r`   s     r   r&   r&      s&     %  r   excc                 |    U R                  5       (       d  U R                  U5        g[        R                  " SUS9  g)a  Set the given ``exc`` as the `Future`'s exception.

If the Future is already canceled, logs the exception instead. If
this logging is not desired, the caller should explicitly check
the state of the Future and call ``Future.set_exception`` instead of
this wrapper.

Avoids ``asyncio.InvalidStateError`` when calling ``set_exception()`` on
a cancelled `asyncio.Future`.

.. versionadded:: 6.0

z$Exception after Future was cancelled)r*   N)rb   rU   r   error)r,   rc   s     r   %future_set_exception_unless_cancelledrf      s0      S!<sKr   r*   c                 B    US   c  [        S5      e[        XS   5        g)ae  Set the given ``exc_info`` as the `Future`'s exception.

Understands both `asyncio.Future` and the extensions in older
versions of Tornado to enable better tracebacks on Python 2.

.. versionadded:: 5.0

.. versionchanged:: 6.0

   If the future is already cancelled, this function is a no-op.
   (previously ``asyncio.InvalidStateError`` would be raised)

rI   Nz,future_set_exc_info called with no exception)r'   rf   )r,   r*   s     r   r(   r(      s&    & {FGG)&1+>r   r#   callbackc                     g r   r   r,   rh   s     r   r\   r\           	r   rN   c                     g r   r   rj   s     r   r\   r\      rk   r   ).Nc                 b    U R                  5       (       a	  U" U 5        gU R                  U5        g)a4  Arrange to call ``callback`` when ``future`` is complete.

``callback`` is invoked with one argument, the ``future``.

If ``future`` is already done, ``callback`` is invoked immediately.
This may differ from the behavior of ``Future.add_done_callback``,
which makes no such guarantee.

.. versionadded:: 5.0
N)rR   add_done_callbackrj   s     r   r\   r\     s%     {{}}  *r   )&__doc__asyncio
concurrentr   rE   r)   typestornado.logr   typingr   r   r   r   r	   TypeVarr
   r'   r   r%   r   r9   r   Executorr   dummy_executorrL   object
_NO_RESULTr?   r&   BaseExceptionrf   typeTracebackTyper(   overloadr\   r   r   r   <module>r~      s      
    8 8^^D	i 	
 
>>6
"" " "G$$ , =%3 =%# =%( =%@ X
"-/0"-/0"- 
"-J!3!<>!	!L3L:GL	L,?3?/%:M:M1NN?
 
?0 	 	,46J5KT5Q,R			 	 		$,l^T-A$B			 	+3+?G	?R+	+r   