6V=j<ddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl mZ ddlmZdd lmZdd lmZdd lmZejrdd lmZdd lmZddlmZddlmZeZGddZd!dZ ej!dej"dej#fZ$d"dZ%d#dZ&d#dZ'GddZ(Gdd Z)dS)$) annotationsN)update_wrapper) TracebackType) HTTPException)typing)_cv_app) _cv_request)appcontext_popped)appcontext_pushed)WSGIEnvironment)Flask) SessionMixin)RequestcbeZdZdZddZdd Zdd ZdddZefddZ dddZ ddZ ddZ ddZ d S) _AppCtxGlobalsaA plain object. Used as a namespace for storing data during an application context. Creating an app context automatically creates this object, which is made available as the :data:`g` proxy. .. describe:: 'key' in g Check whether an attribute is present. .. versionadded:: 0.10 .. describe:: iter(g) Return an iterator over the attribute names. .. versionadded:: 0.10 namestrreturnt.AnycZ |j|S#t$rt|dwxYwN__dict__KeyErrorAttributeErrorselfrs 7C:\PYTHON\_runtimes\venv\Lib\site-packages\flask/ctx.py __getattr__z_AppCtxGlobals.__getattr__4s? 1=& & 1 1 1 &&D 0 1s *valueNonec||j|<dSrr)rrr!s r __setattr__z_AppCtxGlobals.__setattr__:s# dcT |j|=dS#t$rt|dwxYwrrrs r __delattr__z_AppCtxGlobals.__delattr__=sB 1 d### 1 1 1 &&D 0 1s 'Ndefault t.Any | Nonec8|j||S)zGet an attribute by name, or a default value. Like :meth:`dict.get`. :param name: Name of attribute to get. :param default: Value to return if the attribute is not present. .. versionadded:: 0.10 )rgetrrr)s rr,z_AppCtxGlobals.getCs}  w///r&c~|tur|j|S|j||S)a Get and remove an attribute by name. Like :meth:`dict.pop`. :param name: Name of attribute to pop. :param default: Value to return if the attribute is not present, instead of raising a ``KeyError``. .. versionadded:: 0.11 ) _sentinelrpopr-s rr0z_AppCtxGlobals.popNs= i  =$$T** *=$$T733 3r&c8|j||S)a5Get the value of an attribute if it is present, otherwise set and return a default value. Like :meth:`dict.setdefault`. :param name: Name of attribute to get. :param default: Value to set and return if the attribute is not present. .. versionadded:: 0.11 )r setdefaultr-s rr2z_AppCtxGlobals.setdefault\s}''g666r&itemboolc||jvSrr$)rr3s r __contains__z_AppCtxGlobals.__contains__hst}$$r&t.Iterator[str]c*t|jSr)iterrrs r__iter__z_AppCtxGlobals.__iter__ksDM"""r&ctjd}|d|jjdSt|S)Nz )r r,approbject__repr__)rctxs rr?z_AppCtxGlobals.__repr__ns=k$ ?337<333 3t$$$r&)rrrr)rrr!rrr")rrrr"r)rrr)r*rr)rrr)rrr)r3rrr4)rr7rr)__name__ __module__ __qualname____doc__r r%r(r,r/r0r2r6r;r?r&rrrs,1111 $$$$1111 0 0 0 0 0/8 4 4 4 4 4 7 7 7 7 7%%%%####%%%%%%r&rfft.AfterRequestCallable[t.Any]rctjd}|td|j||S)aExecutes a function after this request. This is useful to modify response objects. The function is passed the response object and has to return the same or a new one. Example:: @app.route('/') def index(): @after_this_request def add_header(response): response.headers['X-Foo'] = 'Parachute' return response return 'Hello World!' This is more useful if a function other than the view function wants to modify a response. For instance think of a decorator that wants to add some headers without converting the return value into a response object. .. versionadded:: 0.9 Nzc'after_this_request' can only be used when a request context is active, such as in a view function.)r r, RuntimeError_after_request_functionsappend)rGr@s rafter_this_requestrMusM. /$  C { >    ''*** Hr&F.)boundctjdtddfd }t |S) a:A helper function that decorates a function to retain the current request context. This is useful when working with greenlets. The moment the function is decorated a copy of the request context is created and then pushed when the function is called. The current session is also included in the copied request context. Example:: import gevent from flask import copy_current_request_context @app.route('/') def index(): @copy_current_request_context def do_some_work(): # do some work here, it can access flask.request or # flask.session like you would otherwise in the view function. ... gevent.spawn(do_some_work) return 'Regular response' .. versionadded:: 0.10 Nzm'copy_current_request_context' can only be used when a request context is active, such as in a view function.argsrkwargsrc|5j|i|cdddS#1swxYwYdSr)r= ensure_sync)rQrRr@rGs rwrapperz-copy_current_request_context..wrappers  ; ;)37&&q))4:6:: ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s 155)rQrrRrrr)r r,rJcopyr)rGrUr@s` @rcopy_current_request_contextrWsv0 /$  C { F   ((**C;;;;;;; '1 % %%r&r4c.tjdduS)aIf you have code that wants to test if a request context is there or not this function can be used. For instance, you may want to take advantage of request information if the request object is available, but fail silently if it is unavailable. :: class User(db.Model): def __init__(self, username, remote_addr=None): self.username = username if remote_addr is None and has_request_context(): remote_addr = request.remote_addr self.remote_addr = remote_addr Alternatively you can also just test any of the context bound objects (such as :class:`request` or :class:`g`) for truthness:: class User(db.Model): def __init__(self, username, remote_addr=None): self.username = username if remote_addr is None and request: remote_addr = request.remote_addr self.remote_addr = remote_addr .. versionadded:: 0.7 N)r r,rFr&rhas_request_contextrYs: ?4  ,,r&c.tjdduS)zWorks like :func:`has_request_context` but for the application context. You can also just do a boolean check on the :data:`current_app` object instead. .. versionadded:: 0.9 N)r r,rFr&rhas_app_contextr[s ;t  D ((r&c>eZdZdZddZddZefdd Zdd ZddZ dS) AppContextzThe app context contains application-specific information. An app context is created and pushed at the beginning of each request if one is not already active. An app context is also pushed when running CLI commands. r=rrr"c||_|d|_||_g|_dSr)r=create_url_adapter url_adapterapp_ctx_globals_classg _cv_tokens)rr=s r__init__zAppContext.__init__s=11$77!$!:!:! #$67" C   $$RcRRRRR/##C!_0022NE7  e $ $ $ ?:> #$67" C   $$RcRRRRRs A DBFc.||Srrwr:s rrxzRequestContext.__enter__ryr&rzr{r|r}r~c0||dSrrrs rrzRequestContext.__exit__rr&rc dt|jd|jjd|jjd|jjd S)N< z [z] of >)typerBrurlmethodr=rr:s rr?zRequestContext.__repr__sZ <T # < r/rrMTypeVarCallableAnyrNrWrYr[r]rrFr&rrs5"""""" $$$$$$------ &&&&&&&&&&&&?"......&&&&&&!!!!!! FHH U%U%U%U%U%U%U%U%p     FAIcCJ/000&&&&&&&&R----@))))........bl l l l l l l l l l r&