|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /lib64/python2.7/site-packages/flask/ |
Upload File : |
�
-/�_c @ s d 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
d d l m Z d d
l m
Z
d d l m Z e � Z d e f d
� � YZ d � Z d � Z d � Z d � Z d e f d � � YZ d e f d � � YZ d S( s�
flask.ctx
~~~~~~~~~
Implements the objects required to keep the context.
:copyright: 2010 Pallets
:license: BSD-3-Clause
i����N( t update_wrapper( t
HTTPExceptioni ( t BROKEN_PYPY_CTXMGR_EXIT( t reraise( t _app_ctx_stack( t _request_ctx_stack( t appcontext_popped( t appcontext_pushedt _AppCtxGlobalsc B sM e Z d Z d d � Z e d � Z d d � Z d � Z d � Z d � Z
RS( s� 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
c C s | j j | | � S( s� 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
( t __dict__t get( t selft namet default( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyR
0 s c C s3 | t k r | j j | � S| j j | | � Sd S( s
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( t _sentinelR t pop( R R R
( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyR ; s c C s | j j | | � S( s6 Get 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 t
setdefault( R R R
( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyR I s
c C s
| | j k S( N( R ( R t item( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyt __contains__U s c C s
t | j � S( N( t iterR ( R ( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyt __iter__X s c C s0 t j } | d k r# d | j j St j | � S( Ns <flask.g of %r>( R t topt Nonet appR t objectt __repr__( R R ( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyR [ s N( t __name__t
__module__t __doc__R R
R R R R R R ( ( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyR s c C s t j j j | � | S( s� 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
( R R t _after_request_functionst append( t f( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyt after_this_requestb s c sO t j } | d k r$ t d � � n | j � � � � f d � } t | � � S( s: 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
s| This decorator can only be used at local scopes when a request context is on the stack. For instance within view functions.c s � � � | | � SWd QXd S( N( ( t argst kwargs( R t reqctx( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyt wrapper� s N( R R R t RuntimeErrort copyR ( R R R$ ( ( R R# s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyt copy_current_request_context{ s c C s
t j d k S( s� 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( R R R ( ( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyt has_request_context� s c C s
t j d k S( s� 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( R R R ( ( ( s* /tmp/pip-install-sTXtzD/flask/flask/ctx.pyt has_app_context� s t
AppContextc B s>