
    0h;                       S SK Jr  S SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  \R(                  (       a  S SKJr  SSKJr  SSKJr  SSKJr  \" 5       r " S S5      r    SS jr \RB                  " S\RD                  S\RF                  4   S9r$SS jr%SS jr&SS jr' " S S5      r( " S S5      r)g)     )annotationsN)update_wrapper)TracebackType)HTTPException   )typing)_cv_app)_cv_request)appcontext_popped)appcontext_pushed)WSGIEnvironment)Flask)SessionMixin)Requestc                      \ rS rSrSrSS jrSS jrSS jrSSS jjr\	4SS jjr
SSS	 jjrSS
 jrSS jrSS jrSrg)_AppCtxGlobals   a  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                V     U R                   U   $ ! [         a    [        U5      S ef = fN__dict__KeyErrorAttributeErrorselfnames     A/var/www/auris/envauris/lib/python3.13/site-packages/flask/ctx.py__getattr___AppCtxGlobals.__getattr__4   s2    	1==&& 	1 &D0	1s    (c                     X R                   U'   g r   r   )r   r   values      r   __setattr___AppCtxGlobals.__setattr__:   s    #d    c                T     U R                   U	 g ! [         a    [        U5      S ef = fr   r   r   s     r   __delattr___AppCtxGlobals.__delattr__=   s/    	1d# 	1 &D0	1s    'Nc                8    U R                   R                  X5      $ )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
)r   getr   r   defaults      r   r*   _AppCtxGlobals.getC   s     }}  //r%   c                    U[         L a  U R                  R                  U5      $ U R                  R                  X5      $ )zGet 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
)	_sentinelr   popr+   s      r   r0   _AppCtxGlobals.popN   s6     i==$$T**==$$T33r%   c                8    U R                   R                  X5      $ )a  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   
setdefaultr+   s      r   r3   _AppCtxGlobals.setdefault\   s     }}''66r%   c                    XR                   ;   $ r   r!   )r   items     r   __contains___AppCtxGlobals.__contains__h   s    }}$$r%   c                ,    [        U R                  5      $ r   )iterr   r   s    r   __iter___AppCtxGlobals.__iter__k   s    DMM""r%   c                    [         R                  " S 5      nUb  SUR                  R                   S3$ [        R                  U 5      $ )Nz<flask.g of 'z'>)r	   r*   appr   object__repr__)r   ctxs     r   rA   _AppCtxGlobals.__repr__n   s;    kk$?"377<<.33t$$r%    )r   strreturnt.Any)r   rE   r"   rG   rF   None)r   rE   rF   rH   r   )r   rE   r,   zt.Any | NonerF   rG   )r   rE   r,   rG   rF   rG   )r6   rE   rF   bool)rF   zt.Iterator[str]rF   rE   )__name__
__module____qualname____firstlineno____doc__r   r#   r'   r*   r/   r0   r3   r7   r<   rA   __static_attributes__rD   r%   r   r   r      s9    ,1$1	0 /8 4
7%#%r%   r   c                    [         R                  " S5      nUc  [        S5      eUR                  R	                  U 5        U $ )aw  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
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_functionsappend)frB   s     r   after_this_requestrV   u   sD    . //$
C
{>
 	

   ''*Hr%   F.)boundc                   ^ ^ [         R                  " S5      mTc  [        S5      eTR                  5       mSUU 4S jjn[	        UT 5      $ )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.c                    > T   TR                   R                  T5      " U 0 UD6sS S S 5        $ ! , (       d  f       g = fr   )r?   ensure_sync)argskwargsrB   rU   s     r   wrapper-copy_current_request_context.<locals>.wrapper   s,    77&&q)4:6: SSs   !/
=)r\   rG   r]   rG   rF   rG   )r
   r*   rR   copyr   )rU   r^   rB   s   ` @r   copy_current_request_contextra      sQ    0 //$
C
{F
 	

 ((*C; ; '1%%r%   c                 2    [         R                  " S5      SL$ )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)r
   r*   rD   r%   r   has_request_contextrc      s    : ??4 ,,r%   c                 2    [         R                  " S5      SL$ )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*   rD   r%   r   has_app_contextre      s     ;;tD((r%   c                  `    \ rS rSrSrS
