o
    ßý°j¨V  ã                   @  s>  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rId d	lmZ d d
lmZ d dlmZ e d¡Zejdejdejf d�Zd(dd„ZG dd„ dƒZG dd„ deje ƒZG dd„ dƒZG dd„ dƒZG dd„ deƒZd)d!d"„Z d*d$d%„Z!G d&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                 C  s   |   ¡  dS )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   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/werkzeug/local.pyÚrelease_local   s   	r   c                   @  sb   e Zd ZdZdZdd dd	„Zd!dd„Zddœd"dd„Zd#dd„Zd$dd„Z	d%dd„Z
d&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                 C  s.   |d u rt dt| ƒ› d�ƒ}t | d|¡ d S )Nzwerkzeug.Local<ú	>.storageÚ_Local__storage)r   ÚidÚobjectÚ__setattr__©Úselfr   r   r   r   Ú__init__6   s   zLocal.__init__út.Iterator[tuple[str, t.Any]]c                 C  s   t | j i ¡ ¡ ƒS ©N)Úiterr   ÚgetÚitems©r"   r   r   r   Ú__iter__@   s   zLocal.__iter__©Úunbound_messageÚnameÚstrr,   ú
str | NoneúLocalProxy[t.Any]c                C  ó   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+   ©Ú
LocalProxy©r"   r-   r,   r   r   r   Ú__call__C   s   
zLocal.__call__c                 C  s   | j  i ¡ d S r%   )r   Úsetr)   r   r   r   r   O   ó   zLocal.__release_local__út.Anyc                 C  s$   | j  i ¡}||v r|| S t|ƒ‚r%   )r   r'   ÚAttributeError©r"   r-   Úvaluesr   r   r   Ú__getattr__R   s   zLocal.__getattr__Úvaluec                 C  s(   | j  i ¡ ¡ }|||< | j  |¡ d S r%   )r   r'   Úcopyr6   )r"   r-   r=   r;   r   r   r   r    Z   s   zLocal.__setattr__c                 C  s:   | j  i ¡}||v r| ¡ }||= | j  |¡ d S t|ƒ‚r%   )r   r'   r>   r6   r9   r:   r   r   r   Ú__delattr___   s   zLocal.__delattr__r%   )r   r   r   r   )r   r$   )r-   r.   r,   r/   r   r0   ©r   r   )r-   r.   r   r8   )r-   r.   r=   r8   r   r   )r-   r.   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r#   r*   r5   r   r<   r    r?   r   r   r   r   r   #   s    

ÿ


