
    /hW                       d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dl	mZ d dlmZ ddlmZ ej        rd d	lmZ d d
lmZ d dlmZ  ej        d          Z ej        dej        dej        f                   Zd%dZ G d d          Z G d dej        e                   Z G d d          Z G d d          Z G d de          Zd&d Z d'd"Z! G d# d$ej        e                   Z"dS )(    )annotationsN)
ContextVarpartial)update_wrapper)
attrgetter   )ClosingIterator)StartResponse)WSGIApplication)WSGIEnvironmentTF.)boundlocalLocal | LocalStack[t.Any]returnNonec                .    |                                   dS )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__)r   s    A/var/www/html/venv/lib/python3.11/site-packages/werkzeug/local.pyrelease_localr      s     
    c                  V    e Zd ZdZdZdddZdd
ZddddZddZddZ	ddZ
ddZdS ) Localaq  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.
    )	__storageNcontext_var#ContextVar[dict[str, t.Any]] | Noner   r   c                    | t          dt          |            d          }t                              | d|           d S )Nzwerkzeug.Local<	>.storage_Local__storage)r   idobject__setattr__selfr   s     r   __init__zLocal.__init__6   sH    
 %%Jr$xx%J%J%JKKK4!2K@@@@@r   t.Iterator[tuple[str, t.Any]]c                t    t          | j                            i                                                     S N)iterr!   getitemsr&   s    r   __iter__zLocal.__iter__@   s,    DN&&r**0022333r   unbound_messagenamestrr1   
str | NoneLocalProxy[t.Any]c               &    t          | ||          S )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.
        r0   
LocalProxyr&   r2   r1   s      r   __call__zLocal.__call__C   s     $oFFFFr   c                :    | j                             i            d S r*   )r!   setr.   s    r   r   zLocal.__release_local__O   s    2r   t.Anyc                l    | j                             i           }||v r||         S t          |          r*   )r!   r,   AttributeErrorr&   r2   valuess      r   __getattr__zLocal.__getattr__R   s8    ##B''6>>$<T"""r   valuec                    | j                             i                                           }|||<   | j                             |           d S r*   )r!   r,   copyr<   )r&   r2   rC   rA   s       r   r$   zLocal.__setattr__Z   sH    ##B'',,..t6"""""r   c                    | j                             i           }||v r3|                                }||= | j                             |           d S t	          |          r*   )r!   r,   rE   r<   r?   r@   s      r   __delattr__zLocal.__delattr___   s^    ##B''6>>[[]]FtNv&&&&& &&&r   r*   )r   r   r   r   )r   r(   )r2   r3   r1   r4   r   r5   r   r   )r2   r3   r   r=   )r2   r3   rC   r=   r   r   )r2   r3   r   r   )__name__
__module____qualname____doc__	__slots__r'   r/   r:   r   rB   r$   rG    r   r   r   r   #   s           IA A A A A4 4 4 4 ;?
G 
G 
G 
G 
G 
G   # # # ## # # #
' ' ' ' ' 'r   r   c                  b    e Zd ZdZdZdddZdd	ZddZddZe	dd            Z
	 dddddZdS )
LocalStacka  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
    )_storageNr   ContextVar[list[T]] | Noner   r   c                X    | t          dt          |            d          }|| _        d S )Nzwerkzeug.LocalStack<r    )r   r"   rQ   r%   s     r   r'   zLocalStack.__init__   s4    
 %%OBtHH%O%O%OPPK#r   c                :    | j                             g            d S r*   )rQ   r<   r.   s    r   r   zLocalStack.__release_local__   s    "r   objr   list[T]c                    | j                             g                                           }|                    |           | j                             |           |S )z'Add a new item to the top of the stack.)rQ   r,   rE   appendr<   )r&   rU   stacks      r   pushzLocalStack.push   sP    !!"%%**,,S%   r   T | Nonec                    | j                             g           }t          |          dk    rdS |d         }| j                             |dd                    |S )zjRemove the top item from the stack and return it. If the
        stack is empty, return ``None``.
        r   N)rQ   r,   lenr<   )r&   rY   rvs      r   popzLocalStack.pop   sY     !!"%%u::??42Y%*%%%	r   c                p    | j                             g           }t          |          dk    rdS |d         S )z[The topmost item on the stack.  If the stack is empty,
        `None` is returned.
        r   Nr]   )rQ   r,   r^   )r&   rY   s     r   topzLocalStack.top   s7    
 !!"%%u::??4Ryr   r0   r2   r4   r1   r5   c               &    t          | ||          S )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.
        r0   r7   r9   s      r   r:   zLocalStack.__call__   s     $oFFFFr   r*   )r   rR   r   r   rH   )rU   r   r   rV   )r   r[   )r2   r4   r1   r4   r   r5   )rI   rJ   rK   rL   rM   r'   r   rZ   r`   propertyrb   r:   rN   r   r   rP   rP   j   s         $ I$ $ $ $ $          	 	 	 X	 "&GHLG G G G G G G Gr   rP   c                  B    e Zd ZdZdZ	 dddZdd	ZddZddZddZ	dS )LocalManagera  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.
    )localsNrg   JNone | (Local | LocalStack[t.Any] | t.Iterable[Local | LocalStack[t.Any]])r   r   c                    |	g | _         d S t          |t                    r
