HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/werkzeug/__pycache__/local.cpython-310.pyc
o

"we�U�@s>ddlmZddlZddlZddlZddlZddlmZddl	m
Z
ddl	mZddlmZddl
mZejrIdd	lmZdd
lmZddlmZe�d�Zejd
ejdejfd�Zd(dd�ZGdd�d�ZGdd�deje�ZGdd�d�ZGdd�d�ZGdd�de�Zd)d!d"�Z d*d$d%�Z!Gd&d'�d'eje�Z"dS)+�)�annotationsN)�
ContextVar��partial)�update_wrapper)�
attrgetter�)�ClosingIterator)�
StartResponse)�WSGIApplication)�WSGIEnvironment�T�F.)�bound�local�Local | LocalStack�return�NonecCs|��dS)z�Release 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�r�G/home/arjun/projects/env/lib/python3.10/site-packages/werkzeug/local.py�
release_locals	rc@sbeZdZdZdZdd dd	�Zd!dd�Zdd
�d"dd�Zd#dd�Zd$dd�Z	d%dd�Z
d&dd�ZdS)'�LocalaqCreate 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]] | NonerrcCs.|durtdt|��d��}t�|d|�dS)Nzwerkzeug.Local<�	>.storage�_Local__storage)r�id�object�__setattr__��selfrrrr�__init__6szLocal.__init__�t.Iterator[tuple[str, t.Any]]cCst|j�i����S�N)�iterr�get�items�r"rrr�__iter__@szLocal.__iter__��unbound_message�name�strr,�
str | None�
LocalProxycC�t|||d�S)z�Create 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+�r0�r"r-r,rrr�__call__CszLocal.__call__cCs|j�i�dSr%)r�setr)rrrrM�zLocal.__release_local__�t.AnycCs$|j�i�}||vr||St|��r%)rr'�AttributeError�r"r-�valuesrrr�__getattr__PszLocal.__getattr__�valuecCs(|j�i���}|||<|j�|�dSr%)rr'�copyr5)r"r-r<r:rrrr XszLocal.__setattr__cCs:|j�i�}||vr|��}||=|j�|�dSt|��r%)rr'r=r5r8r9rrr�__delattr__]szLocal.__delattr__r%)rrrr)rr$)r-r.r,r/rr0�rr)r-r.rr7)r-r.r<r7rr)r-r.rr)�__name__�
__module__�__qualname__�__doc__�	__slots__r#r*r4rr;r r>rrrrr#s





rc@s`eZdZdZdZdddd	�Zdd
d�Zd dd�Zd!dd�Ze	d!dd��Z
	ddd�d"dd�ZdS)#�
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]] | NonerrcCs&|durtdt|��d��}||_dS)Nzwerkzeug.LocalStack<r)rrrFr!rrrr#}s
zLocalStack.__init__cCs|j�g�dSr%)rFr5r)rrrr�r6zLocalStack.__release_local__�objr
�list[T]cCs*|j�g���}|�|�|j�|�|S)z'Add a new item to the top of the stack.)rFr'r=�appendr5)r"rH�stackrrr�push�s
zLocalStack.push�T | NonecCs<|j�g�}t|�dkrdS|d}|j�|dd��|S)zjRemove the top item from the stack and return it. If the
        stack is empty, return ``None``.
        rN���)rFr'�lenr5)r"rK�rvrrr�pop�szLocalStack.popcCs$|j�g�}t|�dkrdS|dS)z[The topmost item on the stack.  If the stack is empty,
        `None` is returned.
        rNrN)rFr'rO)r"rKrrr�top�szLocalStack.topr+r-r/r,r0cCr1)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+r2r3rrrr4�szLocalStack.__call__r%)rrGrrr?)rHr
rrI)rrM)r-r/r,r/rr0)r@rArBrCrDr#rrLrQ�propertyrRr4rrrrrEhs




��rEc@sJeZdZdZdZ	dddd	�Zdd
d�Zddd�Zddd�Zddd�Z	dS)�LocalManageraManage 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.
    )�localsNrU�<None | (Local | LocalStack | t.Iterable[Local | LocalStack])rrcCs6|dur	g|_dSt|t�r|g|_dSt|�|_dSr%)rU�
isinstancer�list)r"rUrrrr#�s


zLocalManager.__init__cCs|jD]}t|�qdS)z�Release the data in the locals for this context. Call this at
        the end of each request or use :meth:`make_middleware`.
        N)rUr)r"rrrr�cleanup�s

�zLocalManager.cleanup�apprcsd
��fdd�}|S)z�Wrap 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]cst�||��j�Sr%)r	rY)r[r\�rZr"rr�application�sz1LocalManager.make_middleware.<locals>.applicationN)r[rr\r
rr]r)r"rZr_rr^r�make_middleware�szLocalManager.make_middleware�funccCst|�|�|�S)z�Like :meth:`make_middleware` but used as a decorator on the
        WSGI application function.

        .. code-block:: python

            @manager.middleware
            def application(environ, start_response):
                ...
        )rr`)r"rarrr�
