Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
sessions.cpython-313.pyc160 linesDownload Raw Back to __pycache__
1�

2��jy:���SSKJr SSKJr SSKrSSKrSSKJr SSK	J	r	 SSK	J3r4 SSKJr SSKJ
r
 SSKJr S	S5KJr \R$(aSSKrS	SKJr S	SKJr S	S
KJr "SS\\\R645r"SS\\\R64\5r"SS\5r"SS5r\"5r SSSjjr!"SS\5r"g)�)�annotationsN)�MutableMapping)�datetime)�timezone)�BadSignature)�URLSafeTimedSerializer)�CallbackDict�)�TaggedJSONSerializer)�Flask)�Request)�Responsec�`�\rSrSrSr\S	Sj5r\RS6Sj5rSrSr	Sr7Srg)�SessionMixin�z3Expands a basic dictionary with session attributes.c�&�URSS5$)z3This reflects the ``'_permanent'`` key in the dict.�8_permanentF)�get��selfs �TD:\code\apps\devtools\python\user_packages\Python313\site-packages\flask/sessions.py�	permanent�SessionMixin.permanents���x�x��e�,�,�c� �[U5US'g)Nr)�bool)r�values  rrr s��!�%�[��\�rFT�N)�returnr)rrr�None)�__name__�9__module__�__qualname__�__firstlineno__�__doc__�propertyr�setter�new�modified�accessed�__static_attributes__rrrrrsI��=�
�-��-����)��)��C�10�H��H�rrc�@^�\rSrSrSrSrSSU4SjjjrSrU=r$)�SecureCookieSession�9z�Base class for sessions based on signed cookies.11 12This session backend will set the :attr:`modified` and13:attr:`accessed` attributes. It cannot reliably track whether a14session is new (vs. empty), so :attr:`new` remains hard coded to15``False``.16Fc�.>�SSjn[TU]X5 g)Nc��SUlg)NT�r)rs r�	on_update�/SecureCookieSession.__init__.<locals>.on_updateMs	�� �D�Mr)rzte.Selfrr )�super�__init__)r�initialr2�	__class__s   �rr5�SecureCookieSession.__init__Is���	!�	����,rr1)N)r6zc.Mapping[str, t.Any] | Nonerr )	r!r"r#r$r%r)r5r+�
__classcell__)r7s@rr-r-9s0�����H�15�-�-�-�17�-�-rr-c�@�\rSrSrSrSSjr\=r=r=r=r	=r18=rrCSr
g)�NullSession�Sz�Class used to generate nicer error messages if sessions are not19available.  Will still allow read-only access to the empty session20but fail on setting.21c��[S5e)Nz�The session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.)�RuntimeError)r�args�kwargss   r�_fail�NullSession._failYs���
:�22�	23rrN)r?�t.Anyr@rCrz24t.NoReturn)r!r"r#r$r%rA�__setitem__�__delitem__�clear�pop�popitem�update�25setdefaultr+rrrr;r;Ss6���2627�OT�S�K�S�+�S��S��S�g�S���
rr;c��\rSrSrSr\rSrSSjrSSjr	SSjr28SSjrSSjrSS	jr
SS29jrSSjrSSjrSS
jrSSjrSSjrSSjrSrg)�SessionInterface�da�The basic interface you have to implement in order to replace the30default session interface which uses werkzeug's securecookie31implementation.  The only methods you have to implement are32:meth:`open_session` and :meth:`save_session`, the others have33useful defaults which you don't need to change.34 35The session object returned by the :meth:`open_session` method has to36provide a dictionary like interface plus the properties and methods37from the :class:`SessionMixin`.  We recommend just subclassing a dict38and adding that mixin::39 40    class Session(dict, SessionMixin):41        pass42 43If :meth:`open_session` returns ``None`` Flask will call into44:meth:`make_null_session` to create a session that acts as replacement45if the session support cannot work because some requirement is not46fulfilled.  The default :class:`NullSession` class that is created47will complain that the secret key was not set.48 49To replace the session interface on an application all you have to do50is to assign :attr:`flask.Flask.session_interface`::51 52    app = Flask(__name__)53    app.session_interface = MySessionInterface()54 55Multiple requests with the same session may be sent and handled56concurrently. When implementing a new session interface, consider57whether reads or writes to the backing store must be synchronized.58There is no guarantee on the order in which the session for each59request is opened or saved, it will occur in the order that requests60begin and end processing.61 62.. versionadded:: 0.863Fc�"�UR5$)a�Creates a null session which acts as a replacement object if the64real session support could not be loaded due to a configuration65error.  This mainly aids the user experience because the job of the66null session is to still support lookup without complaining but67modifications are answered with a helpful error message of what68failed.69 70This creates an instance of :attr:`null_session_class` by default.71)�null_session_class�r�apps  r�make_null_session�"SessionInterface.make_null_session�s���&�&�(�(rc�,�[XR5$)z�Checks if a given object is a null session.  Null sessions are72not asked to be saved.73 74This checks if the object is an instance of :attr:`null_session_class`75by default.76)�77isinstancerO)r�objs  r�is_null_session� SessionInterface.is_null_session�s���#�6�6�7�7rc� �URS$)zJThe name of the session cookie. Uses``app.config["SESSION_COOKIE_NAME"]``.�SESSION_COOKIE_NAME��configrPs  r�get_cookie_name� SessionInterface.get_cookie_name�s���z�z�/�0�0rc� �URS$)acThe value of the ``Domain`` parameter on the session cookie. If not set,78browsers will only send the cookie to the exact domain it was set from.79Otherwise, they will send it to any subdomain of the given value as well.80 81Uses the :data:`SESSION_COOKIE_DOMAIN` config.82 83.. versionchanged:: 2.384    Not set by default, does not fall back to ``SERVER_NAME``.85�SESSION_COOKIE_DOMAINr[rPs  r�get_cookie_domain�"SessionInterface.get_cookie_domain�s���z�z�1�2�2rc�L�URS=(d URS$)z�Returns the path for which the cookie should be valid.  The86default implementation uses the value from the ``SESSION_COOKIE_PATH``87config var if it's set, and falls back to ``APPLICATION_ROOT`` or88uses ``/`` if it's ``None``.89�SESSION_COOKIE_PATH�APPLICATION_ROOTr[rPs  r�get_cookie_path� SessionInterface.get_cookie_path�s#���z�z�/�0�R�C�J�J�?Q�4R�Rrc� �URS$)z�Returns True if the session cookie should be httponly.  This90currently just returns the value of the ``SESSION_COOKIE_HTTPONLY``91config var.92�SESSION_COOKIE_HTTPONLYr[rPs  r�get_cookie_httponly�$SessionInterface.get_cookie_httponly����93�z�z�3�4�4rc� �URS$)z~Returns True if the cookie should be secure.  This currently94just returns the value of the ``SESSION_COOKIE_SECURE`` setting.95�SESSION_COOKIE_SECUREr[rPs  r�get_cookie_secure�"SessionInterface.get_cookie_secure�s���z�z�1�2�2rc� �URS$)z�Return ``'Strict'`` or ``'Lax'`` if the cookie should use the96``SameSite`` attribute. This currently just returns the value of97the :data:`SESSION_COOKIE_SAMESITE` setting.98�SESSION_COOKIE_SAMESITEr[rPs  r�get_cookie_samesite�$SessionInterface.get_cookie_samesite�rlrc� �URS$)z�Returns True if the cookie should be partitioned. By default, uses99the value of :data:`SESSION_COOKIE_PARTITIONED`.100 101.. versionadded:: 3.1102�SESSION_COOKIE_PARTITIONEDr[rPs  r�get_cookie_partitioned�'SessionInterface.get_cookie_partitioned�s���z�z�6�7�7rc��UR(a1[R"[R5UR103-$g)z�A helper method that returns an expiration date for the session104or ``None`` if the session is linked to the browser session.  The105default implementation returns now + the permanent session106lifetime configured on the application.107N)rr�nowr�utc�permanent_session_lifetime�rrQ�sessions   r�get_expiration_time�$SessionInterface.get_expiration_time�s.������<�<����-��0N�0N�N�N�rc�l�UR=(d" UR=(a URS$)aqUsed by session backends to determine if a ``Set-Cookie`` header108should be set for this session cookie for this response. If the session109has been modified, the cookie is set. If the session is permanent and110the ``SESSION_REFRESH_EACH_REQUEST`` config is true, the cookie is111always set.112 113This check is usually skipped if the session was deleted.114 115.. versionadded:: 0.11116�SESSION_REFRESH_EACH_REQUEST)r)rr\r}s   r�should_set_cookie�"SessionInterface.should_set_cookie�s/�����117����L�#�*�*�-K�"L�	118rc��[5e)a�This is called at the beginning of each request, after119pushing the request context, before matching the URL.120 121This must return an object which implements a dictionary-like122interface as well as the :class:`SessionMixin` interface.123 124This will return ``None`` to indicate that loading failed in125some way that is not immediately an error. The request126context will fall back to using :meth:`make_null_session`127in this case.128��NotImplementedError)rrQ�requests   r�open_session�SessionInterface.open_session�s
��"�#�#rc��[5e)z�This is called at the end of each request, after generating129a response, before removing the request context. It is skipped130if :meth:`is_null_session` returns ``True``.131r�)rrQr~�responses    r�save_session�SessionInterface.save_sessions
��"�#�#rrN)rQrrr;)rV�objectrr)rQrr�str)rQrrz132str | None)rQrrr)rQrr~rrzdatetime | None)rQrr~rrr)rQrr�r
rzSessionMixin | None�rQrr~rr�rrr )r!r"r#r$r%r;rO�pickle_basedrRrWr]rarfrjrorsrwrr�r�r�r+rrrrLrLdsy��"�P%���L�133)�8�1�1343�S�5�3�5�8��135� $�$��$�#/�$�;C�$�	
�$rrLc�.�[R"U5$)z�Don't access ``hashlib.sha1`` until runtime. FIPS builds may not include136SHA-1, in which case the import and use as a default would fail before the137developer can configure something else.138)�hashlib�sha1)�strings r�139_lazy_sha1r�s��140�<�<���rc�f�\rSrSrSrSr\"\5rSr	\141r\r
S142SjrSSjrSSjrSrg	)
�SecureCookieSessionInterfaceizmThe default session interface that stores sessions in signed cookies143through the :mod:`itsdangerous` module.144zcookie-session�hmacc��UR(dg/nURS=n(aURU5 URUR5 [	UUR145URURURS.S9$)N�SECRET_KEY_FALLBACKS)�key_derivation�
digest_method)�salt�146serializer�
signer_kwargs)	�147secret_keyr\�extend�appendrr�r�r�r�)rrQ�keys�	fallbackss    r�get_signing_serializer�3SecureCookieSessionInterface.get_signing_serializer/sw���~�~��"$���148�149�#9�:�:�9�:��K�K�	�"����C�N�N�#�%��������"&�"5�"5�!%�!3�!3��	150�	151rc�v�URU5nUcgURRURU55nU(dUR	5$[URR55nURXES9nUR	U5$![a UR	5s$f=f)N)�max_age)152r��cookiesrr]�
session_class�intr|�
total_seconds�loadsr)rrQr��s�valr��datas       rr��)SecureCookieSessionInterface.open_sessionCs����'�'��,���9���o�o�!�!�$�"6�"6�s�";�<����%�%�'�'��c�4�4�B�B�D�E��	(��7�7�3�7�0�D��%�%�d�+�+���	(��%�%�'�'�	(�s�;B�B8�7B8c���URU5nURU5nURU5nURU5nUR	U5nURU5n	UR
U5n153UR(aURRS5 U(dBUR(a0URUUUUUU	U154S9 URRS5 gURX5(dgURX5nURU5R[!U55nUR#UUUU155UUUUU	S9	 URRS5 g)N�Cookie)�domain�path�secure�partitioned�samesite�httponly)�expiresr�r�r�r�r�r�)r]rarfrorwrsrjr*�vary�addr)�
delete_cookier�rr��dumps�dict�156set_cookie)
rrQr~r��namer�r�r�r�r�r�r�r�s
             rr��)SecureCookieSessionInterface.save_sessionQsc���#�#�C�(���'�'��,���#�#�C�(���'�'��,���1�1�#�6���+�+�C�0���+�+�C�0������M�M���h�'������&�&��!��!� +�%�%�'���
�
�!�!�(�+���%�%�c�3�3���*�*�3�8���)�)�#�.�4�4�T�'�]�C������������#��	�157	158�	�
�
���(�#rrN)rQrrzURLSafeTimedSerializer | None)rQrr�r
rzSecureCookieSession | Noner�)r!r"r#r$r%r��staticmethodr�r�r��session_json_serializerr�r-r�r�r�r�r+rrrr�r�sZ����D� ��,�M��N�)�J�'�M�159�((�0$��0$�#/�0$�;C�0$�	
�0$rr�)r)r��bytesrrC)#�160__future__r�collections.abc�abc�cr��typing�trrr�itsdangerousrr�werkzeug.datastructuresr	�json.tagr�
TYPE_CHECKING�typing_extensions�terQr�wrappersr
rr��Anyrr-r;rLr�r�r�rrr�<module>r�s���"����*���%�/�0�*��?�?�"��!�"��>�#�q�u�u�*�-��B-�,�s�A�E�E�z�2�L�-�4�%��"j$�j$�Z/�0�� �e$�#3�e$r
codekingpro/portable-devtools · Team Ai