Format: application/x-python-code
⬇ Download File (4.1 KB)
   1  o
   2  
   3  -h��@sTddlZddlZddlZddlZddlmZmZmZGdd�d�ZGdd�d�Z	dS)�N)�Any�Dict�UnioncsReZdZdZddd�Zdd�Zded	eddf�fd
   4  d�Zdeddfdd
   5  �Z	�Z
   6  S)�_CVarzStorage utility for Local.�returnNcCst�d�|_dS)Nz
   7  asgiref.local)�contextvars�
   8  ContextVar�_data��self�r�CC:\Users\shubh\Videos\agent\nova\Lib\site-packages\asgiref/local.py�__init__s
   9  �z_CVar.__init__cCs8|j�i�}z||WStyt|�d|����w�Nz object has no attribute )r	�get�KeyError�AttributeError�r�key�storage_objectrrr
  10  �__getattr__s
  11  �z_CVar.__getattr__r�valuecs:|dkrt��||�S|j�i�}|||<|j�|�dS)Nr	)�super�__setattr__r	r�set)rrrr��	__class__rr
  12  rs
  13  z_CVar.__setattr__cCs<|j�i�}||vr||=|j�|�dSt|�d|����r)r	rrrrrrr
  14  �__delattr__s
  15  z_CVar.__delattr__)rN)�__name__�
  16  __module__�__qualname__�__doc__rr�strrrr�
  17  __classcell__rrrr
  18  rs
  19  rcsReZdZdZddeddfdd�Zejdd	��Zd
  20  d�Z	�fdd
  21  �Z
  22  dd�Z�ZS)�LocalaLocal storage for async tasks.
  23  
  24      This is a namespace object (similar to `threading.local`) where data is
  25      also local to the current async task (if there is one).
  26  
  27      In async threads, local means in the same sense as the `contextvars`
  28      module - i.e. a value set in an async frame will be visible:
  29  
  30      - to other async code `await`-ed from this frame.
  31      - to tasks spawned using `asyncio` utilities (`create_task`, `wait_for`,
  32        `gather` and probably others).
  33      - to code scheduled in a sync thread using `sync_to_async`
  34  
  35      In "sync" threads (a thread with no async event loop running), the
  36      data is thread-local, but additionally shared with async code executed
  37      via the `async_to_sync` utility, which schedules async code in a new thread
  38      and copies context across to that thread.
  39  
  40      If `thread_critical` is True, then the local will only be visible per-thread,
  41      behaving exactly like `threading.local` if the thread is sync, and as
  42      `contextvars` if the thread is async. This allows genuinely thread-sensitive
  43      code (such as DB handles) to be kept stricly to their initial thread and
  44      disable the sharing across `sync_to_async` and `async_to_sync` wrapped calls.
  45  
  46      Unlike plain `contextvars` objects, this utility is threadsafe.
  47      F�thread_criticalrNcCs2||_t��|_||rt��|_dSt�|_dS�N)�_thread_critical�	threading�RLock�_thread_lock�local�_storager)rr%rrr
  48  rDs
  49  zLocal.__init__ccs��|jr+zt��Wnty|jVYdSwt|jd�s$t�|j_|jjVdS|j�
  50  |jVWd�dS1s>wYdS)N�cvar)	r'�asyncio�get_running_loop�RuntimeErrorr,�hasattrrr-r*r
  51  rrr
  52  �
  53  _lock_storageQs��
  54  
  55  "�zLocal._lock_storagecCs6|���
  56  }t||�Wd�S1swYdSr&)r2�getattr�rr�storagerrr
  57  rts
  58  $�zLocal.__getattr__csP|dvrt��||�S|���}t|||�Wd�dS1s!wYdS)N)�_localr,r'r*)rrr2�setattr)rrrr5rrr
  59  rxs
  60  
  61  "�zLocal.__setattr__cCs8|���}t||�Wd�dS1swYdSr&)r2�delattrr4rrr
  62  r~s
  63  "�zLocal.__delattr__)F)
  64  rrr r!�boolr�
  65  contextlib�contextmanagerr2rrrr#rrrr
  66  r$(s
  67  "r$)
  68  r.r:rr(�typingrrrrr$rrrr
  69  �<module>s