§
    ‹Ÿj¸   ã                   ó|  — 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j"                 f         d
dfd„Z#e	j$        dddedgdf         d
dfd„¦   «         Z%e	j$        dd ded gdf         d
dfd!„¦   «         Z%ddded"         d
dfd#„Z%dS )$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dS )ÚReturnValueIgnoredErrorN)Ú__name__Ú
__module__Ú__qualname__© ó    ú_/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/tornado/concurrent.pyr   r   *   s   € € € € € à€Dr   r   ÚxÚreturnc                 ó,   — t          | t          ¦  «        S ©N)Ú
isinstanceÚFUTURES)r   s    r   Ú	is_futurer   4   s   € Ý�a�Ñ!Ô!Ð!r   c                   óx   — 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
dS dde	ddfd„Z
dS )ÚDummyExecutorÚfn.ÚargsÚkwargsr   úfutures.Future[_T]c                 ó¾   — t          j        ¦   «         }	 t          | ||i |¤Ž¦  «         n1# t          $ r$ t	          |t          j        ¦   «         ¦  «         Y nw xY w|S r   )r   ÚFutureÚ"future_set_result_unless_cancelledÚ	ExceptionÚfuture_set_exc_infoÚsysÚexc_info)Úselfr   r   r   Úfutures        r   ÚsubmitzDummyExecutor.submit9   st   € õ ”Ñ!Ô!ˆð	8Ý.¨v°r°r¸4Ð7JÀ6Ð7JÐ7JÑKÔKÐKÐKøÝð 	8ð 	8ð 	8Ý ­¬©¬Ñ7Ô7Ð7Ð7Ð7ð	8øøøàˆs   •, ¬+AÁA)é   é	   TFÚwaitÚcancel_futuresNc                 ó   — d S r   r   )r'   r,   r-   s      r   ÚshutdownzDummyExecutor.shutdownE   ó   € ØˆDr   c                 ó   — d S 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   sÀ   € € € € € ðØ˜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k    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           	      ó²   •‡ ‡— ‰                      dd¦  «        Št          j        ‰ ¦  «        dt          dt          dt          dt          fˆˆ fd„¦   «         }|S )NÚexecutorr'   r   r   r   c                 ó„   •— t          ¦   «         } t          | ‰¦  «        j        ‰| g|¢R 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   sP   ø€ å!™8œ8ˆLØ8�' $¨Ñ1Ô1Ô8¸¸TÐSÀDÐSÐSÐSÈFÐSÐSˆKÝ˜ lÑ3Ô3Ð3ØÐr   )ÚgetÚ	functoolsÚwrapsr   r!   )r   r<   r6   r   s   ` @€r   Úrun_on_executor_decoratorz2run_on_executor.<locals>.run_on_executor_decorator|   ss   øøø€ Ø—:’:˜j¨*Ñ5Ô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   s«   ø€ ðV
¥hð 
µ8¸CÅ¸KÔ3Hð 
ð 
ð 
ð 
ð 
ð 
ð ð G�ð GÝÐEÑFÔFÐFÝ
ˆ4�y„y�A‚~€~Ø(Ð(¨¨a¬Ñ1Ô1Ð1Ý	ˆT‰Œ�aŠˆÝÐ6½¸D¹	¼	ÑBÔBÐBØ$Ð$r   Úa)ú
Future[_T]r   Úbc                 ó¾   ‡— dˆfd„}t          | t          ¦  «        rt          | |¦  «         dS ddlm} |                     ¦   «                              | |¦  «         dS )	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`.

    rE   rF   r   Nc                 ól  •— ‰                      ¦   «         rd S t          | d¦  «        r8|                      ¦   «         �$t          ‰|                      ¦   «         ¦  «         d S |                      ¦   «         }|�‰                     |¦  «         d S ‰                     |                      ¦   «         ¦  «         d S )Nr&   )ÚdoneÚhasattrr&   r$   Ú	exceptionÚset_exceptionÚ
set_resultÚresult)rE   Úa_excrG   s     €r   Úcopyzchain_future.<locals>.copy¤   s    ø€ Ø�6Š6‰8Œ8ð 	ØˆFÝ�1�jÑ!Ô!ð 	) a§j¢j¡l¤lÐ&>Ý  1§:¢:¡<¤<Ñ0Ô0Ð0Ð0Ð0à—K’K‘M”MˆEØÐ Ø—’ Ñ&Ô&Ð&Ð&Ð&à—’˜QŸXšX™Zœ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                 ó\   — |                       ¦   «         s|                      |¦  «         dS dS )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                 óˆ   — |                       ¦   «         s|                      |¦  «         dS t          j        d|¬¦  «         dS )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]   Ç   sO   € ð  ×ÒÑÔð LØ×Ò˜SÑ!Ô!Ð!Ð!Ð!åŒÐ<ÀsÐKÑKÔKÐKÐKÐKr   r&   c                 ó`   — |d         €t          d¦  «        ‚t          | |d         ¦  «         dS )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$   Ý   s7   € ð& �„{ÐÝÐFÑGÔGÐGÝ)¨&°(¸1´+Ñ>Ô>Ð>Ð>Ð>r   r   Úcallbackc                 ó   — d S r   r   ©r(   r_   s     r   rS   rS   õ   ó	   € ð 	€Dr   rF   c                 ó   — d S r   r   ra   s     r   rS   rS   ü   rb   r   ).Nc                 ór   — |                       ¦   «         r || ¦  «         dS |                      |¦  «         dS )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     sD   € ð ‡{‚{�}„}ð +Øˆ�ÑÔÐÐÐà× Ò  Ñ*Ô*Ð*Ð*Ð*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Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8à€V„^�DÑÔ€ð	ð 	ð 	ð 	ð 	˜iñ 	ô 	ð 	ð
 
Œ€àŒ>˜6Ð
"€ð"�ð "˜ð "ð "ð "ð "ðð ð ð ð �GÔ$ñ ô ð ð, �‘”€ð=%˜3ð =%¨#ð =%°(ð =%ð =%ð =%ð =%ð@ ˆV‰XŒX€
ð"-ØÐ/Ô0ð"-àÐ/Ô0ð"-ð 
ð"-ð "-ð "-ð "-ðJ!Ø3ð!Ø<>ð!à	ð!ð !ð !ð !ðLØ3ðLØ:GðLà	ðLð Lð Lð Lð,?Ø3ð?àØ�Œ˜ Ô/°¸%Ô:MÔ1NÐNôð?ð
 
ð?ð ?ð ?ð ?ð0 „ð	Ø ð	Ø,4Ð6JÐ5KÈTÐ5QÔ,Rð	à	ð	ð 	ð 	ñ „ð	ð „ð	Øð	Ø$,¨l¨^¸TÐ-AÔ$Bð	à	ð	ð 	ð 	ñ „ð	ð+Ø3ð+Ø?GÈ	Ô?Rð+à	ð+ð +ð +ð +ð +ð +r   