zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
U
ß=®dY7ã@sìddlmZddlZddlZddlmZddlmZddlmZddl    m
Z
ddl    m Z ddl m Z d    d
lmZejr’d    d lmZd    d lmZmZGd d„deƒZGdd„de eƒZGdd„deƒZGdd„dƒZeƒZGdd„deƒZdS)é)Ú annotationsN)ÚMutableMapping)Údatetime)Útimezone)Ú BadSignature)ÚURLSafeTimedSerializer)Ú CallbackDicté)ÚTaggedJSONSerializer)ÚFlask)ÚRequestÚResponsec@sDeZdZdZeddœdd„ƒZejdddœdd„ƒZd    Zd
Zd
Z    d S) Ú SessionMixinz3Expands a basic dictionary with session attributes.Úbool©ÚreturncCs | dd¡S)z3This reflects the ``'_permanent'`` key in the dict.Ú
_permanentF)Úget©Úself©rúEd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\flask/sessions.pyÚ    permanentszSessionMixin.permanentÚNone)ÚvaluercCst|ƒ|d<dS)Nr)r)rrrrrrsFTN)
Ú__name__Ú
__module__Ú __qualname__Ú__doc__ÚpropertyrÚsetterÚnewÚmodifiedÚaccessedrrrrrsrcsveZdZdZdZdZddddœ‡fdd„ Zd    dd
œ‡fd d „ Zdd    ddd œ‡fdd„ Zdd    ddd œ‡fdd„ Z    ‡Z
S)ÚSecureCookieSessiona    Base class for sessions based on signed cookies.
 
    This session backend will set the :attr:`modified` and
    :attr:`accessed` attributes. It cannot reliably track whether a
    session is new (vs. empty), so :attr:`new` remains hard coded to
    ``False``.
    FNút.Anyr)Úinitialrcs ddœdd„}tƒ ||¡dS)NrrcSsd|_d|_dS©NT)r"r#rrrrÚ    on_updateGsz/SecureCookieSession.__init__.<locals>.on_update)ÚsuperÚ__init__)rr&r(©Ú    __class__rrr*FszSecureCookieSession.__init__Ústr)Úkeyrcsd|_tƒ |¡Sr')r#r)Ú __getitem__)rr.r+rrr/MszSecureCookieSession.__getitem__)r.Údefaultrcsd|_tƒ ||¡Sr')r#r)r©rr.r0r+rrrQszSecureCookieSession.getcsd|_tƒ ||¡Sr')r#r)Ú
setdefaultr1r+rrr2UszSecureCookieSession.setdefault)N)N)N) rrrrr"r#r*r/rr2Ú __classcell__rrr+rr$0s r$c@s@eZdZdZddddœdd„ZeZZZZZ    Z
Z [dS)Ú NullSessionz¤Class used to generate nicer error messages if sessions are not
    available.  Will still allow read-only access to the empty session
    but fail on setting.
    r%z