middleware�s
zLocalManager.middlewarer.cCsdt|�j�dt|j��d�S)N�<z storages: �>)�typer@rOrUr)rrr�__repr__�szLocalManager.__repr__r%)rUrVrrr?)rZrrr)rarrr�rr.)
r@rArBrCrDr#rYr`rbrfrrrrrT�s�


rTc@sReZdZdZdZ				d!d"dd�Zd#dd�Zd$d%dd�Zd&dd�Zd'dd �Z	dS)(�_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_valuer-NF�f�t.Callable | Nonerjrl�t.Any | Nonerk�boolrrcsRt�d�r
d�fdd	�}n�durd�fd
d	�}nd}||_||_||_||_dS)N�__get__�instancer0rHr7r�
t.Callablecs��|t|��Sr%�rqre�rrrH�rmrrrir6z%_ProxyLookup.__init__.<locals>.bind_fcs
t�|�Sr%rrurvrrri �
�rrr0rHr7rrs)�hasattrrirjrlrk)r"rmrjrlrkrirrvrr#s
	
z_ProxyLookup.__init__�ownerr0r-r.cCs
||_dSr%�r-)r"rzr-rrr�__set_name__,rwz_ProxyLookup.__set_name__rr�type | Noner7cCs�|dur|jdur|jS|Sz|��}Wn ty4|jdur!�|j�||�}|jr0|�YS|YSw|jdur@|�||�St||j�Sr%)	rl�_get_current_object�RuntimeErrorrjrqrkri�getattrr-)r"rrrzrHrjrrrrq/s"


�

z_ProxyLookup.__get__cCsd|j��S)Nzproxy r{r)rrrrfJsz_ProxyLookup.__repr__�args�kwargscOs|�|t|��|i|��S)z�Support 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.
        rt)r"rrr�r�rrrr4Msz_ProxyLookup.__call__)NNNF)
rmrnrjrnrlrorkrprr)rzr0r-r.rrr%)rrr0rzr}rr7rg)rrr0r�r7r�r7rr7)
r@rArBrCrDr#r|rqrfr4rrrrrh�s�

rhcs*eZdZdZdZ	dd�fd	d
�
Z�ZS)
�	_ProxyIOpz�Look up an augmented assignment method on a proxied object. The
    method is wrapped to return the proxy instead of the object.
    rNrmrnrjrrcs&t���|�d	�fdd�}||_dS)
