403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/asgiref/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/asgiref/__pycache__/sync.cpython-311.pyc
�

"z�c�P�
���ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZddl
mZmZmZmZmZddlmZddlmZd�Zded	efd
�Zded	efd�Zded	efd�ZGd
�d��ZGd�d��ZGd�d��ZeZe			ddddededd	eedefgeffd���Z e		ddedefdededd	efd���Z 			dd�Z dS)�N)�Future�ThreadPoolExecutor)�Any�Callable�Dict�Optional�overload�)�CurrentThreadExecutor)�Localc�(�|D]�}	|���|�|��kr(|�|�|�����W#t$r+|�|�|����Y��wxYwdS�N)�get�set�LookupError)�context�cvars  �./usr/lib/python3/dist-packages/asgiref/sync.py�_restore_contextrs����(�(��	(��x�x�z�z�W�[�[��.�.�.�.�������T�*�*�+�+�+����	(�	(�	(��H�H�W�[�[��&�&�'�'�'�'�'�	(����	(�(s�AA�2B�B�func�returnc��ttd��rtj|��Stjj|_|S�N�markcoroutinefunction)�hasattr�inspectr�asyncio�
coroutines�
_is_coroutine�rs rrr$s9���w�/�0�0���,�T�2�2�2�$�/�=�����c�|�ttd��rtj|��Stj|��Sr)rr�iscoroutinefunctionrr s rr#r#,s7���w�/�0�0�1��*�4�0�0�0��*�4�0�0�0r!c�2�tjdkrt|��Stj|��r|j}tj|���t
|tj��r!|j	}t
|tj���!t|��S)N)��)
�sys�version_infor#r�ismethod�__func__�
isinstance�	functools�partialrr s r�_iscoroutinefunction_or_partialr.3s�����6�!�!�"�4�(�(�(���t�$�$�	!��=�D���t�$�$�	!���y�0�1�1�	��9�D���y�0�1�1�	�#�4�(�(�(r!c�$�eZdZdZd�Zd�Zd�ZdS)�ThreadSensitiveContextaiAsync context manager to manage context for thread sensitive mode

    This context manager controls which thread pool executor is used when in
    thread sensitive mode. By default, a single thread pool executor is shared
    within a process.

    In Python 3.7+, the ThreadSensitiveContext() context manager may be used to
    specify a thread pool per context.

    This context manager is re-entrant, so only the outer-most call to
    ThreadSensitiveContext will set the context.

    Usage:

    >>> import time
    >>> async with ThreadSensitiveContext():
    ...     await sync_to_async(time.sleep, 1)()
    c��d|_dSr)�token��selfs r�__init__zThreadSensitiveContext.__init__Vs
����
�
�
r!c��K�	tj���n4#t$r'tj�|��|_YnwxYw|Sr)�SyncToAsync�thread_sensitive_contextrrrr2r3s r�
__aenter__z!ThreadSensitiveContext.__aenter__Ysf����	H��0�4�4�6�6�6�6���	H�	H�	H�$�=�A�A�$�G�G�D�J�J�J�	H�����s�#�.A�Ac���K�|jsdStj�|d��}|r|���tj�|j��dSr)r2r7�context_to_thread_executor�pop�shutdownr8�reset)r4�exc�value�tb�executors     r�	__aexit__z ThreadSensitiveContext.__aexit__asf�����z�	��F��9�=�=�d�D�I�I���	 ��������,�2�2�4�:�>�>�>�>�>r!N)�__name__�
__module__�__qualname__�__doc__r5r9rC�r!rr0r0BsK��������&������?�?�?�?�?r!r0c�d�eZdZUdZiZded<e��ZiZded<d
d�Z	d�Z
d	�Zd
�Zd�Z
dS)�AsyncToSynca�
    Utility class which turns an awaitable that only works on the thread with
    the event loop into a synchronous callable that works in a subthread.

    If the call stack contains an async loop, the code runs there.
    Otherwise, the code runs in a new loop in a new thread.

    Either way, this thread then pauses and waits to run any thread_sensitive
    code called from further down the call stack using SyncToAsync, before
    finally exiting once the async task returns.
    z,Dict[asyncio.Task[object], threading.Thread]�
launch_mapz6Dict[asyncio.AbstractEventLoop, CurrentThreadExecutor]�loop_thread_executorsFc�$�t|��r-t|��s4tt|d|����stjdd���||_	|jj|_n#t$rYnwxYw|r	d|_dS	tj
��|_dS#t$rbttj
dd��}|r:|tj��kr#ttj
dd��|_YdSd|_YdSwxYw)N�__call__z4async_to_sync was passed a non-async-marked callable�)�
stacklevel�main_event_loop_pid�main_event_loop)�callabler.�getattr�warnings�warn�	awaitable�__self__�AttributeErrorrRr�get_running_loop�RuntimeErrorr7�threadlocal�os�getpid)r4rW�force_new_looprQs    rr5zAsyncToSync.__init__�s^���	�"�"�
	�/�	�:�:�
	�3��	�:�y�9�9���
	�
