Sindbad~EG File Manager

Current Path : /home/infinitibizsol/mypythonenv/lib/python3.6/site-packages/flask/__pycache__/
Upload File :
Current File : /home/infinitibizsol/mypythonenv/lib/python3.6/site-packages/flask/__pycache__/ctx.cpython-36.pyc

3

Ĝg�D�@sddlZddlZddlmZddlmZddlmZddl	m
Z
ddl	mZddlm
Z
dd	lmZdd
lmZejr�ddlmZddlmZdd
lmZe�ZGdd�d�Zeed�dd�Zejejd�dd�Zed�dd�Zed�dd�ZGdd�d�Z Gdd�d�Z!dS)�N)�update_wrapper)�
TracebackType)�
HTTPException�)�_app_ctx_stack)�_request_ctx_stack)�appcontext_popped)�appcontext_pushed)�AfterRequestCallable)�Flask)�SessionMixin)�Requestc@s�eZdZdZeejd�dd�Zeejdd�dd�Zedd�d	d
�Z	deej
ejejd�dd
�Zefeejejd�dd�Z
deejejd�dd�Zeed�dd�Zejed�dd�Zed�dd�ZdS)�_AppCtxGlobalsa�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
    )�name�returncCs.y
|j|Stk
r(t|�d�YnXdS)N)�__dict__�KeyError�AttributeError)�selfr�r�*/tmp/pip-build-fsllo_ck/Flask/flask/ctx.py�__getattr__/s
z_AppCtxGlobals.__getattr__N)r�valuercCs||j|<dS)N)r)rrrrrr�__setattr__5sz_AppCtxGlobals.__setattr__cCs0y|j|=Wntk
r*t|�d�YnXdS)N)rrr)rrrrr�__delattr__8sz_AppCtxGlobals.__delattr__)r�defaultrcCs|jj||�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
        )r�get)rrrrrrr>s	z_AppCtxGlobals.getcCs&|tkr|jj|�S|jj||�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 raising a ``KeyError``.

        .. versionadded:: 0.11
        N)�	_sentinelr�pop)rrrrrrrIs	z_AppCtxGlobals.popcCs|jj||�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�
setdefault)rrrrrrrWs
z_AppCtxGlobals.setdefault)�itemrcCs
||jkS)N)r)rr rrr�__contains__csz_AppCtxGlobals.__contains__)rcCs
t|j�S)N)�iterr)rrrr�__iter__fsz_AppCtxGlobals.__iter__cCs(tj}|dk	rd|jj�d�Stj|�S)Nz<flask.g of �>)r�top�appr�object�__repr__)rr%rrrr(isz_AppCtxGlobals.__repr__)N)N)�__name__�
__module__�__qualname__�__doc__�str�tZAnyrrr�Optionalrrrr�boolr!�Iteratorr#r(rrrrrsr)�frcCs&tj}|dkrtd��|jj|�|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
    NzaThis decorator can only be used when a request context is active, such as within a view function.)rr%�RuntimeError�_after_request_functions�append)r2r%rrr�after_this_requestpsr6cs6tj}|dkrtd��|j����fdd�}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
    NzaThis decorator can only be used when a request context is active, such as within a view function.c
s���||�SQRXdS)Nr)�args�kwargs)r2�reqctxrr�wrapper�sz-copy_current_request_context.<locals>.wrapper)rr%r3�copyr)r2r%r:r)r2r9r�copy_current_request_context�sr<)rcCs
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)rr%rrrr�has_request_context�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)rr%rrrr�has_app_context�sr>c@sjeZdZdZddd�dd�Zdd�dd	�Zefeje	dd
�dd�Z
dd�d
d�Zee	e
dd�dd�ZdS)�
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.
    rN)r&rcCs&||_|jd�|_|j�|_d|_dS)Nr)r&�create_url_adapter�url_adapterZapp_ctx_globals_class�g�_refcnt)rr&rrr�__init__�s
zAppContext.__init__)rcCs(|jd7_tj|�tj|j�dS)z-Binds the app context to the current context.rN)rCr�pushr	�sendr&)rrrrrE�s
zAppContext.push)�excrcCsvz<|jd8_|jdkr:|tkr.tj�d}|jj|�Wdtj�}X||ksftd|�d|�d���t	j
|j�dS)zPops the app context.rrNzPopped wrong app context.  (z instead of �))rCr�sys�exc_infor&Zdo_teardown_appcontextrr�AssertionErrorrrF)rrG�rvrrrr�s

