U
    ÌZj6W  ã                   @   sJ  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 d¡Zejdejdejf d�Zejd d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eedœdd„Zeed œd!d"„Z G d#d$„ d$eje ƒZ!dS )%é    N)Ú
ContextVar©Úpartial)Úupdate_wrapper)Ú
attrgetteré   )ÚClosingIterator)ÚStartResponse)ÚWSGIApplication)ÚWSGIEnvironmentÚTÚF.)Úbound)ÚLocalÚ
LocalStack)ÚlocalÚreturnc                 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   úQ/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/werkzeug/local.pyÚrelease_local   s    	r   c                   @   s¾   e Zd ZdZdZdejeeje	ej
f   ddœdd„Zejeje	ej
f  dœdd	„Zdd
œe	eje	 ddœdd„Zddœdd„Ze	ej
dœdd„Ze	ej
ddœdd„Ze	ddœdd„ZdS )r   aq  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_varr   c                 C   s.   |d krt dt| ƒ› d�ƒ}t | d|¡ d S )Nzwerkzeug.Local<ú	>.storageÚ_Local__storage)r   ÚidÚobjectÚ__setattr__©Úselfr   r   r   r   Ú__init__4   s    zLocal.__init__©r   c                 C   s   t | j i ¡ ¡ ƒS ©N)Úiterr   ÚgetÚitems©r   r   r   r   Ú__iter__@   s    zLocal.__iter__©Úunbound_messageÚ
LocalProxy©Únamer)   r   c                C   s   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(   ©r*   ©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   s    zLocal.__release_local__)r,   r   c                 C   s(   | j  i ¡}||kr|| S t|ƒ‚d S r"   )r   r$   ÚAttributeError©r   r,   Úvaluesr   r   r   Ú__getattr__R   s    zLocal.__getattr__)r,   Úvaluer   c                 C   s(   | j  i ¡ ¡ }|||< | j  |¡ d S r"   )r   r$   Úcopyr0   )r   r,   r5   r3   r   r   r   r   Z   s    zLocal.__setattr__c                 C   s<   | j  i ¡}||kr0| ¡ }||= | j  |¡ nt|ƒ‚d S r"   )r   r$   r6   r0   r1   r2   r   r   r   Ú__delattr___   s    zLocal.__delattr__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ÚtÚOptionalr   ÚDictÚstrÚAnyr    ÚIteratorÚTupler'   r/   r   r4   r   r7   r   r   r   r   r   !   s$    ÿþ ÿ þr   c                   @   s¬   e Zd ZdZdZdejeeje	   ddœdd„Z
ddœdd	„Ze	eje	 d
œdd„Zeje	 dœdd„Zeeje	 dœdd„ƒZdddœeje eje ddœdd„ZdS )r   aŠ  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   c                 C   s&   |d krt dt| ƒ› d�ƒ}|| _d S )Nzwerkzeug.LocalStack<r   )r   r   rD   r   r   r   r   r       s    zLocalStack.__init__r!   c                 C   s   | j  g ¡ d S r"   )rD   r0   r&   r   r   r   r   ‰   s    zLocalStack.__release_local__)Úobjr   c                 C   s*   | j  g ¡ ¡ }| |¡ | j  |¡ |S )z'Add a new item to the top of the stack.)rD   r$   r6   Úappendr0   )r   rE   Ústackr   r   r   ÚpushŒ   s    
zLocalStack.pushc                 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éÿÿÿÿ)rD   r$   Úlenr0   )r   rG   Ú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   NrI   )rD   r$   rJ   )r   rG   r   r   r   Útop    s    zLocalStack.topr(   r*   r+   c                C   s   t | ||d�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.
        r(   r-   r.   r   r   r   r/   ¬   s    zLocalStack.__call__)N)N)r8   r9   r:   r;   r<   r=   r>   r   ÚListr   r    r   rH   rL   ÚpropertyrM   r@   r/   r   r   r   r   r   j   s    "
 ÿÿ þr   c                	   @   s„   e Zd ZdZdZdejejee	ej
ejee	f  f  ddœdd„Zddœdd	„Zd
d
dœdd„Zd
d
dœdd„Ze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.0
        ``ident_func`` is deprecated and will be removed in Werkzeug
         2.1.

    .. 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.
    )ÚlocalsN)rQ   r   c                 C   s2   |d krg | _ nt|tƒr$|g| _ n
t|ƒ| _ d S r"   )rQ   Ú
isinstancer   Úlist)r   rQ   r   r   r   r    Ñ   s
    