�M�F�ST�
�
�
�
�#���	� �N�3�D�M�M���	�	�	��D�	�����	0�#'�D� � � �
0�'.�'?�'A�'A��$�$�$���

0�

0�

0�'.��+�-B�D�'�'�#�
'�0�+>�"�)�+�+�+M�+M�+2�#�/�1B�D�,�,�D�(�(�(�(�,0�D�(�(�(�(�

0���s+�A-�-
A:�9A:�	B#�#AD�D�Dc���	tj��}|���rtd���n#t$rYnwxYwt	j��g}t
��}tj��}t|j
d��r
|j
j}nd}t��}||j
_d}		|�
||||tj��|��}
|jr|j���sutj��}	||j|	<t'd���}|�|j|	|
��}|r|�|��|���n<|j�|jj|
��|r|�|��|	�|j|	=t|j
d��r|j
`|r||j
_t5|d��nN#|	�|j|	=t|j
d��r|j
`|r||j
_t5|d��wxYw|���S)NznYou cannot use AsyncToSync in the same thread as an async event loop - just await the async function directly.�currentr
��max_workersr)rrZ�
is_runningr[�contextvars�copy_contextr�	threading�current_threadr�	executorsrar�	main_wrapr'�exc_inforR�new_event_looprLr�submit�_run_event_loop�run_until_future�result�call_soon_threadsafe�create_taskr)
r4�args�kwargs�
event_loopr�call_result�
source_thread�old_current_executor�current_executor�looprW�
loop_executor�loop_futures
             rrNzAsyncToSync.__call__�s���		� �1�3�3�J��$�$�&�&�
�"�>����
���	�	�	��D�	�����+�-�-�.���h�h��!�0�2�2�
��4�>�9�-�-�	(�#'�>�#9� � �#'� �0�2�2��!1������"	)�����f�k�=�#�,�.�.�'���I��(�
C�T�-A�-L�-L�-N�-N�
C��-�/�/��3C��*�4�0� 2�q� A� A� A�
�+�2�2��(�$�	����$�C�$�5�5�k�B�B�B��"�"�$�$�$�$��$�9�9��(�4�i����$�C�$�5�5�k�B�B�B����.�t�4��t�~�y�1�1�
+��N�*�#�
>�)=���&��W�Q�Z�(�(�(�(��
���.�t�4��t�~�y�1�1�
+��N�*�#�
>�)=���&��W�Q�Z�(�(�(�(�����!�!�#�#�#s�9�
A�A�?C<H�AIc	�b��tj|��	|�|��	tj|����D]}|�����fd�}|�|�����D]V}|���r�|����+|�d|���|d����Wt|d��r'|�|�	����|�
��tj|j��dS#|�
��tj|j��wxYw#	tj|����D]}|�����fd�}|�|�����D]V}|���r�|����+|�d|���|d����Wt|d��r'|�|�	����|�
��tj|j��w#|�
��tj|j��wxYwxYw)zP
        Runs the given event loop (designed to be called in a thread).
        c��:�K�tj�ddi��d{V��dS)N�return_exceptionsT)r�gather)�taskss�rr�z+AsyncToSync._run_event_loop.<locals>.gathers4�����!�.�%�H�4�H�H�H�H�H�H�H�H�H�H�Hr!Nz(unhandled exception during loop shutdown)�message�	exception�task�shutdown_asyncgens)r�set_event_loop�run_until_complete�	all_tasks�cancel�	cancelledr��call_exception_handlerrr��closerR)r4rz�coror�r�r�s     @rrnzAsyncToSync._run_event_loop�s����	��t�$�$�$�	=��#�#�D�)�)�)�
