o
    1)hW                     @  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 )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    r   MC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\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.
    )Z	__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 )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!   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&   copyr5   )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=   r5   r8   r9   r   r   r   __delattr___   s   zLocal.__delattr__r$   )r   r   r   r   )r   r#   )r,   r-   r+   r.   r   r/   r   r   )r,   r-   r   r7   )r,   r-   r<   r7   r   r   )r,   r-   r   r   )__name__
__module____qualname____doc__	__slots__r"   r)   r4   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   rF   r    r   r   r   r"      s   
zLocalStack.__init__c                 C  s   | j g  d S r$   )rF   r5   r(   r   r   r   r      r6   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.)rF   r&   r=   appendr5   )r!   rH   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)rF   r&   lenr5   )r!   rK   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   NrN   )rF   r&   rO   )r!   rK   r   r   r   top   s   zLocalStack.topr*   r,   r.   r+   r/   c                C  r0   )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   r   r   r   r4      s   zLocalStack.__call__r$   )r   rG   r   r   r?   )rH   r   r   rI   )r   rM   )r,   r.   r+   r.   r   r/   )r@   rA   rB   rC   rD   r"   r   rL   rQ   propertyrR   r4   r   r   r   r   rE   j   s    



rE   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.
    )localsNrU   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$   )rU   
isinstancer   list)r!   rU   r   r   r   r"      s
   

zLocalManager.__init__c                 C  s   | j D ]}t| q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)rU   r   )r!   r   r   r   r   cleanup   s   

zLocalManager.cleanupappr   c                   s   d
 fd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                   s   t  | |jS r$   )r	   rY   )r[   r\   rZ   r!   r   r   application   s   z1LocalManager.make_middleware.<locals>.applicationN)r[   r   r\   r
   r   r]   r   )r!   rZ   r_   r   r^   r   make_middleware   s   zLocalManager.make_middlewarefuncc                 C  s   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   r`   )r!   ra   r   r   r   
middleware   s   
zLocalManager.middlewarer-   c                 C  s   dt | j dt| j dS )N<z storages: >)typer@   rO   rU   r(   r   r   r   __repr__   s   zLocalManager.__repr__r$   )rU   rV   r   r   r?   )rZ   r   r   r   )ra   r   r   r   r   r-   )
r@   rA   rB   rC   rD   r"   rY   r`   rb   rf   r   r   r   r   rT      s    


rT   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] | Nonerj   -t.Callable[[LocalProxy[t.Any]], t.Any] | Nonerl   t.Any | Nonerk   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__instancer/   rH   r7   r   t.Callable[..., t.Any]c                   s     |t|S r$   rr   re   rs   rH   rm   r   r   ri     s   z%_ProxyLookup.__init__.<locals>.bind_fc                   s
   t  |S r$   r   rv   rw   r   r   ri   %  s   
rs   r/   rH   r7   r   rt   )hasattrri   rj   rl   rk   )r!   rm   rj   rl   rk   ri   r   rw   r   r"     s   
	
z_ProxyLookup.__init__ownerr/   r,   r-   c                 C  s
   || _ d S r$   r,   )r!   rz   r,   r   r   r   __set_name__3     
z_ProxyLookup.__set_name__rs   type | Noner7   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$   )	rl   _get_current_objectRuntimeErrorrj   rr   rk   ri   getattrr,   )r!   rs   rz   rH   rj   r   r   r   rr   6  s"   



z_ProxyLookup.__get__c                 C  s   d| j  S )Nzproxy r{   r(   r   r   r   rf   Q  s   z_ProxyLookup.__repr__argskwargsc                 O  s   |  |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.
        ru   )r!   rs   r   r   r   r   r   r4   T  s   z_ProxyLookup.__call__)NNNF)
rm   rn   rj   ro   rl   rp   rk   rq   r   r   )rz   r/   r,   r-   r   r   r$   )rs   r/   rz   r~   r   r7   rg   )rs   r/   r   r7   r   r7   r   r7   )
r@   rA   rB   rC   rD   r"   r|   rr   rf   r4   r   r   r   r   rh      s    
"
rh   c                      s,   e Zd ZdZdZ		dd fd
dZ  ZS )	_ProxyIOpzLook up an augmented assignment method on a proxied object. The
    method is wrapped to return the proxy instead of the object.
    r   Nrm   rn   rj   ro   r   r   c                   s&   t   | d	 fdd}|| _d S )
Nrs   r/   rH   r7   r   rt   c                   s    d fdd}| |t|S )	Nr!   r7   otherr   r/   c                   s    | | S r$   r   r!   r   )rm   rs   r   r   i_opn  s   
z0_ProxyIOp.__init__.<locals>.bind_f.<locals>.i_op)r!   r7   r   r7   r   r/   ru   )rs   rH   r   rw   )rs   r   ri   m  s   z"_ProxyIOp.__init__.<locals>.bind_frx   )superr"   ri   )r!   rm   rj   ri   	__class__rw   r   r"   f  s   
z_ProxyIOp.__init__)NN)rm   rn   rj   ro   r   r   )r@   rA   rB   rC   rD   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.rH   r7   r   r   c                   s
    || S r$   r   )rH   r   r   r   r   r_opz  r}   z_l_to_r_op.<locals>.r_opN)rH   r7   r   r7   r   r7   )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ZejejZejejZeejZeejZeeZeejZeeZeeZeeZeejZeeZeejZeejZeejZe Ze Ze Ze Ze Ze Ze ZeejZeejZdS ) r2   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.
    )Z	__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$   )r8   r   r   get_namer   r+   r   r   r     s
   

z0LocalProxy.__init__.<locals>._get_current_objectc                    s   j } | d u rt | S r$   )rR   r   rH   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   rW   r   	TypeErrorrE   r   callablere   r   r   )r!   r   r,   r+   r   r   r   r   r"     s$   


zLocalProxy.__init__c                 C  s
   t | jS r$   )re   rC   r(   r   r   r   <lambda>     
 zLocalProxy.<lambda>T)rl   rj   rk   c                 C  s   | j S r$   )r   r(   r   r   r   r     s    )rj   rk   c                 C  s   dt | j dS )Nrc   z	 unbound>)re   r@   r(   r   r   r   r     s    )rj   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$   )re   r(   r   r   r   r   ;  s    c                 C  
   t || S r$   )rW   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   )r@   rA   rB   rC   rD   __annotations__r"   rh   __wrapped__reprrf   r-   __str__bytes	__bytes__
__format__operatorlt__lt__le__le__eq__eq__ne__ne__gt__gt__ge__ge__hash__hash__rq   __bool__r   r;   setattrr   delattrr>   dir__dir__r   __instancecheck____subclasscheck__r4   rO   __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   r2     s   
 M8












































r2   )r   r   r   r   )r   r   r   r   )r   r   r   r   )#
__future__r   r=   r#  r   typingr   contextvarsr   	functoolsr   r   r   Zwsgir	   TYPE_CHECKINGZ_typeshed.wsgir
   r   r   TypeVarr   CallableAnyr   r   r   GenericrE   rT   rh   r   r   r   r2   r   r   r   r   <module>   s2    

GPE`

	