Nrrr0rHr7rrscs d��fdd�}|�|t|��S)	Nr"r7�otherrr0cs�||��Sr%r�r"r�)rmrrrr�i_opcs
z0_ProxyIOp.__init__.<locals>.bind_f.<locals>.i_op)r"r7r�r7rr0rt)rrrHr�rv)rrrribsz"_ProxyIOp.__init__.<locals>.bind_frx)�superr#ri)r"rmrjri��	__class__rvrr#]s
z_ProxyIOp.__init__)NN)rmrnrjrnrr)r@rArBrCrDr#�
__classcell__rrr�rr�Vs
�r��opcsd�fdd�}t�t|�S)	z5Swap the argument order to turn an l-op into an r-op.rHr7r�rcs
�||�Sr%r)rHr��r�rr�r_oporwz_l_to_r_op.<locals>.r_opN)rHr7r�r7rr7)�t�castr)r�r�rr�r�
_l_to_r_oplsr��ocCs|Sr%r)r�rrr�	_identityusr�c@s�eZdZUdZdZded<		ddd�ddd�Zeedd�dd�Zedd�dd�Zee	dd�d�Z
ee�Zee
�Ze�Zeej�Zeej�Zeej�Zeej�Zeej�Zeej�Zee�Zeedd�d�Z ee!�Z"ee#�Z$ee%�Z&ee'dd�d�Z(edd�dd�Z)edd��Z*edd��Z+edd��Z,ee-�Z.eej/�Z0eej1�Z2eej3�Z4eej5�Z6ee7�Z8ee9�Z:ee;�Z<eej=�Z>eej?�Z@eejA�ZBeejC�ZDeejE�ZFeejG�ZHeejI�ZJeejK�ZLeeM�ZNeeO�ZPeejQ�ZReejS�ZTeejU�ZVeejW�ZXeejY�ZZee[ej?��Z\ee[ejA��Z]ee[ejC��Z^ee[ejE��Z_ee[ejG��Z`ee[ejI��Zaee[ejK��Zbee[eM��Zcee[eO��Zdee[ejQ��Zeee[ejS��Zfee[ejU��Zgee[ejW��Zhee[ejY��Ziejejk�Zlejejm�Znejejo�Zpejejq�Zrejejs�Ztejeju�Zvejejw�Zxejejy�Zzejej{�Z|ejej}�Z~ejej�Z�ejej��Z�ejej��Z�eej��Z�eej��Z�ee��Z�eej��Z�ee��Z�ee��Z�ee��Z�eej��Z�ee��Z�ee�j��Z�ee�j��Z�ee�j��Z�e�Z�e�Z�e�Z�e�Z�e�Z�e�Z�e�Z�ee�j��Z�ee�j��Z�dS) r0as	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~zt.Callable[[], T]r~Nr+r�9ContextVar[T] | Local | LocalStack[T] | t.Callable[[], T]r-r/r,rrcs�|durt�nt|���durd�t�t�r(|durtd��d���fdd�}n5t�t�r7d���fdd�}n&t�t�rFd���fdd�}nt��rSd��fd	d�}n
td
t���d���t	�
|d��t	�
|d
|�dS)Nzobject is not boundz2'name' is required when proxying a 'Local' object.rr
cs$z���WStyt��d�wr%)r8rr��get_namerr,rrr~�s


�z0LocalProxy.__init__.<locals>._get_current_objectcs�j}|durt����|�Sr%)rRr�rHr�rrr~�scs,z	���}W�|�Styt��d�wr%)r'�LookupErrorrr�r�rrr~�s
�
�cs
����Sr%rr)r�rrrr~rwzDon't know how to proxy 'z'.�_LocalProxy__wrappedr~)rr
)r�rrWr�	TypeErrorrEr�callablererr )r"rr-r,r~rr�rr#�s$


zLocalProxy.__init__cCs
t|�jSr%)rerCr)rrr�<lambda>�
zLocalProxy.<lambda>T)rlrjrkcCs|jSr%)r�r)rrrr�s)rjrkcCsdt|�j�d�S)Nrcz	 unbound>)rer@r)rrrr�s)rjcCsdS)NFrr)rrrr��cCsgSr%rr)rrrr�$r�cCst|�Sr%)rer)rrrr�0scC�
t||�Sr%)rWr�rrrr�2r�cCr�r%)�
issubclassr�rrrr�3r�cOs||i|��Sr%r)r"r�r�rrrr�5sr%)rr�r-r/r,r/rr)�r@rArBrCrD�__annotations__r#rh�__wrapped__�reprrfr.�__str__�bytes�	__bytes__�
__format__�operator�lt�__lt__�le�__le__�eq�__eq__�ne�__ne__�gt�__gt__�ge�__ge__�hash�__hash__rp�__bool__r�r;�setattrr �delattrr>�dir�__dir__r��__instancecheck__�__subclasscheck__r4rO�__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__r=�__copy__�deepcopy�__deepcopy__rrrrr0ys�
M��8
���





�





































r0)rrrr)r�rrr)r�r
rr
)#�
__future__rr=r#r��typingr��contextvarsr�	functoolsrrr�wsgir	�
TYPE_CHECKING�_typeshed.wsgir
rr�TypeVarr
�Callable�Anyrrr�GenericrErTrhr�r�r�r0rrrr�<module>s2

EPDZ