U aU;@sddlZddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z dd lmZejrddlZdd lmZdd lmZmZGd d d eZGddde eZGdddeZGdddZeZGdddeZdS)N)MutableMapping)datetime) BadSignature)URLSafeTimedSerializer) CallbackDict)is_ip)TaggedJSONSerializer)Flask)RequestResponsec@sDeZdZdZeedddZejeddddZdZd Z d Z dS) SessionMixinz3Expands a basic dictionary with session attributes.returncCs |ddS)z3This reflects the ``'_permanent'`` key in the dict. _permanentF)getselfrOC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-e702oxwa\flask\sessions.py permanentszSessionMixin.permanentN)valuercCst||d<dS)Nr)bool)rrrrrrsFT) __name__ __module__ __qualname____doc__propertyrrsetternewmodifiedaccessedrrrrr sr cseZdZdZdZdZdejddfdd Ze ejdfdd Z de ejejd fd d Z de ejejd fd d 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)initialrcs dddd}t||dS)NrcSsd|_d|_dSNT)r r!rrrr on_updateGsz/SecureCookieSession.__init__..on_update)super__init__)rr#r% __class__rrr'FszSecureCookieSession.__init__)keyrcsd|_t|Sr$)r!r& __getitem__)rr*r(rrr+MszSecureCookieSession.__getitem__)r*defaultrcsd|_t||Sr$)r!r&rrr*r,r(rrrQszSecureCookieSession.getcsd|_t||Sr$)r!r& setdefaultr-r(rrr.UszSecureCookieSession.setdefault)N)N)N)rrrrr r!tAnyr'strr+rr. __classcell__rrr(rr"0s r"c@sDeZdZdZejejddddZeZZZ Z Z Z 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. z te.NoReturn)argskwargsrcOs tddS)NzThe session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.) RuntimeError)rr4r5rrr_fail`szNullSession._failN)rrrrr/r0r7 __setitem__ __delitem__clearpoppopitemupdater.rrrrr3Zsr3c@seZdZdZeZdZdedddZee ddd Z de dd d Z de je dd d Zde dddZde dddZde dddZde dddZdee jedddZdee dddZdde jedddZdedd d!d"d#Zd S)$SessionInterfaceaThe 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() .. versionadded:: 0.8 Fr apprcCs|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_classrr@rrrmake_null_sessions z"SessionInterface.make_null_session)objrcCs 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. ) isinstancerA)rrDrrris_null_sessionsz SessionInterface.is_null_sessioncCs|jS)zReturns the name of the session cookie. Uses ``app.session_cookie_name`` which is set to ``SESSION_COOKIE_NAME`` )Zsession_cookie_namerBrrrget_cookie_namesz SessionInterface.get_cookie_namecCs|jd}|dk r|r|SdS|jd}|s:d|jd<dS|dddd}d|kr|t|d |d d|jd<dSt|}|rtd ||d kr|sd|}||jd<|S) aMReturns the domain that should be set for the session cookie. Uses ``SESSION_COOKIE_DOMAIN`` if it is configured, otherwise falls back to detecting the domain based on ``SERVER_NAME``. Once detected (or if not set at all), ``SESSION_COOKIE_DOMAIN`` is updated to avoid re-running the logic. ZSESSION_COOKIE_DOMAINNZ SERVER_NAMEF:rr.zd is not a valid cookie domain, it must contain a '.'. Add an entry to your hosts file, for example 'z$.localdomain', and use that instead.zThe session cookie domain is an IP address. This may not work as intended in some browsers. Add an entry to your hosts file, for example "localhost.localdomain", and use that instead./)configrsplitlstripwarningswarnrget_cookie_path)rr@rviprrrget_cookie_domains.        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_ROOTrKrBrrrrPsz SessionInterface.get_cookie_pathcCs |jdS)zReturns True if the session cookie should be httponly. This currently just returns the value of the ``SESSION_COOKIE_HTTPONLY`` config var. ZSESSION_COOKIE_HTTPONLYrTrBrrrget_cookie_httponlysz$SessionInterface.get_cookie_httponlycCs |jdS)zReturns True if the cookie should be secure. This currently just returns the value of the ``SESSION_COOKIE_SECURE`` setting. ZSESSION_COOKIE_SECURErTrBrrrget_cookie_securesz"SessionInterface.get_cookie_securecCs |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. ZSESSION_COOKIE_SAMESITErTrBrrrget_cookie_samesitesz$SessionInterface.get_cookie_samesite)r@sessionrcCs|jrt|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)rrutcnowpermanent_session_lifetimerr@rXrrrget_expiration_timesz$SessionInterface.get_expiration_timecCs|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 ZSESSION_REFRESH_EACH_REQUEST)r rrKr[rrrshould_set_cookies z"SessionInterface.should_set_cookier r@requestrcCs tdS)a%This method has to be implemented and must either return ``None`` in case the loading failed because of a configuration error or an instance of a session object which implements a dictionary like interface + the methods and attributes on :class:`SessionMixin`. NNotImplementedError)rr@r_rrr open_session$szSessionInterface.open_sessionr Nr@rXresponsercCs tdS)zThis is called for actual sessions returned by :meth:`open_session` at the end of the request. This is still called during a request context so if you absolutely need access to the request you can do that. Nr`)rr@rXrdrrr save_session.szSessionInterface.save_session)rrrrr3rAZ pickle_basedrCobjectrrFr1rGr/OptionalrSrPrUrVrWr rr\r]rbrerrrrr>ks2!  :  r>c@sleZdZdZdZeejZdZ e Z e Z dejedddZddeje d d d Zded d dddZd S)SecureCookieSessionInterfacezuThe default session interface that stores sessions in signed cookies through the :mod:`itsdangerous` module. zcookie-sessionhmacr r?cCs0|js dSt|j|jd}t|j|j|j|dS)N)key_derivation digest_method)salt serializer signer_kwargs)Z secret_keydictrjrkrrlrm)rr@rnrrrget_signing_serializerOsz3SecureCookieSessionInterface.get_signing_serializerr r^cCs~||}|dkrdS|j||}|s4|St|j}z|j||d}||WSt k rx|YSXdS)N)max_age) rpcookiesrrG session_classintrZ total_secondsloadsr)rr@r_svalrqdatarrrrb^s  z)SecureCookieSessionInterface.open_sessionr Nrcc Cs||}||}||}||}||}|sT|jrP|j|||||ddS|jrf|j d| ||svdS| |} | ||} | |t|} |j|| | | ||||ddS)N)domainpathsecuresamesiteCookie)expireshttponlyrzr{r|r})rGrSrPrVrWr Z delete_cookier!varyaddr]rUr\rpdumpsro set_cookie) rr@rXrdnamerzr{r|r}rrrxrrrrens@         z)SecureCookieSessionInterface.save_session)rrrrrl staticmethodhashlibsha1rkrjsession_json_serializerrmr"rsr/rgrrprbr rerrrrrh<s$   rh)rtypingr/rNcollections.abcrrZ itsdangerousrrZwerkzeug.datastructuresrZhelpersrZjson.tagr TYPE_CHECKINGZtyping_extensionster@r wrappersr r r r"r3r>rrhrrrrs(        *O