Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/flask/__pycache__/ctx.cpython-37.pyc

234 lines
14 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>/<2F>]TA<00>@s<>dZddlZddlmZddlmZddlmZddlmZddl m
Z
dd l m Z dd
l m Z dd l mZe<0F>ZGd d <0A>d e<0F>Zdd<0F>Zdd<11>Zdd<13>Zdd<15>ZGdd<17>de<0F>ZGdd<19>de<0F>ZdS)z<>
flask.ctx
~~~~~~~~~
Implements the objects required to keep the context.
:copyright: 2010 Pallets
:license: BSD-3-Clause
<EFBFBD>N)<01>update_wrapper)<01> HTTPException<6F>)<01>BROKEN_PYPY_CTXMGR_EXIT)<01>reraise)<01>_app_ctx_stack)<01>_request_ctx_stack)<01>appcontext_popped)<01>appcontext_pushedc@sHeZdZdZddd<04>Zefdd<06>Zddd<08>Zd d
<EFBFBD>Zd d <0C>Z d d<0E>Z
dS)<11>_AppCtxGlobalsa<73>A 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
NcCs|j<00>||<02>S)z<>Get 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
)<02>__dict__<5F>get)<03>self<6C>name<6D>default<6C>r<00>,/tmp/pip-install-c3kgu56x/Flask/flask/ctx.pyr 0s z_AppCtxGlobals.getcCs&|tkr|j<01>|<01>S|j<01>||<02>SdS)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 raise a ``KeyError``.
.. versionadded:: 0.11
N)<03> _sentinelr <00>pop)rrrrrrr;s  z_AppCtxGlobals.popcCs|j<00>||<02>S)a6Get 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 <00>
setdefault)rrrrrrrIs
z_AppCtxGlobals.setdefaultcCs
||jkS)N)r )r<00>itemrrr<00> __contains__Usz_AppCtxGlobals.__contains__cCs
t|j<01>S)N)<02>iterr )rrrr<00>__iter__Xsz_AppCtxGlobals.__iter__cCs$tj}|dk rd|jjSt<04>|<00>S)Nz<flask.g of %r>)r<00>top<6F>appr<00>object<63>__repr__)rrrrrr[s z_AppCtxGlobals.__repr__)N)N) <0B>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r rrrrrrrrrrr s

r cCstjj<02>|<00>|S)a<>Executes 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
)rr<00>_after_request_functions<6E>append)<01>frrr<00>after_this_requestbsr%cs6tj}|dkrtd<02><01>|<01><03><00><01><00>fdd<04>}t|<02><00>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
Nz|This decorator can only be used at local scopes when a request context is on the stack. For instance within view functions.c s<00><01> <00>||<01>SQRXdS)Nr)<02>args<67>kwargs)r$<00>reqctxrr<00>wrapper<65>sz-copy_current_request_context.<locals>.wrapper)rr<00> RuntimeError<6F>copyr)r$rr)r)r$r(r<00>copy_current_request_context{sr,cCs
tjdk S)a<>If 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)rrrrrr<00>has_request_context<78>sr-cCs
tjdk S)z<>Works 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)rrrrrr<00>has_app_context<78>sr.c@s<eZdZdZdd<03>Zdd<05>Zefdd<07>Zdd <09>Zd
d <0B>Z d S) <0A>
AppContexta]The application context binds an application object implicitly
to the current thread or greenlet, similar to how the
:class:`RequestContext` binds request information. The application
context is also implicitly created if a request context is created
but the application is not on top of the individual application
context.
cCs&||_|<01>d<00>|_|<01><03>|_d|_dS)Nr)r<00>create_url_adapter<65> url_adapterZapp_ctx_globals_class<73>g<>_refcnt)rrrrr<00>__init__<5F>s 
zAppContext.__init__cCs:|jd7_ttd<02>r t<02><03>t<04>|<00>t<06>|j<08>dS)z-Binds the app context to the current context.r<00> exc_clearN) r3<00>hasattr<74>sysr5r<00>pushr
<00>sendr)rrrrr8<00>s


