;ix<ddlmZddlmZddlZddlZddlmZddl m Z ddl m Z ddl m Z ddl m Z ddlmZd d lmZejrddlZd d lmZd d lmZd d lmZGddeeejfZGddeeejfeZGddeZGddZeZ dddZ!GddeZ"dS) ) annotationsN)MutableMapping)datetime)timezone) BadSignature)URLSafeTimedSerializer) CallbackDict)TaggedJSONSerializer)Flask)Request)ResponsecXeZdZdZed dZejd dZdZd Zd Z d S) SessionMixinz3Expands a basic dictionary with session attributes.returnboolc.|ddS)z3This reflects the ``'_permanent'`` key in the dict. _permanentF)getselfs BC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\flask/sessions.py permanentzSessionMixin.permanentsxx e,,,valueNonec*t||d<dS)Nr)r)rrs rrzSessionMixin.permanent s!%[[\rFTN)rr)rrrr) __name__ __module__ __qualname____doc__propertyrsetternewmodifiedaccessedrrrrsk== ---X-)))) C H HHHrrcXeZdZdZdZdZ ddfd Zdfd Zddfd Zddfd Z xZ 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``. FNinitial.on_updateNs DM DMMMr)rr-rr)super__init__)rr*r0 __class__s rr2zSecureCookieSession.__init__Js9 ! ! ! ! ),,,,,rkeystrt.AnycTd|_t|Sr/)r&r1 __getitem__)rr4r3s rr8zSecureCookieSession.__getitem__Ts" ww""3'''rdefaultcVd|_t||Sr/)r&r1rrr4r9r3s rrzSecureCookieSession.getXs" ww{{3(((rcVd|_t||Sr/)r&r1 setdefaultr;s rr=zSecureCookieSession.setdefault\s$ ww!!#w///r)N)r*r+rr)r4r5rr6)r4r5r9r6rr6) rrr r!r%r&r2r8rr= __classcell__)r3s@rr)r)4sH HQU-------(((((()))))))00000000000rr)c8eZdZdZd dZexZxZxZxZxZ xZ Z [dS) NullSessionzClass 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. argsr6kwargsr t.NoReturnc td)NzThe session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.) RuntimeError)rrArBs r_failzNullSession._failgs :   rN)rAr6rBr6rrC) rrr r!rF __setitem__ __delitem__clearpoppopitemupdater=r'rrr@r@asV     OTSKS+SSSgS rr@ceZdZdZeZdZd#dZd$d Zd%d Z d&dZ d%dZ d'dZ d'dZ d&dZd'dZd(dZd)dZd*dZd+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 Fappr rr@c*|S)aCreates 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_classrrOs rmake_null_sessionz"SessionInterface.make_null_sessions&&(((robjobjectrc,t||jS)zChecks 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. ) isinstancerQ)rrTs ris_null_sessionz SessionInterface.is_null_sessions#t6777rr5c|jdS)zJThe name of the session cookie. Uses``app.config["SESSION_COOKIE_NAME"]``.SESSION_COOKIE_NAMEconfigrRs rget_cookie_namez SessionInterface.get_cookie_namesz/00r str | Nonec|jdS)aThe 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``. SESSION_COOKIE_DOMAINr[rRs rget_cookie_domainz"SessionInterface.get_cookie_domainsz122rc6|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``. SESSION_COOKIE_PATHAPPLICATION_ROOTr[rRs rget_cookie_pathz SessionInterface.get_cookie_paths z/0RCJ?Q4RRrc|jdS)zReturns True if the session cookie should be httponly. This currently just returns the value of the ``SESSION_COOKIE_HTTPONLY`` config var. SESSION_COOKIE_HTTPONLYr[rRs rget_cookie_httponlyz$SessionInterface.get_cookie_httponly z344rc|jdS)zReturns True if the cookie should be secure. This currently just returns the value of the ``SESSION_COOKIE_SECURE`` setting. SESSION_COOKIE_SECUREr[rRs rget_cookie_securez"SessionInterface.get_cookie_securesz122rc|jdS)zReturn ``'Strict'`` or ``'Lax'`` if the cookie should use the ``SameSite`` attribute. This currently just returns the value of the :data:`SESSION_COOKIE_SAMESITE` setting. SESSION_COOKIE_SAMESITEr[rRs rget_cookie_samesitez$SessionInterface.get_cookie_samesiterirc|jdS)zReturns True if the cookie should be partitioned. By default, uses the value of :data:`SESSION_COOKIE_PARTITIONED`. .. versionadded:: 3.1 SESSION_COOKIE_PARTITIONEDr[rRs rget_cookie_partitionedz'SessionInterface.get_cookie_partitioneds z677rsessionrdatetime | Nonec`|jr&tjtj|jzSdS)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)rrnowrutcpermanent_session_lifetimerrOrss rget_expiration_timez$SessionInterface.get_expiration_times/   O< --0NN Ntrc8|jp|jo |jdS)aUsed 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 SESSION_REFRESH_EACH_REQUEST)r%rr\rys rshould_set_cookiez"SessionInterface.should_set_cookies'   L#*-K"L rrequestr SessionMixin | Nonect)aThis 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. NotImplementedError)rrOr~s r open_sessionzSessionInterface.open_sessions"###rresponserrct)zThis 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``. r)rrOrsrs r save_sessionzSessionInterface.save_sessions"###rN)rOr rr@)rTrUrr)rOr rr5)rOr rr^)rOr rr)rOr rsrrrt)rOr rsrrr)rOr r~r rrrOr rsrrrrr)rrr r!r@rQ pickle_basedrSrXr]rarerhrlrorrrzr}rrr'rrrNrNrs6""P%L ) ) ) )88881111 3 3 3 3SSSS55553333 55558888    $ $ $ $$$$$$$rrNrstringbytesrr6c*tj|S)zDon't access ``hashlib.sha1`` until runtime. FIPS builds may not include SHA-1, in which case the import and use as a default would fail before the developer can configure something else. )hashlibsha1)rs r _lazy_sha1r"s <  rcPeZdZdZdZeeZdZe Z e Z ddZ dd ZddZdS)SecureCookieSessionInterfacezuThe default session interface that stores sessions in signed cookies through the :mod:`itsdangerous` module. zcookie-sessionhmacrOr rURLSafeTimedSerializer | Nonec|jsdSg}|jdx}r||||jt ||j|j|j|jdS)NSECRET_KEY_FALLBACKS)key_derivation digest_method)salt serializer signer_kwargs) secret_keyr\extendappendrrrrr)rrOkeys fallbackss rget_signing_serializerz3SecureCookieSessionInterface.get_signing_serializer=s~ 4"$ #9: :9 # KK " " " CN###% "&"5!%!3     rr~r SecureCookieSession | Nonec||}|dS|j||}|s|St |j} |||}||S#t$r|cYSwxYw)N)max_age) rcookiesrr] session_classintrx total_secondsloadsr)rrOr~svalrdatas rrz)SecureCookieSessionInterface.open_sessionQs  ' ' , , 94o!!$"6"6s";";<< (%%'' 'c4BBDDEE (773700D%%d++ + ( ( (%%'' ' ' ' (s+B00CCrsrrrrc &||}||}||}||}||}||} ||} |jr|j d|s?|j r6| |||||| | |j ddS| ||sdS| ||} ||t!|} ||| | | |||||  |j ddS)NCookie)domainpathsecure partitionedsamesitehttponly)expiresrrrrrr)r]rarerlrrrorhr&varyaddr% delete_cookier}rzrdumpsdict set_cookie) rrOrsrnamerrrrrrrrs rrz)SecureCookieSessionInterface.save_session_s##C(('',,##C(('',,11#66 ++C00++C00   ( M  h ' ' '  ,&&!! +%%' !!(+++ F%%c733  F**388))#..44T']]CC  #    (#####rN)rOr rr)rOr r~r rrr)rrr r!r staticmethodrrrsession_json_serializerrr)rrrrr'rrrr*s D L,,MN)J'M    ( ( ( ( (0$0$0$0$0$0$rr)r)rrrr6)# __future__rcollections.abcabccrtypingtrrr itsdangerousrrwerkzeug.datastructuresr json.tagr TYPE_CHECKINGtyping_extensionsterOr wrappersr rr5Anyrr)r@rNrrrr'rrrs:""""""******%%%%%%//////000000******?#""""!!!!!!"""""">#qu*-8*0*0*0*0*0,sAEz2L*0*0*0Z%"j$j$j$j$j$j$j$j$Z/.00     e$e$e$e$e$#3e$e$e$e$e$r