r   c                   @  s`   e Zd ZdZdZdddd	„Zdd
d„Zd dd„Zd!dd„Ze	d!dd„ƒZ
	d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                 C  s&   |d u rt dt| ƒ› d�ƒ}|| _d S )Nzwerkzeug.LocalStack<r   )r   r   rG   r!   r   r   r   r#      s   
zLocalStack.__init__c                 C  s   | j  g ¡ d S r%   )rG   r6   r)   r   r   r   r   ‰   r7   zLocalStack.__release_local__Úobjr   úlist[T]c                 C  s*   | j  g ¡ ¡ }| |¡ | j  |¡ |S )z'Add a new item to the top of the stack.)rG   r'   r>   Úappendr6   )r"   rI   Ústackr   r   r   ÚpushŒ   s   
zLocalStack.pushúT | Nonec                 C  s<   | 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éÿÿÿÿ)rG   r'   Úlenr6   )r"   rL   Úrvr   r   r   Úpop“   s   zLocalStack.popc                 C  s$   | 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   NrO   )rG   r'   rP   )r"   rL   r   r   r   Útop    s   zLocalStack.topr+   r-   r/   r,   r0   c                C  r1   )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+   r2   r4   r   r   r   r5   ¬   s   zLocalStack.__call__r%   )r   rH   r   r   r@   )rI   r   r   rJ   )r   rN   )r-   r/   r,   r/   r   r0   )rA   rB   rC   rD   rE   r#   r   rM   rR   ÚpropertyrS   r5   r   r   r   r   rF   j   s    



ÿÿrF   c                   @  sJ   e Zd ZdZdZ	dddd	„Zdd
d„Zddd„Zddd„Zd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.
    )ÚlocalsNrV   úJNone | (Local | LocalStack[t.Any] | t.Iterable[Local | LocalStack[t.Any]])r   r   c                 C  s6   |d u r	g | _ d S t|tƒr|g| _ d S t|ƒ| _ d S r%   )rV   Ú
isinstancer   Úlist)r"   rV   r   r   r   r#   Ð   s
   

zLocalManager.__init__c                 C  s   | j D ]}t|ƒ qdS )z†Release the data in the locals for this context. Call this at
        the end of each request or use :meth:`make_middleware`.
        N)rV   r   )r"   r   r   r   r   ÚcleanupÜ   s   

ÿzLocalManager.cleanupÚappr   c                   s   d
‡ ‡fdd„}|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]c                   s   t ˆ | |ƒˆjƒS r%   )r	   rZ   )r\   r]   ©r[   r"   r   r   Úapplicationè   s   z1LocalManager.make_middleware.<locals>.applicationN)r\   r   r]   r
   r   r^   r   )r"   r[   r`   r   r_   r   Úmake_middlewareã   s   zLocalManager.make_middlewareÚfuncc                 C  s   t |  |¡|ƒ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):
                ...
        )r   ra   )r"   rb   r   r   r   Ú
middlewareï   s   
zLocalManager.middlewarer.   c                 C  s   dt | ƒj› dt| jƒ› d�S )Nú<z storages: ú>)ÚtyperA   rP   rV   r)   r   r   r   Ú__repr__û   s   zLocalManager.__repr__r%   )rV   rW   r   r   r@   )r[   r   r   r   )rb   r   r   r   ©r   r.   )
rA   rB   rC   rD   rE   r#   rZ   ra   rc   rg   r   r   r   r   rU   º   s    ý


rU   c                   @  sR   e Zd ZdZdZ				d"d#dd„Zd$dd„Zd%d&dd„Zd'dd„Zd(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_valuer-   NFÚfút.Callable[..., t.Any] | Nonerk   ú-t.Callable[[LocalProxy[t.Any]], t.Any] | Nonerm   út.Any | Nonerl   Úboolr   r   c                   sR   t ˆ dƒrd‡ fdd	„}nˆ d urd‡ fd
d	„}nd }|| _|| _|| _|| _d S )NÚ__get__Úinstancer0   rI   r8   r   út.Callable[..., t.Any]c                   s   ˆ   |t|ƒ¡S r%   ©rs   rf   ©rt   rI   ©rn   r   r   rj     s   z%_ProxyLookup.__init__.<locals>.bind_fc                   s
   t ˆ |ƒS r%   r   rw   rx   r   r   rj   %  s   
©rt   r0   rI   r8   r   ru   )Úhasattrrj   rk   rm   rl   )r"   rn   rk   rm   rl   rj   r   rx   r   r#     s   
	
z_ProxyLookup.__init__Úownerr0   r-   r.   c                 C  s
   || _ d S r%   ©r-   )r"   r{   r-   r   r   r   Ú__set_name__3  ó   
z_ProxyLookup.__set_name__rt   útype | Noner8   c                 C  sŒ   |d u r| j d ur| j S | S z| ¡ }W n  ty4   | jd u r!‚ | j ||¡}| jr0|ƒ  Y S | Y S w | jd ur@|  ||¡S t|| jƒS r%   )	rm   Ú_get_current_objectÚRuntimeErrorrk   rs   rl   rj   Úgetattrr-   )r"   rt   r{   rI   rk   r   r   r   rs   6  s"   


