
    %hW                       S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  S SK	Jr  S SKJr  SSKJr  \R                  (       a  S S	KJr  S S
KJr  S SKJr  \R(                  " S5      r\R(                  " S\R,                  S\R.                  4   S9rSS jr " S S5      r " S S\R6                  \   5      r " S S5      r " S S5      r " S S\5      rS S jr S!S jr! " S S\R6                  \   5      r"g)"    )annotationsN)
ContextVarpartial)update_wrapper)
attrgetter   )ClosingIterator)StartResponse)WSGIApplication)WSGIEnvironmentTF.)boundc                $    U R                  5         g)zRelease the data for the current context in a :class:`Local` or
:class:`LocalStack` without using a :class:`LocalManager`.

This should not be needed for modern use cases, and may be removed
in the future.

.. versionadded:: 0.6.1
N)__release_local__)locals    F/var/www/auris/envauris/lib/python3.13/site-packages/werkzeug/local.pyrelease_localr      s     
    c                  x    \ rS rSrSrSrSSS jjrSS jrSS.     SS jjrSS	 jr	SS
 jr
SS jrSS jrSrg)Local#   aE  Create a namespace of context-local data. This wraps a
:class:`ContextVar` containing a :class:`dict` value.

This may incur a performance penalty compared to using individual
context vars, as it has to copy data to avoid mutating the dict
between nested contexts.

:param context_var: The :class:`~contextvars.ContextVar` to use as
    storage for this local. If not given, one will be created.
    Context vars not created at the global scope may interfere with
    garbage collection.

.. versionchanged:: 2.0
    Uses ``ContextVar`` instead of a custom storage implementation.
)	__storageNc                h    Uc  [        S[        U 5       S35      n[        R                  U SU5        g )Nzwerkzeug.Local<	>.storage_Local__storage)r   idobject__setattr__selfcontext_vars     r   __init__Local.__init__6   s4    
 %r$xj	%JKK4!2K@r   c                f    [        U R                  R                  0 5      R                  5       5      $ N)iterr   getitemsr"   s    r   __iter__Local.__iter__@   s%    DNN&&r*00233r   unbound_messagec                   [        XUS9$ )zCreate a :class:`LocalProxy` that access an attribute on this
local namespace.

:param name: Proxy this attribute.
:param unbound_message: The error message that the proxy will
    show if the attribute isn't set.
r.   
LocalProxyr"   namer/   s      r   __call__Local.__call__C   s     $oFFr   c                :    U R                   R                  0 5        g r'   )r   setr+   s    r   r   Local.__release_local__O   s    2r   c                `    U R                   R                  0 5      nX;   a  X!   $ [        U5      er'   )r   r)   AttributeErrorr"   r4   valuess      r   __getattr__Local.__getattr__R   s.    ##B'><T""r   c                    U R                   R                  0 5      R                  5       nX#U'   U R                   R                  U5        g r'   )r   r)   copyr8   )r"   r4   valuer=   s       r   r    Local.__setattr__Z   s8    ##B',,.t6"r   c                    U R                   R                  0 5      nX;   a.  UR                  5       nX!	 U R                   R                  U5        g [	        U5      er'   )r   r)   rA   r8   r;   r<   s      r   __delattr__Local.__delattr___   sH    ##B'>[[]FNNv& &&r    r'   )r#   z#ContextVar[dict[str, t.Any]] | NonereturnNone)rH   zt.Iterator[tuple[str, t.Any]])r4   strr/   
str | NonerH   LocalProxy[t.Any]rH   rI   )r4   rJ   rH   t.Any)r4   rJ   rB   rN   rH   rI   )r4   rJ   rH   rI   )__name__
__module____qualname____firstlineno____doc__	__slots__r$   r,   r5   r   r>   r    rE   __static_attributes__rG   r   r   r   r   #   sS      IA4 ;?
G
G-7
G	
G##
'r   r   c                  ~    \ rS rSrSrSrSSS jjrSS jrSS jrSS jr	\
SS	 j5       r SSS
.     SS jjjrSrg)
LocalStackj   aZ  Create a stack of context-local data. This wraps a
:class:`ContextVar` containing a :class:`list` value.

