
    sgh
                     \    d dl Z d dlZd dlZd dlZd dlmZmZ  G d d      Z G d d      Zy)    N)AnyUnionc                   X     e Zd ZdZd
dZdedef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                     i | _         y N)_data)selfs    Q/var/www/enzed_healthcare/enzed_env/lib/python3.12/site-packages/asgiref/local.py__init__z_CVar.__init__   s	    =?
    keyc                     	 | j                   |   }	 |j                         S # t        $ r t        | d|      w xY w# t        $ r t        | d|      w xY wNz object has no attribute )r
   KeyErrorAttributeErrorgetLookupError)r   r   vars      r   __getattr__z_CVar.__getattr__   sz    	N**S/C	N779	  	N D8+DSG!LMM	N
  	N D8+DSG!LMM	Ns   " ? <Avaluec                     |dk(  rt         |   ||      S | j                  j                  |      }|$t	        j
                  |      x| j                  |<   }|j                  |       y )Nr
   )super__setattr__r
   r   contextvars
ContextVarset)r   r   r   r   	__class__s       r   r   z_CVar.__setattr__   s[    '>7&sE22jjnnS!;$/$:$:3$??DJJsOcr   c                 Z    || j                   v r| j                   |= y t        | d|      r   )r
   r   )r   r   s     r   __delattr__z_CVar.__delattr__"   s0    $**

3 D8+DSG!LMMr   )r   N)__name__
__module____qualname____doc__r   strr   r   r   r!   __classcell__r   s   @r   r   r      sR    $@	Ns 	Ns 	Ns 3 4 Ns Nt Nr   r   c                   d     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.
    thread_criticalr   Nc                     || _         t        j                         | _        |  |rt        j                         | _        y t               | _        y r	   )_thread_critical	threadingRLock_thread_locklocal_storager   )r   r+   s     r   r   zLocal.__init__E   s8     /%OO-%OO-DM "GDMr   c              #     K   | j                   rpd}	 t        j                          |s| j                   y t        | j                  d      st               | j                  _        | j                  j                   y | j                  5  | j                   d d d        y # t        $ r d}Y w xY w# 1 sw Y   y xY ww)NTFcvar)	r-   asyncioget_running_loopRuntimeErrorr2   hasattrr   r4   r0   )r   is_asyncs     r   _lock_storagezLocal._lock_storageR   s        H! ((* 
 mm# t}}f5).DMM&
 mm((( "" $mm#$ $3   ! !2$ $s@   C B# A%C B4	C #B1.C 0B11C 4B=9C c                 f    | j                         5 }t        ||      cd d d        S # 1 sw Y   y xY wr	   )r:   getattrr   r   storages      r   r   zLocal.__getattr__x   s/    ! 	)W7C(	) 	) 	)s   '0c                     |dv rt         |   ||      S | j                         5 }t        |||       d d d        y # 1 sw Y   y xY w)N)_localr2   r-   r0   )r   r   r:   setattr)r   r   r   r>   r   s       r   r   zLocal.__setattr__|   sM    LL7&sE22! 	)WGS%(	) 	) 	)s	   =Ac                 f    | j                         5 }t        ||       d d d        y # 1 sw Y   y xY wr	   )r:   delattrr=   s      r   r!   zLocal.__delattr__   s/    ! 	"WGS!	" 	" 	"s   '0)F)r"   r#   r$   r%   boolr   
contextlibcontextmanagerr:   r   r   r!   r'   r(   s   @r   r*   r*   )   sE    6$ $ $ #$ #$J))"r   r*   )	r5   rE   r   r.   typingr   r   r   r*    r   r   <module>rI      s-        N NB[" ["r   