|g| _         d S t          |          | _         d S r*   )rg   
isinstancer   list)r&   rg   s     r   r'   zLocalManager.__init__   sD    
 >DKKK&& 	'!(DKKKv,,DKKKr   c                8    | j         D ]}t          |           dS )zRelease the data in the locals for this context. Call this at
        the end of each request or use :meth:`make_middleware`.
        N)rg   r   )r&   r   s     r   cleanupzLocalManager.cleanup   s0     [ 	! 	!E%    	! 	!r   appr   c                     d fd}|S )	zWrap a WSGI application so that local data is released
        automatically after the response has been sent for a request.
        environr   start_responser   r   t.Iterable[bytes]c                B    t           | |          j                  S r*   )r
   rm   )rp   rq   rn   r&   s     r   applicationz1LocalManager.make_middleware.<locals>.application   s#     #33w#?#?NNNr   )rp   r   rq   r   r   rr   rN   )r&   rn   rt   s   `` r   make_middlewarezLocalManager.make_middleware   s6    
	O 	O 	O 	O 	O 	O 	O
 r   funcc                H    t          |                     |          |          S )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   ru   )r&   rv   s     r   
middlewarezLocalManager.middleware   s"     d22488$???r   r3   c                \    dt          |           j         dt          | j                   dS )N<z storages: >)typerI   r^   rg   r.   s    r   __repr__zLocalManager.__repr__   s.    F4::&FF3t{3C3CFFFFr   r*   )rg   rh   r   r   rH   )rn   r   r   r   )rv   r   r   r   r   r3   )
rI   rJ   rK   rL   rM   r'   rm   ru   rx   r}   rN   r   r   rf   rf      s         & I
 QU
' 
' 
' 
' 
'! ! ! !
 
 
 

@ 
@ 
@ 
@G G G G G Gr   rf   c                  J    e Zd ZdZdZ	 	 	 	 dddZddZd d!dZd"dZd#dZ	dS )$_ProxyLookupa  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_valuer2   NFft.Callable[..., t.Any] | Noner   -t.Callable[[LocalProxy[t.Any]], t.Any] | Noner   t.Any | Noner   boolr   r   c                    t          d          rd
fd}nd
fd	}nd }|| _        || _        || _        || _        d S )N__get__instancer5   rU   r=   r   t.Callable[..., t.Any]c                J                         |t          |                    S r*   r   r|   r   rU   r   s     r   r   z%_ProxyLookup.__init__.<locals>.bind_f  s     yyd3ii000r   c                $    t          |          S r*   r   r   s     r   r   z%_ProxyLookup.__init__.<locals>.bind_f%  s     q#&r   r   r5   rU   r=   r   r   )hasattrr   r   r   r   )r&   r   r   r   r   r   s    `    r   r'   z_ProxyLookup.__init__  s     1i   	1 1 1 1 1 1 1
 ]' ' ' ' ' ' ' F &r   ownerr5   r2   r3   c                    || _         d S r*   r2   )r&   r   r2   s      r   __set_name__z_ProxyLookup.__set_name__3  s    			r   r   type | Noner=   c                F   || j         | j         S | S 	 |                                }nH# t          $ r; | j         | j                            ||          }| j        r |            cY S |cY S w xY w| j        |                     ||          S t          || j                  S r*   )	r   _get_current_objectRuntimeErrorr   r   r   r   getattrr2   )r&   r   r   rU   r   s        r   r   z_ProxyLookup.__get__6  s    +''K	..00CC 	 	 	}$},,Xu==H| "  xzz!!!OOO	 ;";;x---sDI&&&s   ) >A.)A.-A.c                    d| j          S )Nzproxy r   r.   s    r   r}   z_ProxyLookup.__repr__Q  s    #	###r   argskwargsc                T     |                      |t          |                    |i |S )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   r   r   s       r   r:   z_ProxyLookup.__call__T  s-     6t||Hd8nn55tFvFFFr   )NNNF)