This may incur a performance penalty compared to using individual
context vars, as it has to copy data to avoid mutating the list
between nested contexts.

:param context_var: The :class:`~contextvars.ContextVar` to use as
    storage for this local. If not given, one will be created.
    Context vars not created at the global scope may interfere with
    garbage collection.

.. versionchanged:: 2.0
    Uses ``ContextVar`` instead of a custom storage implementation.

.. versionadded:: 0.6.1
)_storageNc                F    Uc  [        S[        U 5       S35      nXl        g )Nzwerkzeug.LocalStack<r   )r   r   rY   r!   s     r   r$   LocalStack.__init__   s'    
 %';BtH:Y%OPK#r   c                :    U R                   R                  / 5        g r'   )rY   r8   r+   s    r   r   LocalStack.__release_local__   s    "r   c                    U R                   R                  / 5      R                  5       nUR                  U5        U R                   R	                  U5        U$ )z'Add a new item to the top of the stack.)rY   r)   rA   appendr8   )r"   objstacks      r   pushLocalStack.push   sB    !!"%**,S% r   c                    U R                   R                  / 5      n[        U5      S:X  a  gUS   nU R                   R                  USS 5        U$ )zZRemove the top item from the stack and return it. If the
stack is empty, return ``None``.
r   N)rY   r)   lenr8   )r"   ra   rvs      r   popLocalStack.pop   sL     !!"%u:?2Y%*%	r   c                b    U R                   R                  / 5      n[        U5      S:X  a  gUS   $ )zKThe topmost item on the stack.  If the stack is empty,
`None` is returned.
r   Nre   )rY   r)   rf   )r"   ra   s     r   topLocalStack.top   s0    
 !!"%u:?Ryr   r.   c                   [        XUS9$ )a  Create a :class:`LocalProxy` that accesses the top of this
local stack.

:param name: If given, the proxy access this attribute of the
    top item, rather than the item itself.
:param unbound_message: The error message that the proxy will
    show if the stack is empty.
r.   r1   r3   s      r   r5   LocalStack.__call__   s     $oFFr   r'   )r#   zContextVar[list[T]] | NonerH   rI   rM   )r`   r   rH   zlist[T])rH   zT | None)r4   rK   r/   rK   rH   rL   )rO   rP   rQ   rR   rS   rT   r$   r   rb   rh   propertyrk   r5   rU   rG   r   r   rW   rW   j   sk    $ I$ 	 	 "&GHLGG;EG	G Gr   rW   c                  Z    \ rS rSrSrSr S
   SS jjrSS jrSS jrSS jr	SS	 jr
Srg)LocalManager   a  Manage releasing the data for the current context in one or more
:class:`Local` and :class:`LocalStack` objects.

This should not be needed for modern use cases, and may be removed
in the future.

:param locals: A local or list of locals to manage.

.. versionchanged:: 2.1
    The ``ident_func`` was removed.

.. versionchanged:: 0.7
    The ``ident_func`` parameter was added.