zLocalManager.__init__r!   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)rQ   r   )r   r   r   r   r   ÚcleanupÞ   s    
zLocalManager.cleanupr
   )Úappr   c                    s"   ddt jt 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.
        r   r	   )ÚenvironÚstart_responser   c                    s   t ˆ | |ƒˆjƒS r"   )r   rT   )rV   rW   ©rU   r   r   r   Úapplicationê   s    z1LocalManager.make_middleware.<locals>.application)r=   ÚIterableÚbytes)r   rU   rY   r   rX   r   Úmake_middlewareå   s
     þzLocalManager.make_middleware)Úfuncr   c                 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   r\   )r   r]   r   r   r   Ú
middlewareñ   s    
zLocalManager.middlewarec                 C   s   dt | ƒj› dt| jƒ› d�S )Nú<z storages: ú>)Útyper8   rJ   rQ   r&   r   r   r   Ú__repr__ý   s    zLocalManager.__repr__)N)r8   r9   r:   r;   r<   r=   r>   ÚUnionr   r   rZ   r    rT   r\   r^   r@   rb   r   r   r   r   rP   º   s    üÿûrP   c                   @   sš   e Zd ZdZdZdejej ejej ejej e	ddœdd„Z
dedd	œd
d„Zddeje ejdœdd„Zedœdd„Zdejejej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)Úfrf   rh   rg   r   c                    sj   t ˆ dƒr&dtjtjdœ‡ fdd„}n(ˆ d k	rJdtjtjdœ‡ fdd„}nd }|| _|| _|| _|| _d S )NÚ__get__r*   ©ÚinstancerE   r   c                    s   ˆ   |t|ƒ¡S r"   ©rj   ra   ©rl   rE   ©ri   r   r   re     s    z%_ProxyLookup.__init__.<locals>.bind_fc                    s
   t ˆ |ƒS r"   r   rn   ro   r   r   re   %  s    )Úhasattrr=   rA   ÚCallablere   rf   rh   rg   )r   ri   rf   rh   rg   re   r   ro   r   r      s    	
z_ProxyLookup.__init__r*   )Úownerr,   r   c                 C   s
   || _ d S r"   ©r,   )r   rr   r,   r   r   r   Ú__set_name__1  s    z_ProxyLookup.__set_name__)rl   rr   r   c                 C   sŽ   |d kr| j d k	r| j S | S z| ¡ }W nB tk
rj   | jd krD‚ | j ||¡}| jrb|ƒ  Y S | Y S X | jd k	r‚|  ||¡S t|| jƒS r"   )	rh   Ú_get_current_objectÚRuntimeErrorrf   rj   rg   re   Úgetattrr,   )r   rl   rr   rE   rf   r   r   r   rj   4  s     




z_ProxyLookup.__get__r!   c                 C   s   d| j › �S )Nzproxy rs   r&   r   r   r   rb   O  s    z_ProxyLookup.__repr__)rl   ÚargsÚkwargsr   c                 O   s   |   |t|ƒ¡||Ž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.
        rm   )r   rl   rx   ry   r   r   r   r/   R  s    z_ProxyLookup.__call__)NNNF)N)r8   r9   r:   r;   r<   r=   r>   rq   rA   Úboolr    r@   rt   ra   rj   rb   r/   r   r   r   r   rd     s"       û


úrd   c                       s@   e Zd ZdZdZdejej ejej 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   N)ri   rf   r   c                    s2   t ƒ  ˆ |¡ dtjtjdœ‡ fdd„}|| _d S )Nr*   rk   c                    s,   t jt jddœ‡‡ fdd„}| |t|ƒ¡S )Nr*   )r   Úotherr   c                    s   ˆ | |ƒ ˆS r"   r   ©r   r|   )ri   rl   r   r   Úi_oph  s    
z0_ProxyIOp.__init__.<locals>.bind_f.<locals>.i_op)r=   rA   rj   ra   )rl   rE   r~   ro   )rl   r   re   g  s    z"_ProxyIOp.__init__.<locals>.bind_f)Úsuperr    r=   rA   rq   re   )r   ri   rf   re   ©Ú	__class__ro   r   r    b  s    z_ProxyIOp.__init__)NN)
r8   r9   r:   r;   r<   r=   r>   rq   r    Ú__classcell__r   r   r€   r   r{   [  s      ÿ
 
þr{   )Úopr   c                    s(   t jt jt jdœ‡ fdd„}t  t|¡S )z5Swap the argument order to turn an l-op into an r-op.)rE   r|   r   c                    s
   ˆ || ƒS r"   r   )rE   r|   ©rƒ   r   r   Úr_opt  s    z_l_to_r_op.<locals>.r_op)r=   rA   Úcastr   )rƒ   r…   r   r„   r   Ú
