
    j                     z    S SK r S SKrS SKrS SKrS SKJrJr   " S S5      rS
S jr " S S5      r	 " S S	5      r
g)    N)AnyUnionc                   <    \ rS rSrSrSrS\S\\\	4   SS4S jr
S	rg)
_Storage   a>  Thread-tagged storage for a non-thread-critical ``Local``.

The data is tagged with the identity of the thread that owns it. This lets
``_CVar`` ignore data that leaked into an unrelated thread.

Python 3.14 added ``sys.flags.thread_inherit_context``, which is enabled by
default on free-threaded builds. When set, a new thread starts with a copy
of the spawning thread's context instead of an empty one, so the contextvar
backing a ``Local`` would otherwise be visible in any thread spawned from
one that had set it -- breaking the documented "thread-local in sync
threads" behaviour. asgiref re-homes the storage to the current thread at
the points where it *intentionally* moves work between threads (see
``asgiref.sync._restore_context``); data merely inherited by an unrelated
thread is never re-homed and so stays isolated.
	thread_iddatar	   r
   returnNc                     Xl         X l        g Nr   )selfr	   r
   s      E/var/www/html/KUNJ/venv/lib/python3.13/site-packages/asgiref/local.py__init___Storage.__init__   s    "	    )r
   r	   )__name__
__module____qualname____firstlineno____doc__	__slots__intdictstrr   r   __static_attributes__ r   r   r   r      s0      &I# T#s(^  r   r   c                 T    [        [        R                  " 5       U R                  5      $ )z7Return a copy of *storage* owned by the current thread.)r   	threading	get_identr
   )storages    r   _rehomer"       s    I'')7<<88r   c                   h   ^  \ rS rSrSrSS j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.r   Nc                 :    [         R                  " S5      U l        g )Nzasgiref.local)contextvars
ContextVar_data)r   s    r   r   _CVar.__init__(   s    9D9O9O:

r   c                     U R                   R                  S 5      nUb#  UR                  [        R                  " 5       :w  a  [        [        R                  " 5       0 5      $ U$ r   )r)   getr	   r   r    r   )r   r!   s     r   _storage_CVar._storage-   sL     **..&?g//93F3F3HHI//1266r   c                 ~     U R                  5       R                  U   $ ! [         a    [        U < SU< 35      ef = fNz object has no attribute )r-   r
   KeyErrorAttributeError)r   keys     r   __getattr___CVar.__getattr__6   sG    	N==?'',, 	N D8+DSG!LMM	Ns    <r3   valuec                    > US:X  a  [         TU ]  X5      $ U R                  5       R                  R	                  5       nX#U'   U R
                  R                  [        [        R                  " 5       U5      5        g )Nr)   )
super__setattr__r-   r
   copyr)   setr   r   r    )r   r3   r6   r
   	__class__s       r   r9   _CVar.__setattr__<   s[    '>7&s22}}##((*S	

x	 3 3 5t<=r   c                     U R                  5       R                  R                  5       nX;   a;  X!	 U R                  R	                  [        [        R                  " 5       U5      5        g [        U < SU< 35      er0   )	r-   r
   r:   r)   r;   r   r   r    r2   )r   r3   r
   s      r   __delattr___CVar.__delattr__D   s]    }}##((*;	JJNN8I$7$7$94@A D8+DSG!LMMr   )r)   )r   N)r   r   )r   r   r   r   r   r   r-   r4   r   r   r9   r?   r   __classcell__r<   s   @r   r$   r$   %   sL    $

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$ )LocalM   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 strictly 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 r   )_thread_criticalr   RLock_thread_locklocalr-   r$   )r   rF   s     r   r   Local.__init__i   s6     /%OO-%OO-DM "GDMr   c              #     #    U R                   (       a{  Sn [        R                  " 5         U(       d  U R                  v   g [        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    Sn Nf = f! , (       d  f       g = f7f)NTFcvar)	rH   asyncioget_running_loopRuntimeErrorr-   hasattrr$   rN   rJ   )r   is_asyncs     r   _lock_storageLocal._lock_storagev   s        H! ((* 
 mm# t}}f55).DMM&
 mm((( ""mm# #"3   ! !2 #"s@   CB3 A/CC*	C3C?CCC
CCc                 n    U R                  5        n[        X!5      sS S S 5        $ ! , (       d  f       g = fr   )rT   getattrr   r3   r!   s      r   r4   Local.__getattr__   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-   rH   rJ   )r8   r9   rT   setattr)r   r3   r6   r!   r<   s       r   r9   Local.__setattr__   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r   )rT   delattrrX   s      r   r?   Local.__delattr__   s$    !WG! "!!s   &
4)r-   rH   rJ   )F)r   r   r   r   r   boolr   
contextlibcontextmanagerrT   r4   r9   r?   r   rA   rB   s   @r   rD   rD   M   sJ    6$ $ $ #$ #$J))" "r   rD   )r!   r   r   r   )rO   rb   r'   r   typingr   r   r   r"   r$   rD   r   r   r   <module>re      s<         09
%N %NP[" ["r   