.. versionchanged:: 0.6.1
    The :func:`release_local` function can be used instead of a
    manager.
)localsNc                v    Uc  / U l         g [        U[        5      (       a	  U/U l         g [        U5      U l         g r'   )rs   
isinstancer   list)r"   rs   s     r   r$   LocalManager.__init__   s1    
 >DK&&!(DKv,DKr   c                @    U R                    H  n[        U5        M     g)zvRelease the data in the locals for this context. Call this at
the end of each request or use :meth:`make_middleware`.
N)rs   r   )r"   r   s     r   cleanupLocalManager.cleanup   s     [[E%  !r   c                (   ^ ^       SUU 4S jjnU$ )zuWrap a WSGI application so that local data is released
automatically after the response has been sent for a request.
c                <   > [        T" X5      TR                  5      $ r'   )r
   ry   )environstart_responseappr"   s     r   application1LocalManager.make_middleware.<locals>.application   s     #3w#?NNr   )r}   r   r~   r   rH   zt.Iterable[bytes]rG   )r"   r   r   s   `` r   make_middlewareLocalManager.make_middleware   s2    
	O$	O6C	O	O 	O
 r   c                8    [        U R                  U5      U5      $ )zLike :meth:`make_middleware` but used as a decorator on the
WSGI application function.

.. code-block:: python

    @manager.middleware
    def application(environ, start_response):
        ...
)r   r   )r"   funcs     r   
middlewareLocalManager.middleware   s     d2248$??r   c                `    S[        U 5      R                   S[        U R                  5       S3$ )N<z storages: >)typerO   rf   rs   r+   s    r   __repr__LocalManager.__repr__   s,    4:&&'{3t{{3C2DAFFr   r'   )rs   zJNone | (Local | LocalStack[t.Any] | t.Iterable[Local | LocalStack[t.Any]])rH   rI   rM   )r   r   rH   r   )r   r   rH   r   rH   rJ   )rO   rP   rQ   rR   rS   rT   r$   ry   r   r   r   rU   rG   r   r   rq   rq      sE    & I
 QU
'N
' 
	
'!

@Gr   rq   c                      \ rS rSrSrSr    S         SS jjrSS jrSSS jjrSS jr	        SS	 jr
S
rg)_ProxyLookup   ad  Descriptor that handles proxied attribute lookup for
:class:`LocalProxy`.

:param f: The built-in function this attribute is accessed through.
    Instead of looking up the special method, the function call
    is redone on the object.
:param fallback: Return this function if the proxy is unbound
    instead of raising a :exc:`RuntimeError`.
:param is_attr: This proxied name is an attribute, not a function.
    Call the fallback immediately to get the value.
:param class_value: Value to return when accessed from the
    ``LocalProxy`` class directly. Used for ``__doc__`` so building
    docs still works.
)bind_ffallbackis_attrclass_valuer4   Nc                   ^ [        TS5      (       a        SU4S jjnOTb        SU4S jjnOS nXPl        X l        X0l        X@l        g )N__get__c                :   > TR                  U[        U5      5      $ r'   r   r   instancer`   fs     r   r   %_ProxyLookup.__init__.<locals>.bind_f  s     yyd3i00r   c                   > [        TU5      $ r'   r   r   s     r   r   r   %  s     q#&r   r   rL   r`   rN   rH   zt.Callable[..., t.Any])hasattrr   r   r   r   )r"   r   r   r   r   r   s    `    r   r$   _ProxyLookup.__init__  sy     1i  1+1271'1 1
 ]'+'27''' ' F &r   c                    X l         g r'   r4   )r"   ownerr4   s      r   __set_name___ProxyLookup.__set_name__3  s    	r   c                p   Uc  U R                   b  U R                   $ U $  UR                  5       nU R                  b  U R                  X5      $ [        X0R                  5      $ ! [         aH    U R                  c  e U R                  R	                  X5      nU R
                  (       a	  U" 5       s $ Us $ f = fr'   )	r   _get_current_objectRuntimeErrorr   r   r   r   getattrr4   )r"   r   r   r`   r   s        r   r   _ProxyLookup.__get__6  s    +'''K	..0C ;;";;x--sII&&!  	}}$}},,X=H||  z!O	s   A# #AB50B54B5c                     SU R                    3$ )Nzproxy r   r+   s    r   r   _ProxyLookup.__repr__Q  s    		{##r   c                D    U R                  U[        U5      5      " U0 UD6$ )zSupport calling unbound methods from the class. For example,
this happens with ``copy.copy``, which does
``type(x).__copy__(x)``. ``type(x)`` can't be proxied, so it
returns the proxy type and descriptor.
r   )r"   r   argskwargss       r   r5   _ProxyLookup.__call__T  s#     ||Hd8n5tFvFFr   )r   r   r   r   r4   )NNNF)
r   t.Callable[..., t.Any] | Noner   -t.Callable[[LocalProxy[t.Any]], t.Any] | Noner   zt.Any | Noner   boolrH   rI   )r   rL   r4   rJ   rH   rI   r'   )r   rL   r   ztype | NonerH   rN   r   )r   rL   r   rN   r   rN   rH   rN   )rO   rP   rQ   rR   rS   rT   r$   r   r   r   r5   rU   rG   r   r   r   r      s     II ,0BF$( (  @  "	 
   
 D'6$G)G27GCHG	Gr   r   c                  F   ^  \ rS rSrSrSr  S     SU 4S jjjrSrU =r$ )	_ProxyIOpi_  z}Look up an augmented assignment method on a proxied object. The
