
    Jn6h                     `    d dl Z d dlZd dlZd dlZd dlmZmZmZ  G d d      Z G d d      Z	y)    N)AnyDictUnionc                   N     e Zd Z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.returnNc                 8    t        j                  d      | _        y )Nzasgiref.local)contextvars
ContextVar_dataselfs    ^/var/www/django-portfolio.reubendavern.link/venv/lib/python3.12/site-packages/asgiref/local.py__init__z_CVar.__init__   s    ?J?U?U@

    c                 ~    | j                   j                  i       }	 ||   S # t        $ r t        | d|      w xY wNz object has no attribute )r   getKeyErrorAttributeErrorr   keystorage_objects      r   __getattr__z_CVar.__getattr__   sM    +	N!#&& 	N D8+DSG!LMM	Ns   " <r   valuec                     |dk(  rt         |   ||      S | j                  j                  i       }|||<   | j                  j	                  |       y )Nr   )super__setattr__r   r   set)r   r   r   r   	__class__s       r   r   z_CVar.__setattr__   sH    '>7&sE22+#s

~&r   c                     | j                   j                  i       }||v r||= | j                   j                  |       y t        | d|      r   )r   r   r   r   r   s      r   __delattr__z_CVar.__delattr__   sK    +. s#JJNN>* D8+DSG!LMMr   )r   N)__name__
__module____qualname____doc__r   r   strr   r   r"   __classcell__r    s   @r   r   r      sA    $

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 N)_thread_critical	threadingRLock_thread_locklocal_storager   )r   r,   s     r   r   zLocal.__init__D   s8     /%OO-%OO-DM "GDMr   c              #   v  K   | j                   r]	 t        j                          t        | j                  d      st               | j                  _        | j                  j                   y | j                  5  | j                   d d d        y # t        $ r | j                   Y y w xY w# 1 sw Y   y xY ww)Ncvar)	r/   asyncioget_running_loophasattrr4   r   r6   RuntimeErrorr2   r   s    r   _lock_storagezLocal._lock_storageQ   s        ) ((* t}}f5).DMM&
 mm((( "" $mm#$ $/   $
 mm#$.$ $s@   B9B AB98B-	B9B*'B9)B**B9-B62B9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__t   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)_localr4   r/   r2   )r   r   r;   setattr)r   r   r   r?   r    s       r   r   zLocal.__setattr__x   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$ $ $  $  $D))"r   r+   )
r7   rF   r
   r0   typingr   r   r   r   r+    r   r   <module>rJ      s0        # #N N@X" X"r   