zAppContext.pushcCspz<|jd8_|jdkr:|tkr.t<02><03>d}|j<04>|<01>Wdt<06><07>}X||ks`td||f<00><01>t <09>
|j<04>dS)zPops the app context.rrNz-Popped wrong app context. (%r instead of %r)) r3rr7<00>exc_inforZdo_teardown_appcontextrr<00>AssertionErrorr r9)r<00>exc<78>rvrrrr<00>s
 
zAppContext.popcCs |<00><00>|S)N)r8)rrrr<00> __enter__<5F>szAppContext.__enter__cCs&|<00>|<02>tr"|dk r"t|||<03>dS)N)rrr)r<00>exc_type<70> exc_value<75>tbrrr<00>__exit__<5F>s
 zAppContext.__exit__N)
rrr r!r4r8rrr>rBrrrrr/<00>s   r/c@sxeZdZdZddd<04>Zedd<06><00>Zejdd<06><00>Zdd <09>Zd
d <0B>Z d d <0A>Z
e fdd<0F>Z dd<11>Z dd<13>Zdd<15>Zdd<17>ZdS)<19>RequestContexta<74>The request context contains all request relevant information. It is
created at the beginning of the request and pushed to the
`_request_ctx_stack` and removed at the end of it. It will create the
URL adapter and request object for the WSGI environment provided.
Do not attempt to use this class directly, instead use
:meth:`~flask.Flask.test_request_context` and
:meth:`~flask.Flask.request_context` to create this object.
When the request context is popped, it will evaluate all the
functions registered on the application for teardown execution
(:meth:`~flask.Flask.teardown_request`).
The request context is automatically popped at the end of the request
for you. In debug mode the request context is kept around if
exceptions happen so that interactive debuggers have a chance to
introspect the data. With 0.4 this can also be forced for requests
that did not fail and outside of ``DEBUG`` mode. By setting
``'flask._preserve_context'`` to ``True`` on the WSGI environment the
context will not pop itself at the end of the request. This is used by
the :meth:`~flask.Flask.test_client` for example to implement the
deferred cleanup functionality.
You might find this helpful for unittests where you need the
information from the context local around for a little longer. Make
sure to properly :meth:`~werkzeug.LocalStack.pop` the stack yourself in
that situation, otherwise your unittests will leak memory.
Nc
Cs<>||_|dkr|<01>|<02>}||_d|_y|<01>|j<02>|_Wn*tk
r`}z ||j_Wdd}~XYnXd|_||_g|_ d|_
d|_ g|_ dS)NF) rZ request_class<73>requestr1r0r<00>routing_exceptionZflashes<65>session<6F>_implicit_app_ctx_stack<63> preserved<65>_preserved_excr")rr<00>environrDrF<00>errrr4s
zRequestContext.__init__cCstjjS)N)rrr2)rrrrr2=szRequestContext.gcCs |tj_dS)N)rrr2)r<00>valuerrrr2AscCs|j|j|jj|j|jd<01>S)a5Creates a copy of this request context with the same request object.
This can be used to move a request context to a different greenlet.
Because the actual request object is the same this cannot be used to
move a request context to a different thread unless access to the
request object is locked.
.. versionadded:: 0.10
.. versionchanged:: 1.1
The current session object is used instead of reloading the original
data. This prevents `flask.session` pointing to an out-of-date object.
)rJrDrF)<05> __class__rrDrJrF)rrrrr+Es
zRequestContext.copyc
CsRy"|jjdd<02>}|\|j_|j_Wn*tk
rL}z ||j_Wdd}~XYnXdS)zZCan be overridden by a subclass to hook into the matching
of the request.
T)Z return_ruleN)r1<00>matchrDZurl_ruleZ view_argsrrE)r<00>resultrKrrr<00> match_requestYs
zRequestContext.match_requestcCs<>tj}|dk r |jr |<01>|j<04>tj}|dks:|j|jkrZ|j<06><07>}|<02><08>|j <09>
|<02>n |j <09>
d<01>t t d<02>rxt <0C> <0A>t<00>|<00>|jdkr<>|jj}|<03>|j|j<11>|_|jdkr<>|<03>|j<06>|_|jdk r<>|<00><14>dS)z1Binds the request context to the current context.Nr5)rrrHrrIrrZ app_contextr8rGr#r6r7r5rF<00>session_interfaceZ open_sessionrDZmake_null_sessionr1rP)rr<00>app_ctxrQrrrr8cs&
 
 




zRequestContext.pushc
Cs<>|j<00><01>}zld}|jstd|_d|_|tkr6t<05><06>d}|j<07>|<01>t td<04>rTt<05>
<EFBFBD>t |j dd<02>}|dk rp|<04>d}Wdt <0A><01>}|r<>d|j jd<|dk r<>|<02>|<01>||ks<>td||f<00><01>XdS) a Pops the request context and unbinds it by doing that. This will
also trigger the execution of functions registered by the
:meth:`~flask.Flask.teardown_request` decorator.
.. versionchanged:: 0.9
Added the `exc` argument.
FNrr5<00>closeTzwerkzeug.requestz0Popped wrong request context. (%r instead of %r))rGrrHrIrr7r:rZdo_teardown_requestr6r5<00>getattrrDrrJr;)rr<rRZ clear_requestZ request_closer=rrrr<00>s.
  
 
 zRequestContext.popcCs:|jj<01>d<01>s|dk r,|jjr,d|_||_n
|<00>|<01>dS)Nzflask._preserve_contextT)rDrJr rZpreserve_context_on_exceptionrHrIr)rr<rrr<00>auto_pop<6F>s
zRequestContext.auto_popcCs |<00><00>|S)N)r8)rrrrr><00>szRequestContext.__enter__cCs&|<00>|<02>tr"|dk r"t|||<03>dS)N)rUrr)rr?r@rArrrrB<00>s
 zRequestContext.__exit__cCs d|jj|jj|jj|jjfS)Nz<%s '%s' [%s] of %s>)rMrrD<00>url<72>methodrr)rrrrr<00>s
zRequestContext.__repr__)NN)rrr r!r4<00>propertyr2<00>setterr+rPr8rrrUr>rBrrrrrrC<00>s

+ /  rC)r!r7<00> functoolsrZwerkzeug.exceptionsr<00>_compatrr<00>globalsrrZsignalsr r
rrr r%r,r-r.r/rCrrrr<00><module>
s"        F( 
2