method is wrapped to return the proxy instead of the object.
rG   c                D   >^ [         TU ]  TU5        SU4S jjnX0l        g )Nc                N   >^  SUU 4S jjnUR                  U[        U5      5      $ )Nc                   > T" X5        T$ r'   rG   )r"   otherr   r   s     r   i_op0_ProxyIOp.__init__.<locals>.bind_f.<locals>.i_opn  s    $r   )r"   rN   r   rN   rH   rL   r   )r   r`   r   r   s   `  r   r   "_ProxyIOp.__init__.<locals>.bind_fm  s$        <<T#Y//r   r   )superr$   r   )r"   r   r   r   	__class__s    `  r   r$   _ProxyIOp.__init__f  s     
 	H%	0 r   )r   )NN)r   r   r   r   rH   rI   )	rO   rP   rQ   rR   rS   rT   r$   rU   __classcell__)r   s   @r   r   r   _  s>     I ,0BF( @ 
	 r   r   c                J   ^  SU 4S jjn[         R                  " [        U5      $ )z5Swap the argument order to turn an l-op into an r-op.c                   > T" X5      $ r'   rG   )r`   r   ops     r   r_op_l_to_r_op.<locals>.r_opz  s    %~r   )r`   rN   r   rN   rH   rN   )tcastr   )r   r   s   ` r   
_l_to_r_opr   w  s     66!T?r   c                    U $ r'   rG   )os    r   	_identityr     s    Hr   c                  L   \ rS rSr% SrSrS\S'     SSS.       SS jjjr\" \S	 S
S9r\" S S
S9r	\" \
S S9r\" \5      r\" \5      r\" 5       r\" \R$                  5      r\" \R(                  5      r\" \R,                  5      r\" \R0                  5      r\" \R4                  5      r\" \R8                  5      r\" \5      r\" \ S S9r!\" \"5      r#\" \$5      r%\" \&5      r'\" \(S S9r)\" S S
S9r*\" S 5      r+\" S 5      r,\" S 5      r-\" \.5      r/\" \R`                  5      r1\" \Rd                  5      r3\" \Rh                  5      r5\" \Rl                  5      r7\" \85      r9\" \:5      r;\" \<5      r=\" \R|                  5      r?\" \R                  5      rA\" \R                  5      rC\" \R                  5      rE\" \R                  5      rG\" \R                  5      rI\" \R                  5      rK\" \R                  5      rM\" \N5      rO\" \P5      rQ\" \R                  5      rS\" \R                  5      rU\" \R                  5      rW\" \R                  5      rY\" \R                  5      r[\" \\" \R                  5      5      r]\" \\" \R                  5      5      r^\" \\" \R                  5      5      r_\" \\" \R                  5      5      r`\" \\" \R                  5      5      ra\" \\" \R                  5      5      rb\" \\" \R                  5      5      rc\" \\" \N5      5      rd\" \\" \P5      5      re\" \\" \R                  5      5      rf\" \\" \R                  5      5      rg\" \\" \R                  5      5      rh\" \\" \R                  5      5      ri\" \\" \R                  5      5      rj\k" \R                  5      rm\k" \R                  5      ro\k" \R                  5      rq\k" \R                  5      rs\k" \R                  5      ru\k" \R                  5      rw\k" \R                  5      ry\k" \R                  5      r{\k" \R                  5      r}\k" \R                  5      r\k" \GR                   5      r\k" \GR                  5      r\k" \GR                  5      r\" \GR                  5      r\" \GR                  5      r\" \5      r\" \GR                  5      r\" \5      r\" \5      r\" \5      r\" \GR(                  5      r\" \5      r\" \GR2                  5      r\" \GR6                  5      r\" \GR:                  5      r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" \GRL                  5      r\" \GRP                  5      rSrg)r2   i  a  A proxy to the object bound to a context-local object. All
operations on the proxy are forwarded to the bound object. If no
object is bound, a ``RuntimeError`` is raised.

:param local: The context-local object that provides the proxied
    object.
:param name: Proxy this attribute from the proxied object.
:param unbound_message: The error message to show if the
    context-local object is unbound.

Proxy a :class:`~contextvars.ContextVar` to make it easier to
access. Pass a name to proxy that attribute.

.. code-block:: python

    _request_var = ContextVar("request")
    request = LocalProxy(_request_var)
    session = LocalProxy(_request_var, "session")

Proxy an attribute on a :class:`Local` namespace by calling the
local with the attribute name:

.. code-block:: python

    data = Local()
    user = data("user")

Proxy the top item on a :class:`LocalStack` by calling the local.
Pass a name to proxy that attribute.

.. code-block::

    app_stack = LocalStack()
    current_app = app_stack()
    g = app_stack("g")

Pass a function to proxy the return value from that function. This
was previously used to access attributes of local objects before
that was supported directly.

.. code-block:: python

    session = LocalProxy(lambda: request.session)

``__repr__`` and ``__class__`` are proxied, so ``repr(x)`` and
``isinstance(x, cls)`` will look like the proxied object. Use
``issubclass(type(x), LocalProxy)`` to check if an object is a
proxy.

.. code-block:: python

    repr(user)  # <User admin>
    isinstance(user, User)  # True
    issubclass(type(user), LocalProxy)  # True

.. versionchanged:: 2.2.2
    ``__wrapped__`` is set when wrapping an object, not only when
    wrapping a function, to prevent doctest from failing.

.. versionchanged:: 2.2
    Can proxy a ``ContextVar`` or ``LocalStack`` directly.

.. versionchanged:: 2.2
    The ``name`` parameter can be used with any proxied object, not
    only ``Local``.

.. versionchanged:: 2.2
    Added the ``unbound_message`` parameter.

.. versionchanged:: 2.0
    Updated proxied attributes and methods to reflect the current
    data model.

.. versionchanged:: 0.6.1
    The class can be instantiated with a callable.
)	__wrappedr   zt.Callable[[], T]r   Nr.   c                 ^^^ Uc  [         mO[        U5      mTc  Sm[        T[        5      (       a  Uc  [	        S5      eSUUU4S jjnOr[        T[
        5      (       a  SUUU4S jjnOR[        T[        5      (       a  SUUU4S jjnO2[        T5      (       a
  SUU4S jjnO[	        S[        T5       S35      e[        R                  U S	T5        [        R                  U S
U5        g )Nzobject is not boundz2'name' is required when proxying a 'Local' object.c                 J   >  T " T5      $ ! [          a    [        T5      S ef = fr'   )r;   r   )get_namer   r/   s   r   r   0LocalProxy.__init__.<locals>._get_current_object  s1    B#E?*% B&7TABs    "c                 H   > TR                   n U c  [        T5      eT" U 5      $ r'   )rk   r   r`   r   r   r/   s    r   r   r     s&    ii;&77}$r   c                 j   >  TR                  5       n T" U 5      $ ! [         a    [        T5      S ef = fr'   )r)   LookupErrorr   r   s    r   r   r     s@    B))+C  }$ # B&7TABs    2c                    > T " T" 5       5      $ r'   rG   )r   r   s   r   r   r     s    ((r   zDon't know how to proxy 'z'._LocalProxy__wrappedr   )rH   r   )r   r   ru   r   	TypeErrorrW   r   callabler   r   r    )r"   r   r4   r/   r   r   s    ` ` @r   r$   LocalProxy.__init__  s     < H!$'H"3OeU##| TUUB B z**% % z**% % e__) ) 7U}BGHH4!7?4!68KLr   c                ,    [        U 5      R                  $ r'   )r   rS   r+   s    r   <lambda>LocalProxy.<lambda>  s    4:3E3Er   T)r   r   r   c                    U R                   $ r'   )r   r+   s    r   r   r     s
    d77r   )r   r   c                4    S[        U 5      R                   S3$ )Nr   z	 unbound>)r   rO   r+   s    r   r   r     s    aT