_l_to_r_opq  s    r‡   )Úor   c                 C   s   | S r"   r   )rˆ   r   r   r   Ú	_identityz  s    r‰   c                	   @   s0  e Zd ZU dZdZejg ef ed< dddœej	e
e eee ejg ef f eje eje 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�Z0edd
„ dd�Z1edd
„ ƒZ2edd
„ ƒZ3edd
„ ƒZ4ee5ƒZ6eej7ƒZ8eej9ƒZ:eej;ƒZ<eej=ƒZ>ee?ƒZ@eeAƒZBeeCƒZDeejEƒZFeejGƒZHeejIƒZJeejKƒZLeejMƒZNeejOƒZPeejQƒZReejSƒZTeeUƒZVeeWƒZXeejYƒZZeej[ƒZ\eej]ƒZ^eej_ƒZ`eejaƒZbeecejGƒƒZdeecejIƒƒZeeecejKƒƒZfeecejMƒƒZgeecejOƒƒZheecejQƒƒZieecejSƒƒZjeeceUƒƒZkeeceWƒƒZleecejYƒƒZmeecej[ƒƒZneecej]ƒƒZoeecej_ƒƒZpeecejaƒƒZqerejsƒZterejuƒZverejwƒZxerejyƒZzerej{ƒZ|erej}ƒZ~erejƒZ€erej�ƒZ‚erejƒƒZ„erej…ƒZ†erej‡ƒZˆerej‰ƒZŠere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 )r*   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	__wrappedru   ru   Nr(   )r   r,   r)   r   c                   sê   |d krt ‰ nt|ƒ‰ ˆd kr"d‰tˆtƒrT|d kr<tdƒ‚tdœ‡ ‡‡fdd„}nvtˆtƒrvtdœ‡ ‡‡fdd„}nTtˆtƒr˜tdœ‡ ‡‡fdd„}n2tˆƒr¶tdœ‡ ‡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!   c                      s.   z
ˆ ˆƒW S  t k
r(   tˆƒd ‚Y nX d S r"   )r1   rv   r   ©Úget_namer   r)   r   r   ru   ë  s    
z0LocalProxy.__init__.<locals>._get_current_objectc                     s   ˆj } | d krtˆƒ‚ˆ | ƒS r"   )rM   rv   ©rE   rŠ   r   r   ru   ó  s    c                     s4   zˆ  ¡ } W n tk
r*   tˆƒd ‚Y nX ˆ | ƒS r"   )r$   ÚLookupErrorrv   rŒ   rŠ   r   r   ru   ý  s
    c                      s
   ˆ ˆƒ ƒS r"   r   r   )r‹   r   r   r   ru     s    zDon't know how to proxy 'z'.Ú_LocalProxy__wrappedru   )r‰   r   rR   r   Ú	TypeErrorr   r   r   Úcallablera   r   r   )r   r   r,   r)   ru   r   rŠ   r   r    Ø  s$    


zLocalProxy.__init__c                 C   s
   t | ƒjS r"   )ra   r;   r&   r   r   r   Ú<lambda>  ó    zLocalProxy.<lambda>T)rh   rf   rg   c                 C   s   | j S r"   )rŽ   r&   r   r   r   r‘     r’   )rf   rg   c                 C   s   dt | ƒj› d�S )Nr_   z	 unbound>)ra   r8   r&   r   r   r   r‘     r’   )rf   c                 C   s   dS )NFr   r&   r   r   r   r‘   $  r’   c                 C   s   g S r"   r   r&   r   r   r   r‘   )  r’   c                 C   s   t | ƒS r"   )ra   r&   r   r   r   r‘   5  r’   c                 C   s
   t || ƒS r"   )rR   r}   r   r   r   r‘   7  r’   c                 C   s
   t || ƒS r"   )Ú
issubclassr}   r   r   r   r‘   8  r’   c                 O   s
   | ||ŽS r"   r   )r   rx   ry   r   r   r   r‘   :  r’   )N)±r8   r9   r:   r;   r<   r=   rq   r   Ú__annotations__rc   r   r   r   r>   r@   r    rd   Ú__wrapped__Úreprrb   Ú__str__r[   Ú	__bytes__Ú
__format__ÚoperatorÚltÚ__lt__ÚleÚ__le__ÚeqÚ__eq__ÚneÚ__ne__ÚgtÚ__gt__ÚgeÚ__ge__ÚhashÚ__hash__rz   Ú__bool__rw   r4   Úsetattrr   Údelattrr7   ÚdirÚ__dir__r�   Ú__instancecheck__Ú__subclasscheck__r/   rJ   Ú__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__r6   Ú__copy__ÚdeepcopyÚ__deepcopy__r   r   r   r   r*   ~  sì   
M ýû"ú8  ÿ ÿ ÿ





 ÿ





































r*   )"r6   r  rš   Útypingr=   Zcontextvarsr   Ú	functoolsr   r   r   Zwsgir   ÚTYPE_CHECKINGZ_typeshed.wsgir	   r
   r   ÚTypeVarr   rq   rA   r   rc   r   r   ÚGenericr   rP   rd   r{   r‡   r‰   r*   r   r   r   r   Ú<module>   s.   
IPGZ	