Ë
    Æ]j¨  ã                   óx   — 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d
d„Z G d„ d«      Z	 G d„ d	«      Z
y)é    N)ÚAnyÚUnionc                   ó2   — e Zd ZdZdZdedeeef   ddfd„Z	y)Ú_Storagean  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                 ó    — || _         || _        y ©Nr   )Úselfr   r	   s      úD/var/www/zogu/zoguvenv/lib/python3.12/site-packages/asgiref/local.pyÚ__init__z_Storage.__init__   s   € Ø"ˆŒØˆ�	ó    )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ÚintÚdictÚstrr   r   © r   r   r   r      s0   „ ñð  &€Ið #ð ¨T°#°s°(©^ð Àô r   r   c                 óR   — t        t        j                  «       | j                  «      S )z7Return a copy of *storage* owned by the current thread.)r   Ú	threadingÚ	get_identr	   )Ústorages    r   Ú_rehomer       s   € ä”I×'Ñ'Ó)¨7¯<©<Ó8Ð8r   c                   óV   ‡ — e Zd ZdZd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.r
   Nc                 ó8   — t        j                  d«      | _        y )Nzasgiref.local)ÚcontextvarsÚ
ContextVarÚ_data)r   s    r   r   z_CVar.__init__(   s   € Ü9D×9OÑ9OØó:
ˆ�
r   c                 ó¾   — | j                   j                  d «      }|�!|j                  t        j                  «       k7  rt        t        j                  «       i «      S |S r   )r$   Úgetr   r   r   r   )r   r   s     r   Ú_storagez_CVar._storage-   sL   € ð —*‘*—.‘. Ó&ˆØˆ?˜g×/Ñ/´9×3FÑ3FÓ3HÒHÜœI×/Ñ/Ó1°2Ó6Ð6Øˆr   c                 óx   — 	 | j                  «       j                  |   S # t        $ r t        | ›d|›�«      ‚w xY w©Nz object has no attribute )r'   r	   ÚKeyErrorÚAttributeError)r   Úkeys     r   Ú__getattr__z_CVar.__getattr__6   sG   € ð	NØ—=‘=“?×'Ñ'¨Ñ,Ð,øÜò 	NÜ  D 8Ð+DÀSÀGÐ!LÓMÐMð	Nús   ‚ Ÿ9r,   Úvaluec                 óø   •— |dk(  rt         ‰| �  ||«      S | j                  «       j                  j	                  «       }|||<   | j
                  j                  t        t        j                  «       |«      «       y )Nr$   )
ÚsuperÚ__setattr__r'   r	   Úcopyr$   Úsetr   r   r   )r   r,   r.   r	   Ú	__class__s       €r   r1   z_CVar.__setattr__<   s_   ø€ Ø�'Š>Ü‘7Ñ& s¨EÓ2Ð2à�}‰}‹×#Ñ#×(Ñ(Ó*ˆØˆˆS‰	Ø�
‰
�‰”x¤	× 3Ñ 3Ó 5°tÓ<Õ=r   c                 óð   — | j                  «       j                  j                  «       }||v r;||= | j                  j	                  t        t        j                  «       |«      «       y t        | ›d|›�«      ‚r)   )	r'   r	   r2   r$   r3   r   r   r   r+   )r   r,   r	   s      r   Ú__delattr__z_CVar.__delattr__D   sa   € Ø�}‰}‹×#Ñ#×(Ñ(Ó*ˆØ�$‰;Ø�S�	Ø�J‰J�N‰Nœ8¤I×$7Ñ$7Ó$9¸4Ó@ÕAä  D 8Ð+DÀSÀGÐ!LÓMÐMr   )r
   N)r
   r   )r   r   r   r   r   r'   r-   r   r   r1   r6   Ú__classcell__©r4   s   @r   r    r    %   sF   ø„ Ù$ó
ó
ò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 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                 óž   — || _         t        j                  «       | _        |  |rt        j                  «       | _        y t        «       | _        y r   )Ú_thread_criticalr   ÚRLockÚ_thread_lockÚlocalr'   r    )r   r;   s     r   r   zLocal.__init__i   s8   € Ø /ˆÔÜ%ŸO™OÓ-ˆÔááä%ŸO™OÓ-ˆD�Mô "›GˆD�Mr   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ÚRuntimeErrorr'   Úhasattrr    rB   r?   )r   Úis_asyncs     r   Ú_lock_storagezLocal._lock_storagev   s®   è ø€ ð × Ò ØˆHð!ô ×(Ñ(Ô*ñ ð
 —m‘mÓ#ô ˜tŸ}™}¨fÔ5Ü).«�D—M‘MÔ&ð
 —m‘m×(Ñ(Ó(ð ×"Ñ"ñ $Ø—m‘mÒ#÷$ð $øô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   )rH   Úgetattr©r   r,   r   s      r   r-   zLocal.__getattr__œ   s/   € Ø×ÑÓ!ð 	) WÜ˜7 CÓ(÷	)÷ 	)ò 	)ús   ‘'§0c                 ó’   •— |dv rt         ‰| �  ||«      S | j                  «       5 }t        |||«       d d d «       y # 1 sw Y   y xY w)N)Ú_localr'   r=   r?   )r0   r1   rH   Úsetattr)r   r,   r.   r   r4   s       €r   r1   zLocal.__setattr__    sM   ø€ ØÐLÑLÜ‘7Ñ& s¨EÓ2Ð2Ø×ÑÓ!ð 	) WÜ�G˜S %Ô(÷	)÷ 	)ñ 	)ús	   ¦=½Ac                 óf   — | j                  «       5 }t        ||«       d d d «       y # 1 sw Y   y xY wr   )rH   ÚdelattrrK   s      r   r6   zLocal.__delattr__¦   s/   € Ø×ÑÓ!ð 	" WÜ�G˜SÔ!÷	"÷ 	"ñ 	"ús   ‘'§0)F)r   r   r   r   Úboolr   Ú
contextlibÚcontextmanagerrH   r-   r1   r6   r7   r8   s   @r   r:   r:   M   sE   ø„ ññ6$¨ð $¸ó $ð ×Ññ#$ó ð#$òJ)ô)ö"r   r:   )r   r   r
   r   )rC   rR   r"   r   Útypingr   r   r   r   r    r:   r   r   r   ú<module>rU      s<   ðÛ Û Û Û ß ÷ñ ó09÷
%Nñ %N÷P["ò ["r   