zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
U
ß=®dù9ã@sddlmZddlZddlZddlZddlmZddlm    Z    ddl
m Z ddl mZ ddlmZdd    lmZdd
lmZdd lmZejr®dd lmZdd lmZddlmZeƒZGdd„dƒZdddœdd„Zdddœdd„Zddœdd„Z ddœdd„Z!Gdd„dƒZ"Gd d!„d!ƒZ#dS)"é)Ú annotationsN)Úupdate_wrapper)Ú TracebackType)Ú HTTPExceptioné)Útyping)Ú_cv_app)Ú _cv_request)Úappcontext_popped)Úappcontext_pushed)ÚFlask)Ú SessionMixin)ÚRequestc@s¬eZdZdZdddœdd„Zddddœd    d
„Zdddœd d „Zd ddddœdd„Zefddddœdd„Z    d!ddddœdd„Z
dddœdd„Z ddœdd„Z ddœdd„Z d S)"Ú_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
    Ústrzt.Any)ÚnameÚreturncCs0z |j|WStk
r*t|ƒd‚YnXdS©N©Ú__dict__ÚKeyErrorÚAttributeError©Úselfr©rú@d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\flask/ctx.pyÚ __getattr__2s z_AppCtxGlobals.__getattr__ÚNone)rÚvaluercCs||j|<dSr©r)rrrrrrÚ __setattr__8sz_AppCtxGlobals.__setattr__cCs0z |j|=Wntk
r*t|ƒd‚YnXdSrrrrrrÚ __delattr__;s z_AppCtxGlobals.__delattr__Nz t.Any | None)rÚdefaultrcCs|j ||¡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©rrr"rrrr#As    z_AppCtxGlobals.getcCs&|tkr|j |¡S|j ||¡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Úpopr$rrrr&Ls     z_AppCtxGlobals.popcCs|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$rrrr'Zs
z_AppCtxGlobals.setdefaultÚbool)ÚitemrcCs
||jkSrr)rr)rrrÚ __contains__fsz_AppCtxGlobals.__contains__zt.Iterator[str]©rcCs
t|jƒSr)Úiterr©rrrrÚ__iter__isz_AppCtxGlobals.__iter__cCs,t d¡}|dk    r"d|jj›dSt |¡S)Nz <flask.g of 'z'>)rr#ÚapprÚobjectÚ__repr__)rÚctxrrrr1ls
z_AppCtxGlobals.__repr__)N)N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rr r!r#r%r&r'r*r.r1rrrrrs  rzft.AfterRequestCallable)ÚfrcCs*t d¡}|dkrtdƒ‚|j |¡|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
    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)r7r2rrrÚafter_this_requestss
ÿ r;z
t.Callablecs:t d¡‰ˆdkrtdƒ‚ˆ ¡‰‡‡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
    Nzm'copy_current_request_context' can only be used when a request context is active, such as in a view function.c