S jrSS jr\4SS jjrSS jr	        SS jr
Srg	)
AppContext   zThe 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.
c                t    Xl         UR                  S 5      U l        UR                  5       U l        / U l        g r   )r?   create_url_adapterurl_adapterapp_ctx_globals_classg
_cv_tokens)r   r?   s     r   __init__AppContext.__init__   s1    11$7!$!:!:!<?Ar%   c                    U R                   R                  [        R                  " U 5      5        [        R
                  " U R                  U R                  R                  S9  g)z-Binds the app context to the current context._async_wrapperN)rn   rT   r	   setr   sendr?   r[   r;   s    r   pushAppContext.push   s;    w{{401txx8L8LMr%   c                \    [        U R                  5      S:X  a<  U[        L a  [        R                  " 5       S   nU R
                  R                  U5        [        R                  " 5       n[        R                  " U R                  R                  5       5        X La  [        SU< SU < S35      e[        R                  " U R
                  U R
                  R                  S9  g! [        R                  " 5       n[        R                  " U R                  R                  5       5        f = f)zPops the app context.r   zPopped wrong app context. ( instead of )rr   N)lenrn   r/   sysexc_infor?   do_teardown_appcontextr	   r*   resetr0   AssertionErrorr   ru   r[   )r   excrB   s      r   r0   AppContext.pop   s    	14??#q()#,,.+C//4++-CMM$//--/0? -cWLJ  	txx8L8LM ++-CMM$//--/0s   AC& &AD+c                &    U R                  5         U $ r   rv   r;   s    r   	__enter__AppContext.__enter__      		r%   c                &    U R                  U5        g r   r0   r   exc_type	exc_valuetbs       r   __exit__AppContext.__exit__       	r%   )rn   r?   rm   rk   N)r?   r   rF   rH   rF   rH   r   BaseException | NonerF   rH   )rF   rg   r   ztype | Noner   r   r   zTracebackType | NonerF   rH   )rK   rL   rM   rN   rO   ro   rv   r/   r0   r   r   rP   rD   r%   r   rg   rg      sN    BN
 /8 N$ ( !	
 
r%   rg   c                      \ rS rSrSr  S         SS jjrSS jrSS jrSS jr\	4SS jjr
SS	 jr        SS
 jrSS jrSrg)RequestContexti  a  The request context contains per-request information. The Flask
app creates and pushes it at the beginning of the request, then pops
it at the end of the request. 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. When using the interactive debugger, the context will be
restored so ``request`` is still accessible. Similarly, the test
client can preserve the context after the request ends. However,
teardown functions may already have closed some resources such as
database connections.
Nc                :   Xl         Uc"  UR                  U5      nUR                  Ul        X0l        S U l         UR                  U R                  5      U l        S U l	        X@l
        / U l        / U l        g ! [         a  nXPR                  l         S nAN;S nAff = fr   )r?   request_classjsonjson_modulerequestrk   rj   r   routing_exceptionflashessessionrS   rn   )r   r?   environr   r   es         r   ro   RequestContext.__init__5  s     ?''0G"%((G '	/"55dllCD 6:,3 OQ%  	  	/-.LL**	/s    A6 6
B BBc                    U R                  U R                  U R                  R                  U R                  U R                  S9$ )a  Creates 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.
)r   r   r   )	__class__r?   r   r   r   r;   s    r   r`   RequestContext.copyQ  s<     ~~HHLL((LLLL	  
 	
r%   c                     U R                   R                  SS9nUu  U R                  l        U R                  l        g! [
         a  nX R                  l         SnAgSnAff = f)zJCan be overridden by a subclass to hook into the matching
of the request.
T)return_ruleN)rk   matchr   url_rule	view_argsr   r   )r   resultr   s      r   match_requestRequestContext.match_requeste  sU    	/%%+++=F<B9DLL!4<<#9 	/-.LL**	/s   <? 
A#	AA#c                V   [         R                  " S 5      nUb  UR                  U R                  La+  U R                  R                  5       nUR	                  5         OS nU R
                  R                  [        R                  " U 5      U45        U R                  cn  U R                  R                  nUR                  U R                  U R                  5      U l	        U R                  c   UR                  U R                  5      U l	        U R                  b  U R                  5         g g r   )r	   r*   r?   app_contextrv   rn   rT   r
   rt   r   session_interfaceopen_sessionr   make_null_sessionrk   r   )r   app_ctxr   s      r   rv   RequestContext.pusho  s     ++d#?gkk9hh**,GLLNG 5w?@ << $ : :,99$((DLLQDL||#0BB488L '  (r%   c           	     T   [        U R                  5      S:H  n U(       a]  U[        L a  [        R                  " 5       S   nU R
                  R                  U5        [        U R                  SS5      nUb  U" 5         [        R                  " 5       nU R                  R                  5       u  pV[        R                  " U5        U(       a  SUR                  R                  S'   Ub  UR                  U5        X@La  [        SU< SU < S35      eg! [        R                  " 5       nU R                  R                  5       u  pV[        R                  " U5        U(       a  SUR                  R                  S'   Ub  UR                  U5        X@La  [        SU< SU < S35      ef = f)zPops 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.
r   closeNzwerkzeug.requestzPopped wrong request context. (ry   rz   )r{   rn   r/   r|   r}   r?   do_teardown_requestgetattrr   r
   r*   r0   r   r   r   )r   r   clear_requestrequest_closerB   tokenr   s          r   r0   RequestContext.pop  sr    DOO,1	)#,,.+C,,S1 'gt D ,!O//#C!__002NEe$ :>##$67"C $5cWLPQR   //#C!__002NEe$ :>##$67"C $5cWLPQR  s   A$D BF'c                &    U R                  5         U $ r   r   r;   s    r   r   RequestContext.__enter__  r   r%   c                &    U R                  U5        g r   r   r   s       r   r   RequestContext.__exit__  r   r%   c           	         S[        U 5      R                   SU R                  R                  < SU R                  R                   SU R
                  R                   S3	$ )N< z [z] of >)typerK   r   urlmethodr?   r   r;   s    r   rA   RequestContext.__repr__  sQ    T
##$Adll&6&6%9$$%U488==/<	
r%   )rS   rn   r?   r   r   r   rk   )NN)
r?   r   r   r   r   zRequest | Noner   zSessionMixin | NonerF   rH   )rF   r   r   r   r   rJ   )rK   rL   rM   rN   rO   ro   r`   r   rv   r/   r0   r   r   rA   rP   rD   r%   r   r   r     s    2 #''+ !  	
 % 
8
(/!: /8 #J ( !	
 

r%   r   )rU   ft.AfterRequestCallable[t.Any]rF   r   )rU   rW   rF   rW   )rF   rI   )*
__future__r   contextvarsr|   r   t	functoolsr   typesr   werkzeug.exceptionsr    ftglobalsr	   r
   signalsr   r   TYPE_CHECKING_typeshed.wsgir   r?   r   sessionsr   wrappersr   r@   r/   r   rV   TypeVarCallableAnyrW   ra   rc   re   rg   r   rD   r%   r   <module>r      s    "  
  $  -     & &??.&! H	U% U%p % # F IIcCJ/0&&R-@). .bb
 b
r%   