
    %h                     `    S SK r S SKrS SKrS SKrS SKJrJrJr   " S S5      r " S S5      r	g)    N)AnyDictUnionc                   ^   ^  \ rS rSrSrSS jrS rS\S\SS4U 4S	 jjr	S\SS4S
 jr
SrU =r$ )_CVar   zStorage utility for Local.returnNc                 :    [         R                  " S5      U l        g )Nzasgiref.local)contextvars
ContextVar_dataselfs    ?/var/www/html/env/lib/python3.13/site-packages/asgiref/local.py__init___CVar.__init__   s    ?J?U?U@

    c                     U R                   R                  0 5      n X!   $ ! [         a    [        U < SU< 35      ef = fNz object has no attribute )r   getKeyErrorAttributeErrorr   keystorage_objects      r   __getattr___CVar.__getattr__   sK    +	N!&& 	N D8+DSG!LMM	Ns   ! >r   valuec                    > US:X  a  [         TU ]  X5      $ U R                  R                  0 5      nX#U'   U R                  R	                  U5        g )Nr   )super__setattr__r   r   set)r   r   r   r   	__class__s       r   r!   _CVar.__setattr__   sD    '>7&s22+#s

~&r   c                     U R                   R                  0 5      nX;   a  X!	 U R                   R                  U5        g [        U < SU< 35      er   )r   r   r"   r   r   s      r   __delattr___CVar.__delattr__   sG    + #JJNN>* D8+DSG!LMMr   )r   )r	   N)__name__
__module____qualname____firstlineno____doc__r   r   strr   r!   r&   __static_attributes____classcell__r#   s   @r   r   r      sG    $

N's '3 '4 'Ns Nt N Nr   r   c                   r   ^  \ rS rSrSrSS\SS4S jjr\R                  S 5       r	S r
U 4S	 jrS
 rSrU =r$ )Local(   a  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                     Xl         [        R                  " 5       U l        U   U(       a  [        R                  " 5       U l        g [        5       U l        g N)_thread_critical	threadingRLock_thread_locklocal_storager   )r   r4   s     r   r   Local.__init__D   s6     /%OO-%OO-DM "GDMr   c              #     #    U R                   (       ac   [        R                  " 5         [        U R                  S5      (       d  [        5       U R                  l        U R                  R                  v   g U R                     U R                  v   S S S 5        g ! [         a    U R                  v    g f = f! , (       d  f       g = f7f)Ncvar)	r7   asyncioget_running_loophasattrr<   r   r?   RuntimeErrorr:   r   s    r   _lock_storageLocal._lock_storageQ   s        ) ((* t}}f55).DMM&
 mm((( ""mm# #"/   $
 mm#$. #"s@   C
B AC
B9	C
B63C
5B66C
9
CC
c                 n    U R                  5        n[        X!5      sS S S 5        $ ! , (       d  f       g = fr6   )rD   getattrr   r   storages      r   r   Local.__getattr__t   s$    !W7( "!!s   &
4c                    > US;   a  [         TU ]  X5      $ U R                  5        n[        X1U5        S S S 5        g ! , (       d  f       g = f)N)_localr<   r7   r:   )r    r!   rD   setattr)r   r   r   rI   r#   s       r   r!   Local.__setattr__x   s@    LL7&s22!WG%( "!!s	   =
Ac                 n    U R                  5        n[        X!5        S S S 5        g ! , (       d  f       g = fr6   )rD   delattrrH   s      r   r&   Local.__delattr__~   s$    !WG! "!!s   &
4)r<   r7   r:   )F)r(   r)   r*   r+   r,   boolr   
contextlibcontextmanagerrD   r   r!   r&   r.   r/   r0   s   @r   r2   r2   (   sJ    6$ $ $  $  $D))" "r   r2   )
r@   rS   r   r8   typingr   r   r   r   r2    r   r   <module>rW      s0        # #N N@X" X"r   