õ
z_ProxyLookup.__get__c                 C  s   d| j › �S )Nzproxy r|   r)   r   r   r   rg   Q  s   z_ProxyLookup.__repr__ÚargsÚkwargsc                 O  s   |   |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.
        rv   )r"   rt   rƒ   r„   r   r   r   r5   T  s   z_ProxyLookup.__call__)NNNF)
rn   ro   rk   rp   rm   rq   rl   rr   r   r   )r{   r0   r-   r.   r   r   r%   )rt   r0   r{   r   r   r8   rh   )rt   r0   rƒ   r8   r„   r8   r   r8   )
rA   rB   rC   rD   rE   r#   r}   rs   rg   r5   r   r   r   r   ri   ÿ   s    û
"
ri   c                      s,   e Zd ZdZdZ		dd‡ fd
d„Z‡  ZS )Ú	_ProxyIOpz…Look up an augmented assignment method on a proxied object. The
    method is wrapped to return the proxy instead of the object.
    r   Nrn   ro   rk   rp   r   r   c                   s&   t ƒ  ˆ |¡ d	‡ fdd„}|| _d S )
Nrt   r0   rI   r8   r   ru   c                   s    d‡‡ fdd„}|  |t|ƒ¡S )	Nr"   r8   Úotherr   r0   c                   s   ˆ | |ƒ ˆS r%   r   ©r"   r†   )rn   rt   r   r   Úi_opn  s   
z0_ProxyIOp.__init__.<locals>.bind_f.<locals>.i_op)r"   r8   r†   r8   r   r0   rv   )rt   rI   rˆ   rx   )rt   r   rj   m  s   z"_ProxyIOp.__init__.<locals>.bind_fry   )Úsuperr#   rj   )r"   rn   rk   rj   ©Ú	__class__rx   r   r#   f  s   
z_ProxyIOp.__init__)NN)rn   ro   rk   rp   r   r   )rA   rB   rC   rD   rE   r#   Ú__classcell__r   r   rŠ   r   r…   _  s    ýr…   Úopc                   s   d‡ fdd„}t  t|¡S )	z5Swap the argument order to turn an l-op into an r-op.rI   r8   r†   r   c                   s
   ˆ || ƒS r%   r   )rI   r†   ©r�   r   r   Úr_opz  r~   z_l_to_r_op.<locals>.r_opN)rI   r8   r†   r8   r   r8   )ÚtÚcastr   )r�   r�   r   rŽ   r   Ú
_l_to_r_opw  s   r’   Úoc                 C  s   | S r%   r   )r“   r   r   r   Ú	_identity€  s   r”   c                   @  sô  e Zd ZU dZdZded< 	 	dddœddd„Zeedd„ dd�Zedd„ dd�Zee	dd„ 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d„ d�Z ee!ƒZ"ee#ƒZ$ee%ƒZ&ee'dd„ d�Z(edd„ dd�Z)edd„ ƒZ*edd„ ƒZ+edd„ ƒZ,ee-ƒZ.eej/ƒZ0eej1ƒZ2eej3ƒZ4eej5ƒZ6ee7ƒZ8ee9ƒZ:ee;ƒZ<eej=ƒZ>eej?ƒZ@eejAƒZBeejCƒZDeejEƒZFeejGƒZHeejIƒZJeejKƒZLeeMƒZNeeOƒZPeejQƒZReejSƒZTeejUƒZVeejWƒZXeejYƒZZe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ƒƒZaee[ejKƒƒZbee[eMƒƒZcee[eOƒƒZdee[ejQƒƒZeee[ejSƒƒZfee[ejUƒƒZgee[ejWƒƒZhee[ejYƒƒZiejejkƒZlejejmƒZnejejoƒZpejejqƒZrejejsƒZtejejuƒZvejejwƒZxejejyƒZzeje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e—j˜ƒZ™ee—jšƒZ›ee—jœƒZ�eƒ Zžeƒ ZŸeƒ Z eƒ Z¡eƒ Z¢eƒ Z£eƒ Z¤ee¥j¥ƒZ¦ee¥j§ƒZ¨dS ) r3   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€   Nr+   r   ú9ContextVar[T] | Local | LocalStack[T] | t.Callable[[], T]r-   r/   r,   r   r   c                  sÚ   |d u rt ‰ nt|ƒ‰ ˆd u rd‰tˆtƒr(|d u rtdƒ‚d‡ ‡‡fdd„}n5tˆtƒr7d‡ ‡‡fdd„}n&tˆtƒrFd‡ ‡‡fdd„}ntˆƒrSd‡ ‡fd	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                     s$   zˆ ˆƒW S  t y   tˆƒd ‚w r%   )r9   r�   r   ©Úget_namer   r,   r   r   r€   ñ  s
   

