ó
    Ñ]j¸   ã                   ó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   ó    ÚO/home/mande/repo/quber/.venv/lib/python3.13/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)ÚDummyExecutoré8   Ú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Ü.¨v°r¸4Ð7JÀ6Ñ7JÔKð ˆøô ó 	8Ü ¬¯ª«Õ7Øˆð	8ús   —* ª)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   ÚwrapperÚCrun_on_executor.<locals>.run_on_executor_decorator.<locals>.wrapper   s;   ø€ ä!›8ˆLÜ! $¨Ó1×8Ò8¸¸TÐSÀDÒSÈFÑSˆKÜ˜Ô3ØÐr   )ÚgetÚ	functoolsÚwrapsr   r%   )r    rB   r<   r"   s   ` @€r   Úrun_on_executor_decoratorÚ2run_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ð 
´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                 ó¢   ^• 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   ø€ Ø�6‰6�8‰8ØÜ�1�j×!Ñ! a§j¡j£lÑ&>Ü  1§:¡:£<Õ0à—K‘K“MˆEØÑ Ø—‘ Õ&à—‘˜QŸX™X›ZÕ(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)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)Ú	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Ñ:MÑ1NÐNñð?ð
 
ô?ð0 ‡�ð	Ø ð	Ø,4Ð6JÐ5KÈTÐ5QÑ,Rð	à	ó	ó ð	ð ‡�ð	Øð	Ø$,¨l¨^¸TÐ-AÑ$Bð	à	ó	ó ð	ð+Ø3ð+Ø?GÈ	Ñ?Rð+à	õ+r   