r   r   r   r   r   r   r   r   r   r   )r   r5   r2   r3   r   r   r*   )r   r5   r   r   r   r=   r~   )r   r5   r   r=   r   r=   r   r=   )
rI   rJ   rK   rL   rM   r'   r   r   r}   r:   rN   r   r   r   r      s          II ,0BF$(         D   ' ' ' ' '6$ $ $ $G G G G G Gr   r   c                  .     e Zd ZdZdZ	 	 dd fd
Z xZS )	_ProxyIOpzLook up an augmented assignment method on a proxied object. The
    method is wrapped to return the proxy instead of the object.
    rN   Nr   r   r   r   r   r   c                h    t                                          |           dfd}|| _        d S )	Nr   r5   rU   r=   r   r   c                Z     d fd}|                     |t          |                    S )Nr&   r=   otherr   r5   c                      | |           S r*   rN   )r&   r   r   r   s     r   i_opz0_ProxyIOp.__init__.<locals>.bind_f.<locals>.i_opn  s    $r   )r&   r=   r   r=   r   r5   r   )r   rU   r   r   s   `  r   r   z"_ProxyIOp.__init__.<locals>.bind_fm  sC                  <<T#YY///r   r   )superr'   r   )r&   r   r   r   	__class__s    `  r   r'   z_ProxyIOp.__init__f  sK    
 	H%%%	0 	0 	0 	0 	0 	0 r   )NN)r   r   r   r   r   r   )rI   rJ   rK   rL   rM   r'   __classcell__)r   s   @r   r   r   _  s[          I ,0BF          r   r   opc                D     d fd}t          j        t          |          S )z5Swap the argument order to turn an l-op into an r-op.rU   r=   r   r   c                     ||           S r*   rN   )rU   r   r   s     r   r_opz_l_to_r_op.<locals>.r_opz  s    r%~~r   )rU   r=   r   r=   r   r=   )tcastr   )r   r   s   ` r   
_l_to_r_opr   w  s3          6!T??r   oc                    | S r*   rN   )r   s    r   	_identityr     s    Hr   c                     e Zd ZU dZdZded<   	 	 dddddZ eed d          Z ed d          Z ee	d           Z
 ee          Z ee          Z e            Z eej                  Z eej                  Z eej                  Z eej                  Z eej                  Z eej                  Z ee          Z eed           Z  ee!          Z" ee#          Z$ ee%          Z& ee'd           Z( ed d          Z) ed           Z* ed           Z+ ed           Z, ee-          Z. eej/                  Z0 eej1                  Z2 eej3                  Z4 eej5                  Z6 ee7          Z8 ee9          Z: ee;          Z< eej=                  Z> eej?                  Z@ eejA                  ZB eejC                  ZD eejE                  ZF eejG                  ZH eejI                  ZJ eejK                  ZL eeM          ZN eeO          ZP eejQ                  ZR eejS                  ZT eejU                  ZV eejW                  ZX eejY                  ZZ e e[ej?                            Z\ e e[ejA                            Z] e e[ejC                            Z^ e e[ejE                            Z_ e e[ejG                            Z` e e[ejI                            Za e e[ejK                            Zb e e[eM                    Zc e e[eO                    Zd e e[ejQ                            Ze e e[ejS                            Zf e e[ejU                            Zg e e[ejW                            Zh e e[ejY                            Zi ejejk                  Zl ejejm                  Zn ejejo                  Zp ejejq                  Zr ejejs                  Zt ejeju                  Zv ejejw                  Zx ejejy                  Zz ejej{                  Z| ejej}                  Z~ ejej                  Z ejej                  Z ejej                  Z eej                  Z eej                  Z ee          Z eej                  Z ee          Z ee          Z ee          Z eej                  Z ee          Z eej                  Z eej                  Z eej                  Z e            Z e            Z e            Z e            Z e            Z e            Z e            Z eej                  Z eej                  ZdS )r8   as	  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   Nr0   r   9ContextVar[T] | Local | LocalStack[T] | t.Callable[[], T]r2   r4   r1   r   r   c                  |t           nt          |          dt          t                    r|t	          d          dfd}nst          t
                    r	dfd}nUt          t                    r	dfd}n7t                    rdfd}n t	          d	t                     d
          t          
                    | d           t          
                    | d|           d S )Nzobject is not boundz2'name' is required when proxying a 'Local' object.r   r   c                 X    	             S # t           $ r t                    d w xY wr*   )r?   r   )get_namer   r1   s   r   r   z0LocalProxy.__init__.<locals>._get_current_object  sF    B#8E??*% B B B&77TABs   
 )c                 J    j         } | t                     |           S r*   )rb   r   rU   r   r   r1   s    r   r   z0LocalProxy.__init__.<locals>._get_current_object  s+    i;&777x}}$r   c                     	                                  } n# t          $ r t                    d w xY w |           S r*   )r,   LookupErrorr   r   s    r   r   z0LocalProxy.__init__.<locals>._get_current_object  sW    B))++CC" B B B&77TAB  x}}$s    3c                 *                             S r*   rN   )r   r   s   r   r   z0LocalProxy.__init__.<locals>._get_current_object  s    x(((r   zDon't know how to proxy 'z'._LocalProxy__wrappedr   )r   r   )r   r   rj   r   	TypeErrorrP   r   callabler|   r#   r$   )r&   r   r2   r1   r   r   s    ` ` @r   r'   zLocalProxy.__init__  s    < HH!$''H"3OeU## $	I| TUUUB B B B B B B B B z** 	I% % % % % % % % % z** 	I% % % % % % % % % e__ 	I) ) ) ) ) ) ) ) GUGGGHHH4!7???4!68KLLLLLr   c                *    t          |           j        S r*   )r|   rL   r.   s    r   <lambda>zLocalProxy.<lambda>  s    4::3E r   T)r   r   r   c                    | j         S r*   )r   r.   s    r   r   zLocalProxy.<lambda>  s	    d7 r   )r   r   c                2    dt          |           j         dS )Nrz   z	 unbound>)r|   rI   r.   s    r   r   zLocalProxy.<lambda>  s    $FT