zAppContext.popcCs|j�|S)N)rE)rrrr�	__enter__	szAppContext.__enter__)�exc_type�	exc_value�tbrcCs|j|�dS)N)r)rrNrOrPrrr�__exit__
szAppContext.__exit__)r)r*r+r,rDrErr.r/�
BaseExceptionrrM�typerrQrrrrr?�s	
r?c@s�eZdZdZd deejdejddd�dd�Zee	d	�d
d��Z
e
je	dd�d
d��Z
dd	�dd�Zdd	�dd�Z
dd	�dd�Zefejedd�dd�Zejedd�dd�Zdd	�dd�Zeeedd�dd�Zed	�dd�ZdS)!�RequestContexta�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.
    Nrr
r)r&�environ�request�sessionrcCs�||_|dkr|j|�}||_d|_y|j|j�|_Wn*tk
r`}z||j_WYdd}~XnXd|_||_g|_	d|_
d|_g|_dS)NF)
r&Z
request_classrVrAr@r�routing_exceptionZflashesrW�_implicit_app_ctx_stack�	preserved�_preserved_excr4)rr&rUrVrW�errrrD1s
zRequestContext.__init__)rcCstjjS)N)rr%rB)rrrrrBWszRequestContext.g)rrcCs|tj_dS)N)rr%rB)rrrrrrB[scCs|j|j|jj|j|jd�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.
        )rUrVrW)�	__class__r&rVrUrW)rrrrr;_s

zRequestContext.copycCsRy"|jjdd�}|\|j_|j_Wn*tk
rL}z||j_WYdd}~XnXdS)zZCan be overridden by a subclass to hook into the matching
        of the request.
        T)Zreturn_ruleN)rA�matchrVZurl_ruleZ	view_argsrrX)r�resultr\rrr�
match_requestss
zRequestContext.match_requestcCs�tj}|dk	r |jr |j|j�tj}|dks:|j|jkrZ|jj�}|j�|j	j
|�n|j	j
d�tj|�|jdkr�|jj}|j
|j|j�|_|jdkr�|j|j�|_|jdk	r�|j�dS)z1Binds the request context to the current context.N)rr%rZrr[rr&Zapp_contextrErYr5rW�session_interfaceZopen_sessionrVZmake_null_sessionrAr`)rr%�app_ctxrarrrrE}s"





zRequestContext.push)rGrcCs�|jj�}d}zV|jsbd|_d|_|tkr6tj�d}|jj|�t	|j
dd�}|dk	r^|�d}Wdtj�}|r~d|j
jd<|dk	r�|j|�||ks�t
d|�d|�d	���XdS)
aPops 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.
        FNr�closeTzwerkzeug.requestzPopped wrong request context. (z instead of rH)rYrrZr[rrIrJr&Zdo_teardown_request�getattrrVrrUrK)rrGrbZ
clear_requestZ
request_closerLrrrr�s(


zRequestContext.popcCs:|jjjd�s|dk	r,|jjr,d|_||_n
|j|�dS)Nzflask._preserve_contextT)rVrUrr&Zpreserve_context_on_exceptionrZr[r)rrGrrr�auto_pop�s
zRequestContext.auto_popcCs|j�|S)N)rE)rrrrrM�szRequestContext.__enter__)rNrOrPrcCs|j|�dS)N)re)rrNrOrPrrrrQ�szRequestContext.__exit__c	Cs0dt|�j�d|jj�d|jj�d|jj�d�	S)N�<� z [z] of r$)rSr)rV�url�methodr&r)rrrrr(�szRequestContext.__repr__)NN)r)r*r+r,�dictr.r/rD�propertyr?rB�setterr;r`rErrRrrerMrSrrQr-r(rrrrrTs" 
*'	rT)"rI�typingr.�	functoolsr�typesrZwerkzeug.exceptionsr�globalsrrZsignalsrr	r
Z
TYPE_CHECKINGr&r�sessionsrZwrappersr
r'rrr6�Callabler<r0r=r>r?rTrrrr�<module>s*X!) 
/

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists