Ë
    êmxi¸   ã                   ó`  — d 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	Z	ddl	m
Z
mZmZmZmZ  e	j                  d«      Z G d„ de«      Zej&                  Zej&                  efZd	e
d
efd„Z G d„ dej.                  «      Z e«       Zde
de
d
efd„Z e«       Zded   ded   d
dfd„Zddded
dfd„Zddded
dfd„Z dddeee!   ee   eejD                     f   d
dfd„Z#e	jH                  dddedgdf   d
dfd„«       Z%e	jH                  dd ded gdf   d
dfd!„«       Z%ddded"   d
dfd#„Z%y)$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                   ó   — e Zd Zy)ÚReturnValueIgnoredErrorN)Ú__name__Ú
__module__Ú__qualname__© ó    úI/home/htdocs/ttos/venv/lib/python3.12/site-packages/tornado/concurrent.pyr   r   *   s   „ àr   r   ÚxÚreturnc                 ó"   — t        | t        «      S ©N)Ú
isinstanceÚFUTURES)r   s    r   Ú	is_futurer   4   s   € Ü�aœÓ!Ð!r   c                   óv   — e Zd Zdedef   dededdfd„Zej                  dk\  rdd	e	d
e	ddfd„Z
ydd	e	ddfd„Z
y)ÚDummyExecutorÚfn.ÚargsÚkwargsr   úfutures.Future[_T]c                 ó°   — t        j                  «       }	 t        | ||i |¤Ž«       |S # t        $ r" t	        |t        j                  «       «       Y |S w xY wr   )r   ÚFutureÚ"future_set_result_unless_cancelledÚ	ExceptionÚfuture_set_exc_infoÚsysÚexc_info)Úselfr   r   r   Úfutures        r   ÚsubmitzDummyExecutor.submit9   sV   € ô —‘Ó!ˆð	8Ü.¨v±r¸4Ð7JÀ6Ñ7JÔKð ˆøô ò 	8Ü ¬¯©«Õ7Øˆð	8ús   –* ª'AÁA)é   é	   ÚwaitÚcancel_futuresNc                  ó   — y r   r   )r'   r,   r-   s      r   ÚshutdownzDummyExecutor.shutdownE   ó   € Ør   c                  ó   — y r   r   )r'   r,   s     r   r/   zDummyExecutor.shutdownJ   r0   r   )TF)T)r   r   r   r   r
   r   r)   r%   Úversion_infoÚboolr/   r   r   r   r   r   8   sm   „ ðØ˜3 ˜7Ñ#ðØ,/ðØ;>ðà	óð ×Ñ˜6Ò!ñ	 ð 	¸dð 	Ètô 	ñ
	 ð 	°ô 	r   r   r   r   c                  óÔ   ‡— dt         dt         dt        f   fˆfd„}| r‰rt        d«      ‚t        | «      dk(  r || d   «      S t        | «      dk7  rt        dt        | «      «      ‚|S )	aE  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           	      óž   •‡ ‡— ‰j                  dd«      Št        j                  ‰ «      dt        dt        dt        dt        fˆˆ fd„«       }|S )NÚexecutorr'   r   r   r   c                 óv   •— t        «       } t        | ‰«      j                  ‰| g|¢­i |¤Ž}t        ||«       |S r   )r!   Úgetattrr)   Úchain_future)r'   r   r   Úasync_futureÚconc_futurer6   r   s        €€r   ÚwrapperzCrun_on_executor.<locals>.run_on_executor_decorator.<locals>.wrapper   s?   ø€ ä!›8ˆLØ8œ' $¨Ó1×8Ñ8¸¸TÐSÀDÒSÈFÑSˆKÜ˜ lÔ3ØÐr   )ÚgetÚ	functoolsÚwrapsr   r!   )r   r<   r6   r   s   ` @€r   Úrun_on_executor_decoratorz2run_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   r@   s    ` r   Úrun_on_executorrD   Q   sp   ø€ ðV
¤hð 
´8¸CÄ¸KÑ3Hõ 
ñ ‘ÜÐEÓFÐFÜ
ˆ4ƒy�A‚~Ù(¨¨a©Ó1Ð1Ü	ˆT‹�aŠÜÐ6¼¸D»	ÓBÐBØ$Ð$r   Úa)ú
Future[_T]r   Úbc                 ó˜   ‡— dˆfd„}t        | t        «      rt        | |«       yddlm} |j                  «       j                  | |«       y)aj  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                 ó  •— ‰j                  «       ry t        | d«      r+| j                  «       �t        ‰| j                  «       «       y | j	                  «       }|�‰j                  |«       y ‰j                  | j                  «       «       y )Nr&   )ÚdoneÚhasattrr&   r$   Ú	exceptionÚset_exceptionÚ
set_resultÚresult)rE   Úa_excrG   s     €r   Úcopyzchain_future.<locals>.copy¤   sc   ø€ Ø�6‰6Œ8ØÜ�1�jÔ! a§j¡j£lÐ&>Ü  1§:¡:£<Õ0à—K‘K“MˆEØÐ Ø—‘ Õ&à—‘˜QŸX™X›ZÕ(r   r   )ÚIOLoop)rE   rF   r   N)r   r!   Úfuture_add_done_callbackÚtornado.iolooprR   ÚcurrentÚ
add_future)rE   rG   rQ   rR   s    `  r   r9   r9   ”   s:   ø€ õ 
)ô �!”VÔÜ   DÕ)õ 	*à�‰Ó×#Ñ# A tÕ,r   r(   z%Union[futures.Future[_T], Future[_T]]Úvaluec                 óH   — | j                  «       s| j                  |«       yy)zÐSet 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)Ú	cancelledrN   )r(   rW   s     r   r"   r"   ¹   s#   € ð ×ÑÔØ×Ñ˜%Õ ð r   Úexcc                 óv   — | j                  «       s| j                  |«       yt        j                  d|¬«       y)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)rY   rM   r   Úerror)r(   rZ   s     r   Ú%future_set_exception_unless_cancelledr]   Ç   s-   € ð  ×ÑÔØ×Ñ˜SÕ!ä�‰Ð<ÀsÖKr   r&   c                 óB   — |d   €t        d«      ‚t        | |d   «       y)a�  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)

    rA   Nz,future_set_exc_info called with no exception)r#   r]   )r(   r&   s     r   r$   r$   Ý   s(   € ð& ��{ÐÜÐFÓGÐGÜ)¨&°(¸1±+Õ>r   r   Úcallbackc                  ó   — y r   r   ©r(   r_   s     r   rS   rS   õ   ó   € ð 	r   rF   c                  ó   — y r   r   ra   s     r   rS   rS   ü   rb   r   ).Nc                 óX   — | j                  «       r	 || «       y| j                  |«       y)aL  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)rJ   Úadd_done_callbackra   s     r   rS   rS     s#   € ð ‡{�{„}Ù�Õà× Ñ  Õ*r   )&Ú__doc__ÚasyncioÚ
