
    _f                     n    d dl Z d dlZd dlZd dlZd dlmZmZmZ  G d d          Z G d d          Z	dS )    N)AnyDictUnionc                   N     e Zd ZdZd
dZd Zdededdf fdZdeddfd	Z	 xZ
S )_CVarzStorage utility for Local.returnNc                 8    t          j        d          | _        d S )Nzasgiref.local)contextvars
ContextVar_dataselfs    ?/var/www/html/env/lib/python3.11/site-packages/asgiref/local.py__init__z_CVar.__init__   s    ?J?U@
 @



    c                     | j                             i           }	 ||         S # t          $ r t          | d|          w xY w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!LS!L!LMMM	Ns	   $ Ar   valuec                     |dk    r"t                                          ||          S | j                            i           }|||<   | j                            |           d S )Nr   )super__setattr__r   r   set)r   r   r   r   	__class__s       r   r   z_CVar.__setattr__   s]    '>>77&&sE222++#s
~&&&&&r   c                     | j                             i           }||v r||= | j                             |           d S t          | d|          r   )r   r   r   r   r   s      r   __delattr__z_CVar.__delattr__   s^    ++.  s#JNN>***** D!L!LS!L!LMMMr   )r   N)__name__
__module____qualname____doc__r   r   strr   r   r"   __classcell__r    s   @r   r   r      s        $$
 
 
 

N N N's '3 '4 ' ' ' ' ' 'Ns Nt N N N N N N N Nr   r   c                   `     e Zd ZdZddeddfdZej        d             Zd Z	 fd	Z
d
 Z xZS )Locala  Local 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_criticalr   Nc                     || _         t          j                    | _        |  |rt          j                    | _        d S t                      | _        d S N)_thread_critical	threadingRLock_thread_locklocal_storager   )r   r,   s     r   r   zLocal.__init__D   sL     /%O--6 	$%O--DMMM "GGDMMMr   c              #   @  K   | j         rk	 t          j                     t          | j        d          st                      | j        _        | j        j        V  d S # t          $ r | j        V  Y d S w xY w| j        5  | j        V  d d d            d S # 1 swxY w Y   d S )Ncvar)	r/   asyncioget_running_loophasattrr4   r   r6   RuntimeErrorr2   r   s    r   _lock_storagezLocal._lock_storageQ   s        	$) (*** t}f55 1).DM&
 m(((((('   $ $ $
 m######$. " $ $m###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s#   A A21A2<
BBBc                 ~    |                                  5 }t          ||          cd d d            S # 1 swxY w Y   d S r.   )r;   getattrr   r   storages      r   r   zLocal.__getattr__t   s    !! 	)W7C((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   266c                     |dv r"t                                          ||          S |                                 5 }t          |||           d d d            d S # 1 swxY w Y   d S )N)_localr4   r/   r2   )r   r   r;   setattr)r   r   r   r?   r    s       r   r   zLocal.__setattr__x   s    LLL77&&sE222!! 	)WGS%(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   AA"Ac                     |                                  5 }t          ||           d d d            d S # 1 swxY w Y   d S r.   )r;   delattrr>   s      r   r"   zLocal.__delattr__~   s    !! 	"WGS!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   377)F)r#   r$   r%   r&   boolr   
contextlibcontextmanagerr;   r   r   r"   r(   r)   s   @r   r+   r+   (   s         6$ $ $ $ $ $ $  $  $  $D) ) )) ) ) ) )" " " " " " "r   r+   )
r7   rF   r
   r0   typingr   r   r   r   r+    r   r   <module>rJ      s                 # # # # # # # # # #N N N N N N N N@X" X" X" X" X" X" X" X" X" X"r   