t.NoReturn)ÚargsÚkwargsrcOs tdƒ‚dS)Nz€The session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.)Ú RuntimeError)rr5r6rrrÚ_fail`sÿzNullSession._failN) rrrrr8Ú __setitem__Ú __delitem__ÚclearÚpopÚpopitemÚupdater2rrrrr4Zsr4c@sâeZdZdZeZdZdddœdd„Zdd    d
œd d „Zdd dœdd„Z    dddœdd„Z
dd dœdd„Z dd    dœdd„Z dd    dœdd„Z dd dœdd„Zddddœdd„Zddd    dœd d!„Zdd"d#d$œd%d&„Zddd'd(d)œd*d+„Zd,S)-ÚSessionInterfacea4The basic interface you have to implement in order to replace the
    default session interface which uses werkzeug's securecookie
    implementation.  The only methods you have to implement are
    :meth:`open_session` and :meth:`save_session`, the others have
    useful defaults which you don't need to change.
 
    The session object returned by the :meth:`open_session` method has to
    provide a dictionary like interface plus the properties and methods
    from the :class:`SessionMixin`.  We recommend just subclassing a dict
    and adding that mixin::
 
        class Session(dict, SessionMixin):
            pass
 
    If :meth:`open_session` returns ``None`` Flask will call into
    :meth:`make_null_session` to create a session that acts as replacement
    if the session support cannot work because some requirement is not
    fulfilled.  The default :class:`NullSession` class that is created
    will complain that the secret key was not set.
 
    To replace the session interface on an application all you have to do
    is to assign :attr:`flask.Flask.session_interface`::
 
        app = Flask(__name__)
        app.session_interface = MySessionInterface()
 
    Multiple requests with the same session may be sent and handled
    concurrently. When implementing a new session interface, consider
    whether reads or writes to the backing store must be synchronized.
    There is no guarantee on the order in which the session for each
    request is opened or saved, it will occur in the order that requests
    begin and end processing.
 
    .. versionadded:: 0.8
    Fr r4©ÚapprcCs| ¡S)aÉCreates a null session which acts as a replacement object if the
        real session support could not be loaded due to a configuration
        error.  This mainly aids the user experience because the job of the
        null session is to still support lookup without complaining but
        modifications are answered with a helpful error message of what
        failed.
 
        This creates an instance of :attr:`null_session_class` by default.
        )Únull_session_class©rrArrrÚmake_null_sessions
z"SessionInterface.make_null_sessionÚobjectr)ÚobjrcCs t||jƒS)zÊChecks if a given object is a null session.  Null sessions are
        not asked to be saved.
 
        This checks if the object is an instance of :attr:`null_session_class`
        by default.
        )Ú
isinstancerB)rrFrrrÚis_null_session©sz SessionInterface.is_null_sessionr-cCs
|jdS)zJThe name of the session cookie. Uses``app.config["SESSION_COOKIE_NAME"]``.ZSESSION_COOKIE_NAME©ÚconfigrCrrrÚget_cookie_name²sz SessionInterface.get_cookie_namez
str | NonecCs|jd}|r|SdS)a“The value of the ``Domain`` parameter on the session cookie. If not set,
        browsers will only send the cookie to the exact domain it was set from.
        Otherwise, they will send it to any subdomain of the given value as well.
 
        Uses the :data:`SESSION_COOKIE_DOMAIN` config.
 
        .. versionchanged:: 2.3
            Not set by default, does not fall back to ``SERVER_NAME``.
        ZSESSION_COOKIE_DOMAINNrI)rrAÚrvrrrÚget_cookie_domain¶s
 
z"SessionInterface.get_cookie_domaincCs|jdp|jdS)aReturns the path for which the cookie should be valid.  The
        default implementation uses the value from the ``SESSION_COOKIE_PATH``
        config var if it's set, and falls back to ``APPLICATION_ROOT`` or
        uses ``/`` if it's ``None``.
        ZSESSION_COOKIE_PATHZAPPLICATION_ROOTrIrCrrrÚget_cookie_pathÃsz SessionInterface.get_cookie_pathcCs
|jdS)z¥Returns True if the session cookie should be httponly.  This
        currently just returns the value of the ``SESSION_COOKIE_HTTPONLY``
        config var.
        ZSESSION_COOKIE_HTTPONLYrIrCrrrÚget_cookie_httponlyËsz$SessionInterface.get_cookie_httponlycCs
|jdS)zŽReturns True if the cookie should be secure.  This currently
        just returns the value of the ``SESSION_COOKIE_SECURE`` setting.
        ZSESSION_COOKIE_SECURErIrCrrrÚget_cookie_secureÒsz"SessionInterface.get_cookie_securecCs
|jdS)zÄReturn ``'Strict'`` or ``'Lax'`` if the cookie should use the
        ``SameSite`` attribute. This currently just returns the value of
        the :data:`SESSION_COOKIE_SAMESITE` setting.
        ZSESSION_COOKIE_SAMESITErIrCrrrÚget_cookie_samesiteØsz$SessionInterface.get_cookie_samesiterzdatetime | None)rAÚsessionrcCs|jrt tj¡|jSdS)aA helper method that returns an expiration date for the session
        or ``None`` if the session is linked to the browser session.  The
        default implementation returns now + the permanent session
        lifetime configured on the application.
        N)rrÚnowrÚutcÚpermanent_session_lifetime©rrArRrrrÚget_expiration_timeßsz$SessionInterface.get_expiration_timecCs|jp|jo|jdS)a©Used by session backends to determine if a ``Set-Cookie`` header
        should be set for this session cookie for this response. If the session
        has been modified, the cookie is set. If the session is permanent and
        the ``SESSION_REFRESH_EACH_REQUEST`` config is true, the cookie is
        always set.
 
        This check is usually skipped if the session was deleted.
 
        .. versionadded:: 0.11
        ZSESSION_REFRESH_EACH_REQUEST)r"rrJrVrrrÚshould_set_cookieés ÿz"SessionInterface.should_set_cookier zSessionMixin | None©rAÚrequestrcCs
tƒ‚dS)aãThis is called at the beginning of each request, after
        pushing the request context, before matching the URL.
 
        This must return an object which implements a dictionary-like
        interface as well as the :class:`SessionMixin` interface.
 
        This will return ``None`` to indicate that loading failed in
        some way that is not immediately an error. The request
        context will fall back to using :meth:`make_null_session`
        in this case.
        N©ÚNotImplementedError)rrArZrrrÚ open_sessionùs zSessionInterface.open_sessionr r©rArRÚresponsercCs
tƒ‚dS)zÀThis is called at the end of each request, after generating
        a response, before removing the request context. It is skipped
        if :meth:`is_null_session` returns ``True``.
        Nr[)rrArRr_rrrÚ save_sessionszSessionInterface.save_sessionN)rrrrr4rBZ pickle_basedrDrHrKrMrNrOrPrQrWrXr]r`rrrrr?ks(      
r?c@s`eZdZdZdZeejƒZdZ    e
Z e Z dddœdd„Zdd    d
d œd d „Zdddddœdd„ZdS)ÚSecureCookieSessionInterfacezuThe default session interface that stores sessions in signed cookies
    through the :mod:`itsdangerous` module.
    zcookie-sessionÚhmacr zURLSafeTimedSerializer | Noner@cCs0|js
dSt|j|jd}t|j|j|j|dS)N)Úkey_derivationÚ digest_method)ÚsaltÚ
serializerÚ signer_kwargs)Z
secret_keyÚdictrcrdrrerf)rrArgrrrÚget_signing_serializer'sÿüz3SecureCookieSessionInterface.get_signing_serializerr zSecureCookieSession | NonerYcCs~| |¡}|dkrdS|j | |¡¡}|s4| ¡St|j ¡ƒ}z|j||d}| |¡WSt    k
rx| ¡YSXdS)N)Úmax_age)
riÚcookiesrrKÚ session_classÚintrUÚ total_secondsÚloadsr)rrArZÚsÚvalrjÚdatarrrr]4s
 z)SecureCookieSessionInterface.open_sessionrr rr^c
CsØ| |¡}| |¡}| |¡}| |¡}| |¡}| |¡}    |jrN|j d¡|s~|j    rz|j
||||||    d|j d¡dS|  ||¡sŽdS|  ||¡}
|  |¡ t|ƒ¡} |j|| |
|    ||||d|j d¡dS)NÚCookie)ÚdomainÚpathÚsecureÚsamesiteÚhttponly)Úexpiresrxrtrurvrw)rKrMrNrPrQrOr#ÚvaryÚaddr"Z delete_cookierXrWriÚdumpsrhÚ
set_cookie) rrArRr_Únamertrurvrwrxryrqrrrr`BsF
 
 
 
 
 
 ú   ø
z)SecureCookieSessionInterface.save_sessionN)rrrrreÚ staticmethodÚhashlibÚsha1rdrcÚsession_json_serializerrfr$rlrir]r`rrrrras
 ra)Ú
__future__rr€ÚtypingÚtÚcollections.abcrrrZ itsdangerousrrZwerkzeug.datastructuresrZjson.tagr
Ú TYPE_CHECKINGrAr Úwrappersr r rr$r4r?r‚rarrrrÚ<module>s&         *'