concurrentr   r>   r%   ÚtypesÚtornado.logr   Útypingr   r   r   r   r	   ÚTypeVarr
   r#   r   r!   r   r3   r   ÚExecutorr   Údummy_executorrD   ÚobjectÚ
_NO_RESULTr9   r"   ÚBaseExceptionr]   ÚtypeÚTracebackTyper$   ÚoverloadrS   r   r   r   ú<module>ru      sö  ðñó Ý Û Û 
Û å ã ß 8Õ 8à€V‡^�^�DÓ€ô	˜iô 	ð
 
�‰€à�>‰>˜6Ð
"€ð"�ð "˜ó "ô�G×$Ñ$ô ñ, “€ð=%˜3ð =%¨#ð =%°(ó =%ñ@ ‹X€
ð"-ØÐ/Ñ0ð"-àÐ/Ñ0ð"-ð 
ó"-ðJ!Ø3ð!Ø<>ð!à	ó!ðLØ3ðLØ:GðLà	óLð,?Ø3ð?àØ�‰˜ Ñ/°¸%×:MÑ:MÑ1NÐNñð?ð
 
ó?ð0 ‡�ð	Ø ð	Ø,4Ð6JÐ5KÈTÐ5QÑ,Rð	à	ò	ó ð	ð ‡�ð	Øð	Ø$,¨l¨^¸TÐ-AÑ$Bð	à	ò	ó ð	ð+Ø3ð+Ø?GÈ	Ñ?Rð+à	ô+r   