(;$F$F$F r   )r   c                    dS )NFrN   r.   s    r   r   zLocalProxy.<lambda>+  s     r   c                    g S r*   rN   r.   s    r   r   zLocalProxy.<lambda>0  s    b r   c                     t          |           S r*   )r|   r.   s    r   r   zLocalProxy.<lambda>;  s    4:: r   c                "    t          ||           S r*   )rj   r&   r   s     r   r   zLocalProxy.<lambda><      E49P9P r   c                "    t          ||           S r*   )
issubclassr   s     r   r   zLocalProxy.<lambda>=  r   r   c                     | |i |S r*   rN   )r&   r   r   s      r   r   zLocalProxy.<lambda>?  s    $$:O:O:O r   r*   )r   r   r2   r4   r1   r4   r   r   )rI   rJ   rK   rL   rM   __annotations__r'   r   __wrapped__reprr}   r3   __str__bytes	__bytes__
__format__operatorlt__lt__le__le__eq__eq__ne__ne__gt__gt__ge__ge__hash__hash__r   __bool__r   rB   setattrr$   delattrrG   dir__dir__r   __instancecheck____subclasscheck__r:   r^   __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__rE   __copy__deepcopy__deepcopy__rN   r   r   r8   r8     s*        K KZ 5I****  6M
 '+6M 6M 6M 6M 6M 6Mp l&E&Et  G ,77  K
 |FF  H l3GU##IJ\(+&&F\(+&&F\(+&&F\(+&&F\(+&&F\(+&&F|D!!H|D+=+=>>>H,w''K,w''K,w''Kl3999G &=&=tLLLI$%P%PQQ$%P%PQQ|OOPPHl3G"l8#788O,x/00K,x/00K,x/00K|D!!H|D!!H<))L< 122Ll8<((Gl8<((Gl8<((Gho..J,x/00K< 122Ll8<((Gf%%Jl3Gho..Jho..Jl8=))Gl8<((G\(,''F|JJx|4455H|JJx|4455H|JJx|4455H,zz(/::;;K<

8+; < <==L LH,=!>!>??M|JJx|4455H,zz&1122K|JJsOO,,H,zz(/::;;K,zz(/::;;K|JJx}5566H|JJx|4455Hl::hl3344Gy''Hy''Hy''H)H,--K9X.//LIh011My''Hy''H)H,--K)H,--Ky''Hy''Hi%%Gl8<((Gl8<((Gl3Gho..J,w''Kl3GU##IX^,,IU##ITZ((ITZ((I|DI&&HI|~~HIIIJI|DI&&H<..LLLr   r8   )r   r   r   r   )r   r   r   r   )r   r   r   r   )#
__future__r   rE   rR  r   typingr   contextvarsr   	functoolsr   r   r   wsgir
   TYPE_CHECKING_typeshed.wsgir   r   r   TypeVarr   CallableAnyr   r   r   GenericrP   rf   r   r   r   r   r8   rN   r   r   <module>rn     s   " " " " " "        " " " " " "       $ $ $ $ $ $       ! ! ! ! ! !? /,,,,,,............AIcNNAIcCJ/000	 	 	 	D' D' D' D' D' D' D' D'NMG MG MG MG MG1 MG MG MG`BG BG BG BG BG BG BG BGJ]G ]G ]G ]G ]G ]G ]G ]G@       0      C/ C/ C/ C/ C/1 C/ C/ C/ C/ C/r   