Ë
    /~hö  ã                   ó@   — d dl Z d dlZd dlZd dlZd dlZ G d„ d«      Zy)é    Nc                   óR   ‡ — e Zd ZdZddeddfd„Zd„ Zd„ Zd„ Zd	„ Z	ˆ fd
„Z
d„ Zˆ xZS )ÚLocalaÞ  
    A drop-in replacement for threading.locals that also works with asyncio
    Tasks (via the current_task asyncio method), and passes locals through
    sync_to_async and async_to_sync.

    Specifically:
     - Locals work per-coroutine on any thread not spawned using asgiref
     - Locals work per-thread on any thread not spawned using asgiref
     - Locals are shared with the parent coroutine when using sync_to_async
     - Locals are shared with the parent thread when using async_to_sync
       (and if that thread was launched using sync_to_async, with its parent
       coroutine as well, with this working for indefinite levels of nesting)

    Set thread_critical to True to not allow locals to pass from an async Task
    to a thread it spawns. This is needed for code that truly needs
    thread-safety, as opposed to things used for helpful context (e.g. sqlite
    does not like being called from a different thread to the one it is from).
    Thread-critical code will still be differentiated per-Task within a thread
    as it is expected it does not like concurrent access.

    This doesn't use contextvars as it needs to support 3.6. Once it can support
    3.7 only, we can then reimplement the storage more nicely.
    Úthread_criticalÚreturnNc           	      óô   — || _         t        j                  «       | _        t	        j
                  «       | _        dj                  t        | «      dj                  d„ t        d«      D «       «      «      | _        y )Nz_asgiref_local_impl_{}_{}Ú c              3   ób   K  — | ]'  }t        j                  t        j                  «      –— Œ) y ­w©N)ÚrandomÚchoiceÚstringÚascii_letters)Ú.0Úis     úV/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/asgiref/local.pyú	<genexpr>z!Local.__init__.<locals>.<genexpr>)   s   è ø€ ÒJ¸A”F—M‘M¤&×"6Ñ"6×7ÑJùs   ‚-/é   )Ú_thread_criticalÚ	threadingÚRLockÚ_thread_lockÚweakrefÚWeakSetÚ_context_refsÚformatÚidÚjoinÚrangeÚ
_attr_name)Úselfr   s     r   Ú__init__zLocal.__init__!   sY   € Ø /ˆÔÜ%ŸO™OÓ-ˆÔÜ8?¿¹Ó8IˆÔð 6×<Ñ<Üˆt‹HØG‰GÑJÄÀqÃÔJÓJó
ˆó    c                 óJ  — ddl m}m} |j                  «       }d}|€t	        j
                  «       }d}| j                  r|S t        t        j                  «       «      D ](  }	 |r|j                  |   }d}n|j                  |   }d}Œ* t        d«      ‚# t        $ r Y  |S w xY w)zC
        Get the ID we should use for looking up variables
        é   )ÚAsyncToSyncÚSyncToAsyncTFzInfinite launch_map loops)Úsyncr%   r&   Úget_current_taskr   Úcurrent_threadr   r   ÚsysÚgetrecursionlimitÚ
launch_mapÚKeyErrorÚRuntimeError)r    r%   r&   Ú
context_idÚcontext_is_asyncr   s         r   Ú_get_context_idzLocal._get_context_id,   sÄ   € ÷
 	3ð !×1Ñ1Ó3ˆ
ØÐàÐÜ"×1Ñ1Ó3ˆJØ$Ðà× Ò ØÐä”s×,Ñ,Ó.Ó/ò 	<ˆAð
Ù#à!,×!7Ñ!7¸
Ñ!CJØ',Ñ$ð "-×!7Ñ!7¸
Ñ!CJØ'+Ð$øð	<ô Ð:Ó;Ð;øô ò Ùð
 Ððús   Á"%BÂ	B"Â!B"c                 óÞ   — | j                  «       }t        || j                  «      s2t        || j                  i «       | j                  j                  |«       t        || j                  «      S r
   )r1   Úhasattrr   Úsetattrr   ÚaddÚgetattr©r    Úcontext_objs     r   Ú_get_storagezLocal._get_storageP   sS   € Ø×*Ñ*Ó,ˆÜ{ D§O¡OÔ4ÜK §¡°"Ô5Ø×Ñ×"Ñ" ;Ô/Ü{ D§O¡OÓ4Ð4r"   c                 ó’   — 	 | j                   D ]  }	 t        || j                  «       Œ y # t        $ r Y Œ(w xY w# t        $ r Y y w xY wr
   )r   Údelattrr   ÚAttributeErrorÚ	TypeErrorr7   s     r   Ú__del__zLocal.__del__W   sV   € ð		Ø#×1Ñ1ò ðÜ˜K¨¯©Õ9ñøô &ò Ùðûäò 	ñ ð	ús'   ‚: ’+¨: «	7´: ¶7·: º	AÁAc                 ó˜   — | j                   5  | j                  «       }||v r||   cd d d «       S t        | ›d|›«      ‚# 1 sw Y   y xY w©Nz object has no attribute ©r   r9   r<   ©r    ÚkeyÚstorages      r   Ú__getattr__zLocal.__getattr__c   s_   € Ø×Ññ 	RØ×'Ñ'Ó)ˆGØg‰~Ø˜s‘|÷	Rñ 	Rô
 %¨ xÐ/HÈÈÐ%PÓQÐQ÷	Rð 	Rús   A °A Á A	c                 óš   •— |dv rt         ‰|   ||«      S | j                  5  | j                  «       }|||<   d d d «       y # 1 sw Y   y xY w)N)r   r   r   r   )ÚsuperÚ__setattr__r   r9   )r    rC   ÚvaluerD   Ú	__class__s       €r   rH   zLocal.__setattr__k   sS   ø€ ØÐUÑUÜ‘7Ñ& s¨EÓ2Ð2Ø×Ññ 	!Ø×'Ñ'Ó)ˆGØ ˆGC‰L÷	!÷ 	!ñ 	!ús   ¢AÁA
c                 ó˜   — | j                   5  | j                  «       }||v r||= nt        | ›d|›«      ‚	 d d d «       y # 1 sw Y   y xY wr@   rA   rB   s      r   Ú__delattr__zLocal.__delattr__r   s\   € Ø×Ññ 	RØ×'Ñ'Ó)ˆGØg‰~Ø˜C‘Lä$¨ xÐ/HÈÈÐ%PÓQÐQð !÷	R÷ 	Rñ 	Rús   )A Á A	)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úboolr!   r1   r9   r>   rE   rH   rL   Ú__classcell__)rJ   s   @r   r   r      s<   ø„ ññ0	
¨ð 	
¸ó 	
ò"òH5ò
òRô!öRr"   r   )r   r   r*   r   r   r   © r"   r   ú<module>rT      s"   ðÛ Û Û 
Û Û ÷pRò pRr"   