U aX @s ddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ej r~ddl mZddl mZddl mZejd ejd ejfd Zzdd lmZWn ek rdd lmZYnXedddZGdddeZzddlmZdej ksdej krtddlZe!eddZ"e"stzddl#m$Z$Wnek rTeYn Xe$ddrte$ddsteWn(eefk rGdddZYnXej%dddd d!Z&Gd"d#d#Z'Gd$d%d%Z(Gd&d'd'Z)Gd(d)d)Z*Gd*d+d+e*Z+eed,d-d.Z,Gd/d0d0Z-dS)1Npartial)update_wrapper)ClosingIterator) StartResponse)WSGIApplication)WSGIEnvironmentF.)bound) getcurrent) get_identreturncCstjdtddtS)Nz'get_ident' is deprecated and will be removed in Werkzeug 2.1. Use 'greenlet.getcurrent' or 'threading.get_ident' for previous behavior. stacklevelwarningswarnDeprecationWarning _get_identrrOC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-1tps7o9u\werkzeug\local.pyr s r c@s eZdZdS)_CannotUseContextVarN)__name__ __module__ __qualname__rrrrr$sr) ContextVarZgeventZeventletZGREENLET_USE_CONTEXT_VARSF)is_object_patched threadinglocal contextvarsrc@sdeZdZdZeddddZejeejfejeejfdddZ ejeejfdd d d Z dS) rzA fake ContextVar based on the previous greenlet/threading ident function. Used on Python 3.6, eventlet, and old versions of gevent. N)_namercCs i|_dSN)storage)selfr#rrr__init__IszContextVar.__init__)defaultrcCs|jt|Sr$)r%getr)r&r(rrrr)LszContextVar.getvaluercCs||jt<dSr$)r%rr&r+rrrsetOszContextVar.set) rrr__doc__strr'tDictAnyr)r-rrrrrCs()Local LocalStack)r!rcCs |dS)aMReleases the contents of the local for the current context. This makes it possible to use locals without a manager. Example:: >>> loc = Local() >>> loc.foo = 42 >>> release_local(loc) >>> hasattr(loc, 'foo') False With this function one can release :class:`Local` objects as well as :class:`LocalStack` objects. However it is not possible to release data held by proxies that way, one always has to retain a reference to the underlying local object in order to be able to release it. .. versionadded:: 0.6.1 N)__release_local__)r!rrr release_localSsr6c@seZdZdZddddZeejeej fdddZ eej ge fddd Z e jej ge fdd d d Z ejeje ej fdd d ZeddddZddddZeej dddZeej ddddZeddddZdS)r3)_storageNrcCst|dtddS)Nr7Z local_storage)object __setattr__rr&rrrr'mszLocal.__init__cCstjdtdd|jiS)Nz@'__storage__' is deprecated and will be removed in Werkzeug 2.1.rr)rrrr7r)r:rrr __storage__ps zLocal.__storage__cCstjdtddtS)Nzi'__ident_func__' is deprecated and will be removed in Werkzeug 2.1. It should not be used in Python 3.7+.rrrr:rrr__ident_func__ys zLocal.__ident_func__funcrcCstjdtdddS)Nzh'__ident_func__' is deprecated and will be removed in Werkzeug 2.1. Setting it no longer has any effect.rrrrrr&r>rrrr<s cCst|jiSr$)iterr7r)itemsr:rrr__iter__szLocal.__iter__ LocalProxy)proxyrcCs t||S)zCreate a proxy for a name.)rD)r&rErrr__call__szLocal.__call__cCs|jidSr$)r7r-r:rrrr5szLocal.__release_local__)namercCs8|ji}z ||WStk r2t|YnXdSr$)r7r)KeyErrorAttributeErrorr&rGvaluesrrr __getattr__s   zLocal.__getattr__)rGr+rcCs(|ji}|||<|j|dSr$)r7r)copyr-)r&rGr+rKrrrr9szLocal.__setattr__cCsH|ji}z||=|j|Wntk rBt|YnXdSr$)r7r)rMr-rHrIrJrrr __delattr__s zLocal.__delattr__)rrr __slots__r'propertyr0r1r/r2r;Callableintr<setterIteratorTuplerCrFr5rLr9rNrrrrr3js  r3c@seZdZdZddddZddddZeejge fddd Z e j ejge fdd d d Z d dd dZ ej ejej dddZej dddZeej dddZdS)r4aThis class works similar to a :class:`Local` but keeps a stack of objects instead. This is best explained with an example:: >>> ls = LocalStack() >>> ls.push(42) >>> ls.top 42 >>> ls.push(23) >>> ls.top 23 >>> ls.pop() 23 >>> ls.top 42 They can be force released by using a :class:`LocalManager` or with the :func:`release_local` function but the correct way is to pop the item from the stack after using. When the stack is empty it will no longer be bound to the current context (and as such released). By calling the stack without arguments it returns a proxy that resolves to the topmost item on the stack. .. versionadded:: 0.6.1 NrcCs t|_dSr$)r3_localr:rrrr'szLocalStack.__init__cCs|jdSr$)rVr5r:rrrr5szLocalStack.__release_local__cCs|jjSr$)rVr<r:rrrr<szLocalStack.__ident_func__r*cCst|jd|dS)Nr<)r8r9rVr,rrrr<srDcstjdfdd }t|S)Nrcsj}|dkrtd|S)Nzobject unbound)top RuntimeError)rvr:rr_lookupsz$LocalStack.__call__.._lookup)r0r2rD)r&rZrr:rrFszLocalStack.__call__)objrcCs(t|jdg}||||j_|S)zPushes a new item to the stackstack)getattrrVrMappendr\)r&r[rYrrrpushs zLocalStack.pushcCsDt|jdd}|dkrdSt|dkr8t|j|dS|SdS)z}Removes the topmost item from the stack, will return the old value or `None` if the stack was already empty. r\Nr)r]rVlenr6pop)r&r\rrrrbs  zLocalStack.popc Cs.z|jjdWSttfk r(YdSXdS)z[The topmost item on the stack. If the stack is empty, `None` is returned. r`N)rVr\rI IndexErrorr:rrrrWszLocalStack.top)rrrr.r'r5rPr0rQrRr<rSrFr2Listr_rbrWrrrrr4s  r4c@seZdZdZdejejejee fdddddZ e ej ge fdddZejej ge fdd d dZe dd d Zddd dZdddddZddd ddZedddZdS) LocalManageraZLocal objects cannot manage themselves. For that you need a local manager. You can pass a local manager multiple locals or add them later y appending them to `manager.locals`. Every time the manager cleans up, it will clean up all the data left in the locals for this context. .. versionchanged:: 2.0 ``ident_func`` is deprecated and will be removed in Werkzeug 2.1. .. versionchanged:: 0.6.1 The :func:`release_local` function can be used instead of a manager. .. versionchanged:: 0.7 The ``ident_func`` parameter was added. N)locals ident_funcrcCsJ|dkrg|_nt|tr$|g|_n t||_|dk rFtjdtdddS)Nzd'ident_func' is deprecated and will be removed in Werkzeug 2.1. Setting it no longer has any effect.rr)rf isinstancer3listrrr)r&rfrgrrrr's   zLocalManager.__init__rcCstjdtddtS)Nz?'ident_func' is deprecated and will be removed in Werkzeug 2.1.rrrr:rrrrg#s zLocalManager.ident_funcr=cCstjdtdddS)Nzc'ident_func' is deprecated and will be removedin Werkzeug 2.1. Setting it no longer has any effect.rrr?r@rrrrg,s cCstjdtdd|S)a*Return the context identifier the local objects use internally for this context. You cannot override this method to change the behavior but use it to link other context local objects (such as SQLAlchemy's scoped sessions) to the Werkzeug locals. .. deprecated:: 2.0 Will be removed in Werkzeug 2.1. .. versionchanged:: 0.7 You can pass a different ident function to the local manager that will then be propagated to all the locals passed to the constructor. z>'get_ident' is deprecated and will be removed in Werkzeug 2.1.rr)rrrrgr:rrrr 5s zLocalManager.get_identcCs|jD] }t|qdS)zManually clean up the data in the locals for this context. Call this at the end of the request or use `make_middleware()`. N)rfr6)r&r!rrrcleanupJs zLocalManager.cleanupr)apprcs"ddtjtdfdd }|S)zWWrap a WSGI application so that cleaning up happens after request end. r r)environstart_responsercst||jSr$)rrj)rlrmrkr&rr applicationVsz1LocalManager.make_middleware..application)r0Iterablebytes)r&rkrorrnrmake_middlewareQs zLocalManager.make_middlewarecCst|||S)asLike `make_middleware` but for decorating functions. Example usage:: @manager.middleware def application(environ, start_response): ... The difference to `make_middleware` is that the function passed will have all the arguments copied from the inner application (name, docstring, module). )rrrr@rrr middleware]s zLocalManager.middlewarecCsdt|jdt|jdS)N)typerrarfr:rrr__repr__lszLocalManager.__repr__)NN)rrrr.r0OptionalrpUnionr3r4r'rPrQrRrgrSr rjrrrsr/rwrrrrres"  rec@seZdZdZdZdejejejejejejddddZ de ddd d Z ddeje ejd d d Z e dddZdejejejdddZdS) _ProxyLookupaDescriptor 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: Call this method if the proxy is unbound instead of raising a :exc:`RuntimeError`. :param class_value: Value to return when accessed from the class. Used for ``__doc__`` so building docs still works. )bind_ffallback class_valuerGN)fr|r}rcsdtdr&dtjtjdfdd }n(dk rJdtjtjdfdd }nd}||_||_||_dS)N__get__rDinstancer[rcs|t|Sr$rrvrr[r~rrr{sz%_ProxyLookup.__init__..bind_fcs t|Sr$rrrrrr{s)hasattrr0r2rQr{r|r})r&r~r|r}r{rrrr's z_ProxyLookup.__init__rD)ownerrGrcCs ||_dSr$rG)r&rrGrrr __set_name__sz_ProxyLookup.__set_name__)rrrcCsz|dkr|jdk r|jS|Sz |}Wn.tk rV|jdkrD|j||YSX|jdk rn|||St||jSr$)r}_get_current_objectrXr|rr{r]rG)r&rrr[rrrrs     z_ProxyLookup.__get__rcCs d|jS)Nzproxy rr:rrrrwsz_ProxyLookup.__repr__)rargskwargsrcOs||t|||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&rrrrrrrFsz_ProxyLookup.__call__)NNN)N)rrrr.rOr0rxrQr2r'r/rrvrrwrFrrrrrzps     rzcs@eZdZdZdZdejejejejddfdd ZZ S) _ProxyIOpzLook up an augmented assignment method on a proxied object. The method is wrapped to return the proxy instead of the object. rN)r~r|rcs2t|dtjtjdfdd }||_dS)NrDrcs,tjtjddfdd }||t|S)NrD)r&otherrcs||Sr$rr&r)r~rrri_ops z0_ProxyIOp.__init__..bind_f..i_op)r0r2rrv)rr[rr)rrr{sz"_ProxyIOp.__init__..bind_f)superr'r0r2rQr{)r&r~r|r{ __class__rrr'sz_ProxyIOp.__init__)NN) rrrr.rOr0rxrQr' __classcell__rrrrrs r)oprcs(tjtjtjdfdd }tt|S)z5Swap the argument order to turn an l-op into an r-op.)r[rrcs ||Sr$r)r[rrrrr_opsz_l_to_r_op..r_op)r0r2castr )rrrrr _l_to_r_opsrc@seZdZdZdZdejdejgejffej e ddddZ ejdd d Z e ed d d Ze edd dZe e Ze eZe Ze ejZe ejZe ejZe ejZe ejZe ejZ e e!Z"e e#dd dZ$e e%Z&e e'Z(e e)Z*e e+dd dZ,e dd dZ-e dd Z.e dd Z/e dd Z0e e1Z2e ej3Z4e ej5Z6e ej7Z8e ej9Z:e e;Ze e?Z@e ejAZBe ejCZDe ejEZFe ejGZHe ejIZJe ejKZLe ejMZNe ejOZPe eQZRe eSZTe ejUZVe ejWZXe ejYZZe ej[Z\e ej]Z^e e_ejCZ`e e_ejEZae e_ejGZbe e_ejIZce e_ejKZde e_ejMZee e_ejOZfe e_eQZge e_eSZhe e_ejUZie e_ejWZje e_ejYZke e_ej[Zle e_ej]ZmenejoZpenejqZrenejsZtenejuZvenejwZxenejyZzenej{Z|enej}Z~enejZenejZenejZenejZenejZe ejZe ejZe eZe ejZe eZe eZe eZe ejZe eZe ejZe ejZe ejZe Ze Ze Ze Ze Ze Ze Ze ejZe ejZdS)rDauA proxy to the object bound to a :class:`Local`. All operations on the proxy are forwarded to the bound object. If no object is bound, a :exc:`RuntimeError` is raised. .. code-block:: python from werkzeug.local import Local l = Local() # a proxy to whatever l.user is set to user = l("user") from werkzeug.local import LocalStack _request_stack = LocalStack() # a proxy to _request_stack.top request = _request_stack() # a proxy to the session attribute of the request proxy session = LocalProxy(lambda: request.session) ``__repr__`` and ``__class__`` are forwarded, 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) # isinstance(user, User) # True issubclass(type(user), LocalProxy) # True :param local: The :class:`Local` or callable that provides the proxied object. :param name: The attribute name to look up on a :class:`Local`. Not used if a callable is given. .. 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__localZ__name __wrapped__Nr3)r!rGrcCs@t|d|t|d|t|r(zLocalProxy.)r}r|cCsdt|jdS)Nrtz unbound>)rvrr:rrrr,r)r|cCsdS)NFrr:rrrr8rcCsgSr$rr:rrrr=rcCst|Sr$)rvr:rrrrHrcCs t||Sr$)rhrrrrrIrcCs t||Sr$) issubclassrrrrrJrcOs |||Sr$r)r&rrrrrrLr)N)rrrr.rOr0ryrQr2rxr/r'rrzreprrw__str__rq __bytes__ __format__operatorlt__lt__le__le__eq__eq__ne__ne__gt__gt__ge__ge__hash__hash__bool__bool__r]rLsetattrr9delattrrNdir__dir__r__instancecheck____subclasscheck__rFra__len__ length_hint__length_hint__getitem __getitem__setitem __setitem__delitem __delitem__rArCnext__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__riadd__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__rR__int__float __float__index __index__round __round__mathtrunc __trunc__floor __floor__ceil__ceil__ __enter____exit__ __await__ __aiter__ __anext__ __aenter__ __aexit__rM__copy__deepcopy __deepcopy__rrrrrDs-                                                    rD).rMrrsystypingr0r functoolsrrZwsgir TYPE_CHECKINGZ_typeshed.wsgirrr TypeVarrQr2r Zgreenletr r ImportErrorr r rR Exceptionrr"rmodulesr]Zgreenlet_patchedZ gevent.monkeyrryr6r3r4rerzrrrDrrrrsX           AQtN