s.ˆ ˆj ˆ¡||ŽW5QR£SQRXdSr)r/Ú ensure_sync)ÚargsÚkwargs©r2r7rrÚwrapper¶sz-copy_current_request_context.<locals>.wrapper)r    r#r8Úcopyr)r7r@rr?rÚcopy_current_request_context”s
ÿrBr(r+cCst d¡dk    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)r    r#rrrrÚhas_request_context½srCcCst d¡dk    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ÝsrDc@sdeZdZdZdddœdd„Zddœdd    „Zefd
dd œd d „Zddœdd„Zdd
dddœdd„Z    dS)Ú
AppContextzèThe 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 r)r/rcCs&||_| d¡|_| ¡|_g|_dSr)r/Úcreate_url_adapterÚ url_adapterZapp_ctx_globals_classÚgÚ
_cv_tokens)rr/rrrÚ__init__îs 
zAppContext.__init__r+cCs*|j t |¡¡tj|j|jjddS)z-Binds the app context to the current context.©Z_async_wrapperN)rIr:rÚsetr Úsendr/r<r-rrrÚpushôszAppContext.pushúBaseException | None©Úexcrc
Cs„z2t|jƒdkr0|tkr$t ¡d}|j     
|¡W5t ¡}t |j ¡¡X||k    rlt d|›d|›dƒ‚t j |j    |j    jddS)zPops the app context.rzPopped wrong app context. (ú  instead of ú)rKN)rr#ÚresetrIr&Úlenr%ÚsysÚexc_infor/Zdo_teardown_appcontextÚAssertionErrorr
rMr<)rrQr2rrrr&ùs ÿzAppContext.popcCs | ¡|Sr©rNr-rrrÚ    __enter__ szAppContext.__enter__ú type | NoneúTracebackType | None©Úexc_typeÚ    exc_valueÚtbrcCs| |¡dSr©r&©rr^r_r`rrrÚ__exit__szAppContext.__exit__N)
r3r4r5r6rJrNr%r&rZrcrrrrrEçs rEc@s–eZdZdZd ddddddœd    d
„Zdd œd d „Zdd œdd„Zdd œdd„Zefdddœdd„Z    dd œdd„Z
dddddœdd„Z dd œdd„Z dS)!ÚRequestContextaÛ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.
    Nr ÚdictzRequest | NonezSessionMixin | Noner)r/ÚenvironÚrequestÚsessionrc
Cs†||_|dkr | |¡}|j|_||_d|_z| |j¡|_Wn*tk
rh}z ||j_W5d}~XYnXd|_    ||_
g|_ g|_ dSr) r/Z request_classÚjsonZ json_modulergrGrFrÚrouting_exceptionZflashesrhr9rI)rr/rfrgrhÚerrrrJ.s
zRequestContext.__init__r+cCs|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.
        )rfrgrh)Ú    __class__r/rgrfrhr-rrrrAHs üzRequestContext.copyc
CsRz"|jjdd}|\|j_|j_Wn*tk
rL}z ||j_W5d}~XYnXdS)zZCan be overridden by a subclass to hook into the matching
        of the request.
        T)Z return_ruleN)rGÚmatchrgZurl_ruleZ    view_argsrrj)rÚresultrkrrrÚ match_request\s
zRequestContext.match_requestcCsžt d¡}|dks|j|jk    r2|j ¡}| ¡nd}|j t |¡|f¡|j    dkrˆ|jj
}|  |j|j ¡|_    |j    dkrˆ|  |j¡|_    |jdk    rš| ¡dSr)rr#r/Z app_contextrNrIr:r    rLrhÚsession_interfaceZ open_sessionrgZmake_null_sessionrGro)rÚapp_ctxrprrrrNfs
 
 
 
 
 
zRequestContext.pushrOrPc Csºt|jƒdk}zD|rP|t    kr(t
  ¡d}|j   |¡t|jddƒ}|dk    rP|ƒW5t ¡}|j ¡\}}t |¡|r„d|jjd<|dk    r–| |¡||k    r´td|›d|›dƒ‚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.
        rNzwerkzeug.requestzPopped wrong request context. (rRrSÚclose)rUrIr    r#r&rTrgrfrXr%rVrWr/Zdo_teardown_requestÚgetattr)rrQZ clear_requestr2ÚtokenrqZ request_closerrrr&ƒs(  
 
 
ÿzRequestContext.popcCs | ¡|SrrYr-rrrrZ¨szRequestContext.__enter__r[r\r]cCs| |¡dSrrarbrrrrc¬szRequestContext.__exit__rc    Cs0dt|ƒj›d|jj›d|jj›d|jj›d    S)Nú<ú z [z] of ú>)Útyper3rgÚurlÚmethodr/rr-rrrr1´s.ÿzRequestContext.__repr__)NN) r3r4r5r6rJrArorNr%r&rZrcr1rrrrrdsû
%rd)$Ú
__future__rZ contextvarsrVrÚtÚ    functoolsrÚtypesrZwerkzeug.exceptionsrÚÚftÚglobalsrr    Zsignalsr
r Ú TYPE_CHECKINGr/r Úsessionsr Úwrappersrr0r%rr;rBrCrDrErdrrrrÚ<module>s.            X!) 
1