ÿz0LocalProxy.__init__.<locals>._get_current_objectc                    s   ˆj } | d u rtˆƒ‚ˆ | ƒS r%   )rS   r�   ©rI   r—   r   r   r€   ù  s   c                    s,   z	ˆ  ¡ } W ˆ | ƒS  ty   tˆƒd ‚w r%   )r'   ÚLookupErrorr�   r™   r—   r   r   r€     s   
ý
ÿc                     s
   ˆ ˆƒ ƒS r%   r   r   )r˜   r   r   r   r€     r~   zDon't know how to proxy 'z'.Ú_LocalProxy__wrappedr€   )r   r   )r”   r   rX   r   Ú	TypeErrorrF   r   Úcallablerf   r   r    )r"   r   r-   r,   r€   r   r—   r   r#   Þ  s$   


zLocalProxy.__init__c                 C  s
   t | ƒjS r%   )rf   rD   r)   r   r   r   Ú<lambda>  ó   
 zLocalProxy.<lambda>T)rm   rk   rl   c                 C  s   | j S r%   )r›   r)   r   r   r   rž     s    )rk   rl   c                 C  s   dt | ƒj› d�S )Nrd   z	 unbound>)rf   rA   r)   r   r   r   rž     s    )rk   c                 C  s   dS )NFr   r)   r   r   r   rž   +  ó    c                 C  s   g S r%   r   r)   r   r   r   rž   0  r    c                 C  s   t | ƒS r%   )rf   r)   r   r   r   rž   ;  s    c                 C  ó
   t || ƒS r%   )rX   r‡   r   r   r   rž   <  rŸ   c                 C  r¡   r%   )Ú
issubclassr‡   r   r   r   rž   =  rŸ   c                 O  s   | |i |¤ŽS r%   r   )r"   rƒ   r„   r   r   r   rž   ?  s    r%   )r   r–   r-   r/   r,   r/   r   r   )©rA   rB   rC   rD   rE   Ú__annotations__r#   ri   Ú__wrapped__Úreprrg   r.   Ú__str__ÚbytesÚ	__bytes__Ú
__format__ÚoperatorÚltÚ__lt__ÚleÚ__le__ÚeqÚ__eq__ÚneÚ__ne__ÚgtÚ__gt__ÚgeÚ__ge__ÚhashÚ__hash__rr   Ú__bool__r‚   r<   Úsetattrr    Údelattrr?   ÚdirÚ__dir__r‹   Ú__instancecheck__Ú__subclasscheck__r5   rP   Ú__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__r   r   r   r   r3   „  sÚ   
 Mýû8
ÿþÿ











































r3   )r   r   r   r   )r�   r   r   r   )r“   r   r   r   )#Ú
__future__r   r>   r%  rª   Útypingr�   Úcontextvarsr   Ú	functoolsr   r   r   Úwsgir	   ÚTYPE_CHECKINGÚ_typeshed.wsgir
   r   r   ÚTypeVarr   ÚCallableÚAnyr   r   r   ÚGenericrF   rU   ri   r…   r’   r”   r3   r   r   r   r   Ú<module>   s2    

GPE`

	