Current File : //usr/local/apps/python3/lib/python3.11/site-packages/asgiref/__pycache__/local.cpython-311.pyc
�

�rRh���n�ddlZddlZddlZddlZddlmZmZmZGd�d��ZGd�d��Z	dS)�N)�Any�Dict�Unionc�N��eZdZdZd
d�Zd�Zdededdf�fd�Zdeddfd	�Z	�xZ
S)�_CVarzStorage utility for Local.�returnNc�8�tjd��|_dS)Nz
asgiref.local)�contextvars�
ContextVar�_data��selfs �E/usr/local/apps/python3/lib/python3.11/site-packages/asgiref/local.py�__init__z_CVar.__init__s��?J�?U��@
�@
��
�
�
�c��|j�i��}	||S#t$rt|�d|�����wxYw�Nz object has no attribute )r�get�KeyError�AttributeError�r�key�storage_objects   r�__getattr__z_CVar.__getattr__sa�������+�+��	N�!�#�&�&���	N�	N�	N� �D�!L�!L�S�!L�!L�M�M�M�	N���s	�$�Ar�valuec����|dkr"t���||��S|j�i��}|||<|j�|��dS)Nr)�super�__setattr__rr�set)rrrr�	__class__s    �rrz_CVar.__setattr__s]����'�>�>��7�7�&�&�s�E�2�2�2������+�+��#��s���
���~�&�&�&�&�&rc��|j�i��}||vr||=|j�|��dSt|�d|�����r)rrrrrs   r�__delattr__z_CVar.__delattr__s^�������+�+���.� � ��s�#��J�N�N�>�*�*�*�*�*� �D�!L�!L�S�!L�!L�M�M�Mr)rN)�__name__�
__module__�__qualname__�__doc__rr�strrrr"�
__classcell__�r s@rrrs��������$�$�
�
�
�
�
N�N�N�'�s�'�3�'�4�'�'�'�'�'�'�N�s�N�t�N�N�N�N�N�N�N�Nrrc�`��eZdZdZddeddfd�Zejd���Zd�Z	�fd	�Z
d
�Z�xZS)�LocalaLocal storage for async tasks.

    This is a namespace object (similar to `threading.local`) where data is
    also local to the current async task (if there is one).

    In async threads, local means in the same sense as the `contextvars`
    module - i.e. a value set in an async frame will be visible:

    - to other async code `await`-ed from this frame.
    - to tasks spawned using `asyncio` utilities (`create_task`, `wait_for`,
      `gather` and probably others).
    - to code scheduled in a sync thread using `sync_to_async`

    In "sync" threads (a thread with no async event loop running), the
    data is thread-local, but additionally shared with async code executed
    via the `async_to_sync` utility, which schedules async code in a new thread
    and copies context across to that thread.

    If `thread_critical` is True, then the local will only be visible per-thread,
    behaving exactly like `threading.local` if the thread is sync, and as
    `contextvars` if the thread is async. This allows genuinely thread-sensitive
    code (such as DB handles) to be kept stricly to their initial thread and
    disable the sharing across `sync_to_async` and `async_to_sync` wrapped calls.

    Unlike plain `contextvars` objects, this utility is threadsafe.
    F�thread_criticalrNc��||_tj��|_||rtj��|_dSt
��|_dS�N)�_thread_critical�	threading�RLock�_thread_lock�local�_storager)rr,s  rrzLocal.__init__DsL�� /���%�O�-�-����6��	$�%�O�-�-�D�M�M�M�"�G�G�D�M�M�Mrc#�@K�|jrk	tj��t|jd��st��|j_|jjV�dS#t$r
|jV�YdSwxYw|j5|jV�ddd��dS#1swxYwYdS)N�cvar)	r/�asyncio�get_running_loop�hasattrr4rr6�RuntimeErrorr2r
s r�
_lock_storagezLocal._lock_storageQs����� �	$�
)��(�*�*�*��t�}�f�5�5�1�).���D�M�&�
�m�(�(�(�(�(�(��' �
$�
$�
$�
�m�#�#�#�#�#�#�
$����.�"�
$�
$��m�#�#�#�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$����
$�
$�
$�
$�
$�
$s#�A�A2�1A2�<
B�B�Bc�~�|���5}t||��cddd��S#1swxYwYdSr.)r;�getattr�rr�storages   rrzLocal.__getattr__ts���
�
�
�
!�
!�	)�W��7�C�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)�	)�	)s�2�6�6c����|dvr"t���||��S|���5}t|||��ddd��dS#1swxYwYdS)N)�_localr4r/r2)rrr;�setattr)rrrr?r s    �rrzLocal.__setattr__xs�����L�L�L��7�7�&�&�s�E�2�2�2�
�
�
�
!�
!�	)�W��G�S�%�(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)�	)�	)s�A�A�"Ac��|���5}t||��ddd��dS#1swxYwYdSr.)r;�delattrr>s   rr"zLocal.__delattr__~s���
�
�
�
!�
!�	"�W��G�S�!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s�3�7�7)F)
r#r$r%r&�boolr�
contextlib�contextmanagerr;rrr"r(r)s@rr+r+(s����������6$�$��$��$�$�$�$��� $� $��� $�D)�)�)�)�)�)�)�)�"�"�"�"�"�"�"rr+)
r7rFr
r0�typingrrrrr+�rr�<module>rJs�������������������#�#�#�#�#�#�#�#�#�#�N�N�N�N�N�N�N�N�@X"�X"�X"�X"�X"�X"�X"�X"�X"�X"r