(;(;'<I$Fr   )r   c                    g)NFrG   r+   s    r   r   r   +  s    r   c                    / $ r'   rG   r+   s    r   r   r   0  s    br   c                    [        U 5      $ r'   )r   r+   s    r   r   r   ;  s    4:r   c                    [        X5      $ r'   )ru   r"   r   s     r   r   r   <  	    E9Pr   c                    [        X5      $ r'   )
issubclassr   s     r   r   r   =  r   r   c                    U " U0 UD6$ r'   rG   )r"   r   r   s      r   r   r   ?  s    $:O:Or   rG   r'   )r   z9ContextVar[T] | Local | LocalStack[T] | t.Callable[[], T]r4   rK   r/   rK   rH   rI   )rO   rP   rQ   rR   rS   rT   __annotations__r$   r   __wrapped__reprr   rJ   __str__bytes	__bytes__
__format__operatorlt__lt__le__le__eq__eq__ne__ne__gt__gt__ge__ge__hash__hash__r   __bool__r   r>   setattrr    delattrrE   dir__dir__r   __instancecheck____subclasscheck__r5   rf   __len__length_hint__length_hint__getitem__getitem__setitem__setitem__delitem__delitem__r(   r,   next__next__reversed__reversed__contains__contains__add__add__sub__sub__mul__mul__matmul
__matmul__truediv__truediv__floordiv__floordiv__mod__mod__divmod
__divmod__pow__pow__lshift
__lshift__rshift
__rshift__and___and__xor__xor__or___or__r   __radd____rsub____rmul____rmatmul____rtruediv____rfloordiv____rmod____rdivmod____rpow____rlshift____rrshift____rand____rxor____ror__r   iadd__iadd__isub__isub__imul__imul__imatmul__imatmul__itruediv__itruediv__	ifloordiv__ifloordiv__imod__imod__ipow__ipow__ilshift__ilshift__irshift__irshift__iand__iand__ixor__ixor__ior__ior__neg__neg__pos__pos__abs__abs__invert
__invert__complex__complex__int__int__float	__float__index	__index__round	__round__mathtrunc	__trunc__floor	__floor__ceil__ceil__	__enter____exit__	__await__	__aiter__	__anext__
__aenter__	__aexit__rA   __copy__deepcopy__deepcopy__rU   rG   r   r   r2   r2     sV   KZ 5I**  6M
 '+6MH6M 6M
 $6M 
6Mp &EtG 7K
 FH 3GU#IJ(++&F(++&F(++&F(++&F(++&F(++&FD!HD+=>Hw'Kw'Kw'K39G &=tLI$%PQ$%PQOPH3G"8#7#78Ox//0Kx//0Kx//0KD!HD!H)L 1 12L8<<(G8<<(G8<<(Ghoo.Jx//0K 1 12L8<<(Gf%J3Ghoo.Jhoo.J8==)G8<<(G(,,'FJx||45HJx||45HJx||45Hz(//:;K
8+;+; <=L H,=,=!>?MJx||45Hz&12KJsO,Hz(//:;Kz(//:;KJx}}56HJx||45H:hll34G'H'H'HH,,-KX../Lh001M'H'HH,,-KH,,-K'H'H%G8<<(G8<<(G3Ghoo.Jw'K3GU#IX^^,IU#ITZZ(ITZZ(IDII&HI~HIIIJIDII&H.Lr   r2   )r   zLocal | LocalStack[t.Any]rH   rI   )r   r   rH   r   )r   r   rH   r   )#
__future__r   rA   rl  r   typingr   contextvarsr   	functoolsr   r   r   wsgir
   TYPE_CHECKING_typeshed.wsgir   r   r   TypeVarr   CallableAnyr   r   r   GenericrW   rq   r   r   r   r   r2   rG   r   r   <module>r     s    "     "  $  !??,..IIcNIIcCJ/0	D' D'NMG1 MG`BG BGJ]G ]G@ 0C/1 C/r   