=� �)�$�/�/��!�"�"�D��K�K�M�M�M�M�I�I�I�I�I��'�'�����1�1�1�!�
�
�D��~�~�'�'�!� ��~�~�'�'�3��3�3�+U�-1�^�^�-=�-=�(,��������4�!5�6�6�G��+�+�D�,C�,C�,E�,E�F�F�F��
�
�����&�t�';�<�<�<�<�<���
�
�����&�t�';�<�<�<�<�����5
=� �)�$�/�/��!�"�"�D��K�K�M�M�M�M�I�I�I�I�I��'�'�����1�1�1�!�
�
�D��~�~�'�'�!� ��~�~�'�'�3��3�3�+U�-1�^�^�-=�-=�(,��������4�!5�6�6�G��+�+�D�,C�,C�,E�,E�F�F�F��
�
�����&�t�';�<�<�<�<���
�
�����&�t�';�<�<�<�<������s0�E-�CD;�;/E*�-J.�/CI<�.J.�</J+�+J.c�j�tj|j|��}tj||j��S�z*
        Include self for methods
        )r,r-rN�update_wrapperrW�r4�parent�objtypers    r�__get__zAsyncToSync.__get__s-��� ����7�7���'��d�n�=�=�=r!c��K�|�t|d��t���}||j|<	|dr,	|d�#t$r|j|i|���d{V��}YnwxYw|j|i|���d{V��}|�|��n,#t$r}	|�|	��Yd}	~	nd}	~	wwxYw|j|=tj	��|d<dS#|j|=tj	��|d<wxYw)zs
        Wraps the awaitable with something that puts the result into the
        result/exception future.
        Nrr
)
rr7�get_current_taskrK�
BaseExceptionrW�
set_result�
set_exceptionrerf)
r4rsrtrvrwrkr�current_taskrp�es
          rrjzAsyncToSync.main_wraps�������W�Q�Z�(�(�(�"�3�3�5�5��(5����%�	4���{�
?�C�"�1�+�%��$�C�C�C�#1�4�>�4�#B�6�#B�#B�B�B�B�B�B�B�F�F�F�C���� .�t�~�t�>�v�>�>�>�>�>�>�>�>��
�"�"�6�*�*�*�*���	)�	)�	)��%�%�a�(�(�(�(�(�(�(�(�����	)����
���-�$�1�3�3�G�A�J�J�J�����-�$�1�3�3�G�A�J�3�3�3�3sM�B�A�A/�,B�.A/�/B�C'�
C�%B?�:C'�?C�C'�' DN)F)rDrErFrGrK�__annotations__rrirLr5rNrnr�rjrHr!rrJrJks��������
�
�BD�J�>�C�C�C�����I�WY��S�X�X�X�$0�$0�$0�$0�LG$�G$�G$�R"=�"=�"=�H>�>�>�4�4�4�4�4r!rJc	�6�eZdZUdZiZded<ej��Ze	d���Z
ejd��Z
ded<ejd��Zd	ed<ej��Zd
ed<		ddedefdededdd
fd�Zd�Zd�Zd�Zed���Zd
S)r7a
    Utility class which turns a synchronous callable into an awaitable that
    runs in a threadpool. It also sets a threadlocal inside the thread so
    calls to AsyncToSync can escape it.

    If thread_sensitive is passed, the code will run in the same thread as any
    outer code. This is needed for underlying Python code that is not
    threadsafe (for example, code which handles SQLite database connections).

    If the outermost program is async (i.e. SyncToAsync is outermost), then
    this will be a dedicated single sub-thread that all sync code runs in,
    one after the other. If the outermost program is sync (i.e. AsyncToSync is
    outermost), this will just be the main thread. This is achieved by idling
    with a CurrentThreadExecutor while AsyncToSync is blocking its sync parent,
    rather than just blocking.

    If executor is passed in, that will be used instead of the loop's default executor.
    In order to pass in an executor, thread_sensitive must be set to False, otherwise
    a TypeError will be raised.
    z,Dict[threading.Thread, asyncio.Task[object]]rKr
rbr8zcontextvars.ContextVar[str]�deadlock_contextzcontextvars.ContextVar[bool]z5weakref.WeakKeyDictionary[object, ThreadPoolExecutor]r;TNr.�thread_sensitiverBrrc�p�t|��r-t|��stt|d|����rtd���||_tj||��||_t|��|r|�td���||_		|j
|_
dS#t$rYdSwxYw)NrNz4sync_to_async can only be applied to sync functions.z6executor must not be set when thread_sensitive is True)rSr.rT�	TypeErrorrr,r��_thread_sensitiver�	_executorrXrY)r4rr�rBs    rr5zSyncToAsync.__init__ns�������	T�.�t�4�4�	T�/�w�t�Z��/N�/N�O�O�	T�
�R�S�S�S���	�� ��t�,�,�,�!1����d�#�#�#��	V�� 4��T�U�U�U�!���	� �M�D�M�M�M���	�	�	��D�D�	���s�B'�'
B5�4B5c
��K�tj��}|j�rttjd��rtjj}n�|jre|j�d��rK|j���}||j	vr|j	|}n�td���}||j	|<n�|tjvrtj|}n`|jr)|j�d��rtd���|j}|jr|j�d��n|j}t#j��}t'j|jg|�Ri|��}|j}|f}i}	|�|t'j|j||���t5j��|g|�Ri|����}	tj|	d����d{V��}
t;|��|jr|j�d��n6#t;|��|jr|j�d��wwxYw|
S)Nrar
rbFz9Single thread executor already being used, would deadlockT)�timeout)rrZr�rrJrirar8rr;rrLr�r[�single_thread_executorrr�rerfr,r-r�run�run_in_executor�thread_handlerr�r'rk�wait_forr)r4rsrtrzrBr8r�childr�future�rets           rrNzSyncToAsync.__call__�s������'�)�)���!� 	&��{�,�i�8�8�
4�&�0�8����.�
4�4�3P�3T�3T��4�4�
4�
,0�+H�+L�+L�+N�+N�(�+�t�/N�N�N�#�>�?W�X�H�H� 2�a�@�@�@�H�PX�D�3�4L�M�M���:�:�:�&�<�T�B����&�
4�4�+@�+D�+D�U�+K�+K�
4�"�O����
 �6���(�4��)�-�-�d�3�3�3���~�H��*�,�,���!�$�)�=�d�=�=�=�f�=�=���{���x����	1��)�)���!��'���)�)�+�+��L�N�N����
��������F� �(���>�>�>�>�>�>�>�>�>�C�
�W�%�%�%��$�
1��%�)�)�%�0�0�0���
�W�%�%�%��$�
1��%�)�)�%�0�0�0�0�
1�����
s
�1A1H�3Ic�j�tj|j|��}tj||j��Sr�)r,r-rNr�rr�s    rr�zSyncToAsync.__get__�s-��� ����7�7���'��d�i�8�8�8r!c��||j_tj��|j_tj��}tj�	|��|krd}n||j|<d}	|dr,	|d�#t$r||i|��cY|r	|j|=SSwxYw||i|��|r	|j|=SS#|r|j|=wxYw)zE
        Wraps the sync application with exception handling.
        FTr
)r\rRr]r^rQrgrhrJrKrr�)	r4rz�source_taskrkrrsrtrh�
parent_sets	         rr�zSyncToAsync.thread_handler�s#��
,0���(�/1�y�{�{���,�"�1�3�3���!�%�%�k�2�2�n�D�D��J�J�.9�D�O�N�+��J�	4���{�
-�1�"�1�+�%��$�1�1�1��4��0��0�0�0�0��
4��O�N�3�3�
4�1�����t�T�,�V�,�,��
4��O�N�3�3�
4��z�
4��O�N�3�3�3�3�3s*�0B7�9B�B!�B7� B!�!
B7�7Cc�L�	tj��S#t$rYdSwxYw)zi
        Implementation of asyncio.current_task()
        that returns None if there is no task.
        N)rr�r[rHr!rr�zSyncToAsync.get_current_task�s8��	��'�)�)�)���	�	�	��4�4�	���s��
#�#�TN)rDrErFrGrKr�rg�localr\rr�re�
ContextVarr8r��weakref�WeakKeyDictionaryr;rr�boolrr5rNr�r��staticmethodr�rHr!rr7r7=s����������,BD�J�>�C�C�C�"�)�/�#�#�K�0�/�A�>�>�>��?U�k�>T�"�?�?��;����8N�{�7M��8�8��4����	"��!�#�#�� W����"&�37�	���s�C�x� �����/�0�	�

�����0A�A�A�F9�9�9�4�4�4�B����\���r!r7Tr�rBr.c��dSrrH�rr�rBs   r�
sync_to_asyncr��	���Cr!c��dSrrHr�s   rr�r�
r�r!c�:���|���fd�St|�����S)Nc�(��t|�����S)N�r�rB�r7)�frBr�s ��r�<lambda>zsync_to_async.<locals>.<lambda>s����
�-��
�
�
�r!r�r�r�s ``rr�r�sK����
�|�
�
�
�
�
�	
�
��)�����r!)NTNr�)!r�asyncio.coroutinesrer,rr]r'rgrUr��concurrent.futuresrr�typingrrrrr	�current_thread_executorrr�rrrr�r#r.r0rJr7�
async_to_syncr�rHr!r�<module>r�s�����������������������	�	�	�	�
�
�
�
�������������9�9�9�9�9�9�9�9�:�:�:�:�:�:�:�:�:�:�:�:�:�:�:�:�:�:�:�:�������(�(�(�$��������1�c�1�d�1�1�1�1�)�#�)�$�)�)�)�)�&?�&?�&?�&?�&?�&?�&?�&?�RO4�O4�O4�O4�O4�O4�O4�O4�d}�}�}�}�}�}�}�}�B�
�
��!�/3���
�����+�,���x��S��!�"�K�/�0�	���
���
�"�/3���
�3��8�
�����+�,���	���
���
��
������r!

Youez - 2016 - github.com/yon3zu
LinuXploit