B
Rd]; @ sp d dl mZmZmZmZmZmZmZ ddlZddl Z ddl
m
Z
mZ ddlm
ZmZmZmZmZmZ ddlmZmZ ddlmZ ddlmZmZ dd lmZ d
ZdZ dd
dgZ!G dd de"Z#e# Z$yddl%Z%dd Z&W nB e'k
r ddl(Z(e)edrej*Z*ndd Z*dd Z&Y nX G dd deZ+G dd de,Z-G dd
d
e-Z.G dd de.Z/G dd de"Z0dS ) )PY2picklehttp_cookiesunicode_text b64encode b64decodestring_type N)datetime timedelta)hmac hmac_sha1sha1get_nonce_sizeDEFAULT_NONCE_BITSget_crypto_module)cryptoutil)clsmap)BeakerExceptionInvalidCryptoBackendError)SimpleCookie)
NJanFebMarAprMayJunJulAugSepOctNovDec)MonTueWedThuFriSatSunSignedCookieSessionInvalidSignaturec @ s e Zd ZdZdd Zdd ZdS )_InvalidSignatureTypezBReturned from SignedCookie when the value's signature was invalid.c C s dS )NF )selfr/ r/ ?/opt/alt/python37/lib/python3.7/site-packages/beaker/session.py__nonzero__ s z!_InvalidSignatureType.__nonzero__c C s dS )NFr/ )r0 r/ r/ r1 __bool__ s z_InvalidSignatureType.__bool__N)__name__
__module____qualname____doc__r2 r3 r/ r/ r/ r1 r. s r. c C s
t jS )N)uuidZuuid4hexr/ r/ r/ r1 _session_id$ s r: getpidc C s dS )N r/ r/ r/ r/ r1 r; + s c C s dt ti t t f } tsVtt| d }t |
dd
dddS tt| }|
dd
d
ddS d S )
Nz%f%s%f%sascii + - / _ =+-/_=)timeidrandomr; r r r encodedigeststrreplacerstrip)Zid_strZraw_idr/ r/ r1 r: . s
c @ s* e Zd ZdZd ddZdd Zdd ZdS )
r+ z7Extends python cookie to give digital signature supportNc C s | d| _tj| | d S )NzUTF-8)rK secretr Z
BaseCookie__init__)r0 rP inputr/ r/ r1 rQ A s zSignedCookie.__init__c C s | d}|sd |fS t| j|dd dt }d}|d d }t|t|kr`t|fS x"t ||D ]\}}|||k7 }qlW |rt|fS |dd |fS d S )N"( zutf-8r )
stripHMACnewrP rK SHA1 hexdigestlenr- zip)r0 valsigZinvalid_bitsZ input_sigabr/ r/ r1 value_decodeE s
"zSignedCookie.value_decodec C s. t | j|dt }t|d||f fS )Nzutf-8z%s%s)rV rW rP rK rX rY rM )r0 r\ r] r/ r/ r1 value_encodeZ s zSignedCookie.value_encode)N)r4 r5 r6 r7 rQ r` ra r/ r/ r/ r1 r+ ? s
c s* e Zd ZdZdddZ fddZ ZS ) _ConfigurableSessionzProvides support for configurable Session objects.
Provides a way to ensure some properties of sessions
are always available with pre-configured values
when they are not available in the session cookie itself.
NrE c C s ||d| _ d S )N)_domain_path)_config)r0
cookie_domaincookie_pathr/ r/ r1 rQ g s z_ConfigurableSession.__init__c s t t| | | j dS )z5Clears Session data. Preserves session configuration.N)superrb clearupdatere )r0 ) __class__r/ r1 ri m s z_ConfigurableSession.clear)NrE )r4 r5 r6 r7 rQ ri
__classcell__r/ r/ )rk r1 rb _ s
rb c @ s* e Zd ZdZddddddddddddddddddedd fd
dZdd
Zdd Zd<ddZe dd Z
dd Zd=ddZdd Z
d>ddZedd Zdd Zd d! ZeeeZd"d# Zd$d% ZeeeZd?d&d'Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd@d2d3Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!dS )Ar, an
Session object that uses container package for storage.
:param invalidate_corrupt: How to handle corrupt data when loading. When
set to True, then corrupt data will be silently
invalidated and a new session created,
otherwise invalid data will cause an exception.
:type invalidate_corrupt: bool
:param use_cookies: Whether or not cookies should be created. When set to
False, it is assumed the user will handle storing the
session on their own.
:type use_cookies: bool
:param type: What data backend type should be used to store the underlying
session data
:param key: The name the cookie should be set to.
:param timeout: How long session data is considered valid. This is used
regardless of the cookie being present or not to determine
whether session data is still valid. Can be set to None to
disable session time out.
:type timeout: int or None
:param save_accessed_time: Whether beaker should save the session's access
time (True) or only modification time (False).
Defaults to True.
:param cookie_expires: Expiration date for cookie
:param cookie_domain: Domain to use for the cookie.
:param cookie_path: Path to use for the cookie.
:param data_serializer: If ``"json"`` or ``"pickle"`` should be used
to serialize data. Can also be an object with
``loads` and ``dumps`` methods. By default
``"pickle"`` is used.
:param secure: Whether or not the cookie should only be sent over SSL.
:param httponly: Whether or not the cookie should only be accessible by
the browser not by JavaScript.
:param encrypt_key: The key to use for the local session encryption, if not
provided the session will not be encrypted.
:param validate_key: The key used to sign the local encrypted session
:param encrypt_nonce_bits: Number of bits used to generate nonce for encryption key salt.
For security reason this is 128bits be default. If you want
to keep backward compatibility with sessions generated before 1.8.0
set this to 48.
:param crypto_type: encryption module to use
:param samesite: SameSite value for the cookie -- should be either 'Lax',
'Strict', or None.
NFTzbeaker.session.idrE r defaultLaxc
K s$ t j| ||d | |s0|r(d| _q6d| _n|| _|pBt| j | _|| _|| _|| _|| _ |rn| snt
d|| _| jd k r| jd | jd<