Format: application/x-python-code
⬇ Download File (13.9 KB)
   1  o
   2  
   3  D'hF<�@s(ddlmZddlmZddlZddlZddlmZddl	m	Z	ddl	m
   4  Z
   5  ddlmZddlm
   6  Z
   7  ddlmZd	d
   8  lmZejrWddlZd	dlmZd	dlmZd	d
   9  lmZGdd�deeejf�ZGdd�deeejfe�ZGdd�de�ZGdd�d�Ze�Z dd dd�Z!Gdd�de�Z"dS)!�)�annotationsN)�MutableMapping)�datetime)�timezone)�BadSignature)�URLSafeTimedSerializer)�CallbackDict�)�TaggedJSONSerializer)�Flask)�Request)�Responsec@s:eZdZdZeddd��Zejd
  10  dd��Zd	Zd
  11  Zd
  12  Z	dS)�SessionMixinz3Expands a basic dictionary with session attributes.�return�boolcCs|�dd�S)z3This reflects the ``'_permanent'`` key in the dict.�
  13  _permanentF)�get��self�r�DC:\Users\shubh\Videos\agent\nova\Lib\site-packages\flask/sessions.py�	permanentszSessionMixin.permanent�value�NonecCst|�|d<dS)Nr)r)rrrrrr sFTN)rr)rrrr)
  14  �__name__�
  15  __module__�__qualname__�__doc__�propertyr�setter�new�modified�accessedrrrrrsrcs\eZdZdZdZdZ	dd�fdd	�
  16  Zd�fd
  17  d�Zdd�fdd�
  18  Zdd�fdd�
  19  Z	�Z
  20  S)�SecureCookieSessiona	Base class for sessions based on signed cookies.
  21  
  22      This session backend will set the :attr:`modified` and
  23      :attr:`accessed` attributes. It cannot reliably track whether a
  24      session is new (vs. empty), so :attr:`new` remains hard coded to
  25      ``False``.
  26      FN�initial�<c.Mapping[str, t.Any] | c.Iterable[tuple[str, t.Any]] | Nonerrcsddd�}t��||�dS)Nr�te.SelfrrcSsd|_d|_dS�NT)r!r"rrrr�	on_updateNs
  27  z/SecureCookieSession.__init__.<locals>.on_update)rr&rr)�super�__init__)rr$r(��	__class__rrr*Js
  28  zSecureCookieSession.__init__�key�str�t.Anycsd|_t��|�Sr')r"r)�__getitem__)rr-r+rrr0TszSecureCookieSession.__getitem__�defaultc�d|_t��||�Sr')r"r)r�rr-r1r+rrrX�zSecureCookieSession.getcr2r')r"r)�
  29  setdefaultr3r+rrr5\r4zSecureCookieSession.setdefault)N)r$r%rr)r-r.rr/)r-r.r1r/rr/)rrrrr!r"r*r0rr5�
  30  __classcell__rrr+rr#4s
  31  �
  32  r#c@s8eZdZdZd
  33  dd�ZeZZZZZ	Z
  34  Z[d	S)�NullSessionz�Class used to generate nicer error messages if sessions are not
  35      available.  Will still allow read-only access to the empty session
  36      but fail on setting.
  37      �argsr/�kwargsr�
  38  t.NoReturncOstd��)Nz�The session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.)�RuntimeError)rr8r9rrr�_failgs�zNullSession._failN)r8r/r9r/rr:)rrrrr<�__setitem__�__delitem__�clear�pop�popitem�updater5rrrrr7as
  39  
  40  r7c@s�eZdZdZeZdZd0dd�Zd1dd
  41  �Zd2dd�Z	d3dd�Z
  42  d2dd�Zd4dd�Zd4dd�Z
  43  d3dd�Zd4dd�Zd5d!d"�Zd6d#d$�Zd7d(d)�Zd8d-d.�Zd/S)9�SessionInterfacea4The basic interface you have to implement in order to replace the
  44      default session interface which uses werkzeug's securecookie
  45      implementation.  The only methods you have to implement are
  46      :meth:`open_session` and :meth:`save_session`, the others have
  47      useful defaults which you don't need to change.
  48  
  49      The session object returned by the :meth:`open_session` method has to
  50      provide a dictionary like interface plus the properties and methods
  51      from the :class:`SessionMixin`.  We recommend just subclassing a dict
  52      and adding that mixin::
  53  
  54          class Session(dict, SessionMixin):
  55              pass
  56  
  57      If :meth:`open_session` returns ``None`` Flask will call into
  58      :meth:`make_null_session` to create a session that acts as replacement
  59      if the session support cannot work because some requirement is not
  60      fulfilled.  The default :class:`NullSession` class that is created
  61      will complain that the secret key was not set.
  62  
  63      To replace the session interface on an application all you have to do
  64      is to assign :attr:`flask.Flask.session_interface`::
  65  
  66          app = Flask(__name__)
  67          app.session_interface = MySessionInterface()
  68  
  69      Multiple requests with the same session may be sent and handled
  70      concurrently. When implementing a new session interface, consider
  71      whether reads or writes to the backing store must be synchronized.
  72      There is no guarantee on the order in which the session for each
  73      request is opened or saved, it will occur in the order that requests
  74      begin and end processing.
  75  
  76      .. versionadded:: 0.8
  77      F�apprrr7cCs|��S)a�Creates a null session which acts as a replacement object if the
  78          real session support could not be loaded due to a configuration
  79          error.  This mainly aids the user experience because the job of the
  80          null session is to still support lookup without complaining but
  81          modifications are answered with a helpful error message of what
  82          failed.
  83  
  84          This creates an instance of :attr:`null_session_class` by default.
  85          )�null_session_class�rrDrrr�make_null_session�s
  86  z"SessionInterface.make_null_session�obj�objectrcCst||j�S)z�Checks if a given object is a null session.  Null sessions are
  87          not asked to be saved.
  88  
  89          This checks if the object is an instance of :attr:`null_session_class`
  90          by default.
  91          )�
  92  isinstancerE)rrHrrr�is_null_session�sz SessionInterface.is_null_sessionr.cC�
  93  |jdS)zJThe name of the session cookie. Uses``app.config["SESSION_COOKIE_NAME"]``.ZSESSION_COOKIE_NAME��configrFrrr�get_cookie_name�s
  94  z SessionInterface.get_cookie_name�
  95  str | NonecCrL)a�The value of the ``Domain`` parameter on the session cookie. If not set,
  96          browsers will only send the cookie to the exact domain it was set from.
  97          Otherwise, they will send it to any subdomain of the given value as well.
  98  
  99          Uses the :data:`SESSION_COOKIE_DOMAIN` config.
 100  
 101          .. versionchanged:: 2.3
 102              Not set by default, does not fall back to ``SERVER_NAME``.
 103          ZSESSION_COOKIE_DOMAINrMrFrrr�get_cookie_domain�s
 104  
 105  z"SessionInterface.get_cookie_domaincCs|jdp	|jdS)aReturns the path for which the cookie should be valid.  The
 106          default implementation uses the value from the ``SESSION_COOKIE_PATH``
 107          config var if it's set, and falls back to ``APPLICATION_ROOT`` or
 108          uses ``/`` if it's ``None``.
 109          ZSESSION_COOKIE_PATHZAPPLICATION_ROOTrMrFrrr�get_cookie_path�sz SessionInterface.get_cookie_pathcCrL)z�Returns True if the session cookie should be httponly.  This
 110          currently just returns the value of the ``SESSION_COOKIE_HTTPONLY``
 111          config var.
 112          ZSESSION_COOKIE_HTTPONLYrMrFrrr�get_cookie_httponly��
 113  z$SessionInterface.get_cookie_httponlycCrL)z�Returns True if the cookie should be secure.  This currently
 114          just returns the value of the ``SESSION_COOKIE_SECURE`` setting.
 115          ZSESSION_COOKIE_SECURErMrFrrr�get_cookie_secure�s
 116  z"SessionInterface.get_cookie_securecCrL)z�Return ``'Strict'`` or ``'Lax'`` if the cookie should use the
 117          ``SameSite`` attribute. This currently just returns the value of
 118          the :data:`SESSION_COOKIE_SAMESITE` setting.
 119          ZSESSION_COOKIE_SAMESITErMrFrrr�get_cookie_samesite�rTz$SessionInterface.get_cookie_samesitecCrL)z�Returns True if the cookie should be partitioned. By default, uses
 120          the value of :data:`SESSION_COOKIE_PARTITIONED`.
 121  
 122          .. versionadded:: 3.1
 123          ZSESSION_COOKIE_PARTITIONEDrMrFrrr�get_cookie_partitioned�s
 124  z'SessionInterface.get_cookie_partitioned�sessionr�datetime | NonecCs|jrt�tj�|jSdS)aA helper method that returns an expiration date for the session
 125          or ``None`` if the session is linked to the browser session.  The
 126          default implementation returns now + the permanent session
 127          lifetime configured on the application.
 128          N)rr�nowr�utc�permanent_session_lifetime�rrDrXrrr�get_expiration_time�sz$SessionInterface.get_expiration_timecCs|jp
 129  |jo
 130  |jdS)a�Used by session backends to determine if a ``Set-Cookie`` header
 131          should be set for this session cookie for this response. If the session
 132          has been modified, the cookie is set. If the session is permanent and
 133          the ``SESSION_REFRESH_EACH_REQUEST`` config is true, the cookie is
 134          always set.
 135  
 136          This check is usually skipped if the session was deleted.
 137  
 138          .. versionadded:: 0.11
 139          ZSESSION_REFRESH_EACH_REQUEST)r!rrNr]rrr�should_set_cookie�s�z"SessionInterface.should_set_cookie�requestr�SessionMixin | NonecC�t��)a�This is called at the beginning of each request, after
 140          pushing the request context, before matching the URL.
 141  
 142          This must return an object which implements a dictionary-like
 143          interface as well as the :class:`SessionMixin` interface.
 144  
 145          This will return ``None`` to indicate that loading failed in
 146          some way that is not immediately an error. The request
 147          context will fall back to using :meth:`make_null_session`
 148          in this case.
 149          ��NotImplementedError)rrDr`rrr�open_sessionszSessionInterface.open_session�responser
 150  rcCrb)z�This is called at the end of each request, after generating
 151          a response, before removing the request context. It is skipped
 152          if :meth:`is_null_session` returns ``True``.
 153          rc)rrDrXrfrrr�save_sessionszSessionInterface.save_sessionN)rDrrr7)rHrIrr)rDrrr.)rDrrrP)rDrrr)rDrrXrrrY)rDrrXrrr)rDrr`rrra�rDrrXrrfr
 154  rr)rrrrr7rEZpickle_basedrGrKrOrQrRrSrUrVrWr^r_rergrrrrrCrs"(
 155  
 156  
 157  	
 158  
 159  
 160  
 161  
 162  
 163  
 164  
 165  
 166  
 167  rC��string�bytesrr/cCs
 168  t�|�S)z�Don't access ``hashlib.sha1`` until runtime. FIPS builds may not include
 169      SHA-1, in which case the import and use as a default would fail before the
 170      developer can configure something else.
 171      )�hashlib�sha1)rjrrr�
 172  _lazy_sha1"rTrnc@sFeZdZdZdZee�ZdZe	Z
 173  eZddd	�Z
 174  dd
 175  d�Zddd�ZdS)�SecureCookieSessionInterfacezuThe default session interface that stores sessions in signed cookies
 176      through the :mod:`itsdangerous` module.
 177      zcookie-session�hmacrDrr�URLSafeTimedSerializer | NonecCsH|jsdS|jg}|jd}r|�|�t||j|j|j|jd�d�S)NZSECRET_KEY_FALLBACKS)�key_derivation�
 178  digest_method)�salt�
 179  serializerZ
 180  signer_kwargs)Z
 181  secret_keyrN�extendrrtrurrrs)rrD�keysZ	fallbacksrrr�get_signing_serializer=s
 182  ��z3SecureCookieSessionInterface.get_signing_serializerr`r�SecureCookieSession | NonecCsx|�|�}|durdS|j�|�|��}|s|��St|j���}z
 183  |j||d�}|�|�WSt	y;|��YSw)N)�max_age)
 184  rx�cookiesrrO�
 185  session_class�intr\�
 186  total_seconds�loadsr)rrDr`�s�valrz�datarrrrePs
 187  �z)SecureCookieSessionInterface.open_sessionrXrrfr
 188  rc
 189  Cs�|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}	|�|�}
 190  |jr,|j�	d�|sE|j
 191  rC|j||||||	|
 192  d�|j�	d�dS|�||�sMdS|�
 193  ||�}|�|��t|��}|j||||
 194  |||||	d�	|j�	d�dS)N�Cookie)�domain�path�secure�partitioned�samesite�httponly)�expiresr�r�r�r�r�r�)rOrQrRrUrWrVrSr"�vary�addr!Z
 195  delete_cookier_r^rx�dumps�dict�
 196  set_cookie)
 197  rrDrXrf�namer�r�r�r�r�r�r�r�rrrrg^sL
 198  
 199  
 200  
 201  
 202  
 203  
 204  �	�z)SecureCookieSessionInterface.save_sessionN)rDrrrq)rDrr`rrryrh)rrrrrt�staticmethodrnrsrr�session_json_serializerrur#r|rxrergrrrrro*s
 205  
 206  ro)ri)rjrkrr/)#�
 207  __future__r�collections.abc�abc�crl�typing�trrrZitsdangerousrrZwerkzeug.datastructuresrZjson.tagr
 208  �
 209  TYPE_CHECKINGZtyping_extensions�terDrZwrappersrr
 210  r.�Anyrr#r7rCr�rnrorrrr�<module>s0-.