• File: session.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/beaker/__pycache__/session.cpython-37.pyc
  • Date Modified: 12/01/2019 7:12 PM
  • File size: 26.34 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

Rd];@spddlmZmZmZmZmZmZmZddlZddl	Z	ddl
m
Z
mZddlm
ZmZmZmZmZmZddlmZmZddlmZddlmZmZdd	lmZd
ZdZ dd
dgZ!Gddde"Z#e#Z$yddl%Z%ddZ&WnBe'k
rddl(Z(e)edrej*Z*nddZ*ddZ&YnXGdddeZ+Gddde,Z-Gdd
d
e-Z.Gddde.Z/Gddde"Z0dS))PY2picklehttp_cookiesunicode_text	b64encode	b64decodestring_typeN)datetime	timedelta)hmac	hmac_sha1sha1get_nonce_sizeDEFAULT_NONCE_BITSget_crypto_module)cryptoutil)clsmap)BeakerExceptionInvalidCryptoBackendError)SimpleCookie)
NJanFebMarAprMayJunJulAugSepOctNovDec)MonTueWedThuFriSatSunSignedCookieSessionInvalidSignaturec@s eZdZdZddZddZdS)_InvalidSignatureTypezBReturned from SignedCookie when the value's signature was invalid.cCsdS)NF)selfr/r/?/opt/alt/python37/lib/python3.7/site-packages/beaker/session.py__nonzero__sz!_InvalidSignatureType.__nonzero__cCsdS)NFr/)r0r/r/r1__bool__sz_InvalidSignatureType.__bool__N)__name__
__module____qualname____doc__r2r3r/r/r/r1r.sr.cCs
tjS)N)uuidZuuid4hexr/r/r/r1_session_id$sr:getpidcCsdS)Nr/r/r/r/r1r;+scCsdttittf}tsVtt|d}t	|
dd
dddStt|}|
dd	
d
ddSdS)
Nz%f%s%f%sascii+-/_=+-/_=)timeidrandomr;rrrencodedigeststrreplacerstrip)Zid_strZraw_idr/r/r1r:.s
c@s*eZdZdZd	ddZddZddZdS)
r+z7Extends python cookie to give digital signature supportNcCs|d|_tj||dS)NzUTF-8)rKsecretrZ
BaseCookie__init__)r0rPinputr/r/r1rQAszSignedCookie.__init__cCs|d}|sd|fSt|j|dddt}d}|dd}t|t|kr`t|fSx"t	||D]\}}|||k7}qlW|rt|fS|dd|fSdS)N"(zutf-8r	)
stripHMACnewrPrKSHA1	hexdigestlenr-zip)r0valsigZinvalid_bitsZ	input_sigabr/r/r1value_decodeEs
"zSignedCookie.value_decodecCs.t|j|dt}t|d||ffS)Nzutf-8z%s%s)rVrWrPrKrXrYrM)r0r\r]r/r/r1value_encodeZszSignedCookie.value_encode)N)r4r5r6r7rQr`rar/r/r/r1r+?s
cs*eZdZdZdddZfddZZS)	_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.
    NrEcCs||d|_dS)N)_domain_path)_config)r0
cookie_domaincookie_pathr/r/r1rQgsz_ConfigurableSession.__init__cstt|||jdS)z5Clears Session data. Preserves session configuration.N)superrbclearupdatere)r0)	__class__r/r1rimsz_ConfigurableSession.clear)NrE)r4r5r6r7rQri
__classcell__r/r/)rkr1rb_s
rbc@s*eZdZdZddddddddddddddddddedd	fd
dZdd
ZddZd<ddZe	ddZ
ddZd=ddZddZ
d>ddZeddZddZd d!ZeeeZd"d#Zd$d%ZeeeZd?d&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd@d2d3Zd4d5Zd6d7Zd8d9Z 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.idrErdefaultLaxc
Ks$tj|||d||s0|r(d|_q6d|_n||_|pBt|j|_||_||_||_||_	|rn|	snt
d||_|jdk	r|jd|jd<|	|_||_
|
|_||
d|_||_||_||_||_||_||_t||_t||_||_i|_||_|j
r|dd	}|rPyt||d
|_ Wn&t!j"k
rLt|dd
|_ YnXnt#|d
|_ |js|j	|j kr|j |j	j$}|t%krd}||_|jdk|_&|j&r|'t((|d<|d<nZy|)WnLt*k
r}z,|jrt+,d
|j|f|-nWdd}~XYnXdS)N)rfrgfileZmemoryz#timeout requires save_accessed_timextimeoutFcookier<)rR_accessed_time_creation_timezjInvalidating corrupt session %s; error was: %s.  Set invalidate_corrupt=False to propagate this exception.).rbrQritypernamespace_classnamespace_argsrequestdata_dirkeyrrq
save_atimeuse_cookiescookie_expires_set_serializerwas_invalidatedrPsecurehttponlysamesiteencrypt_keyvalidate_keyrencrypt_nonce_sizer
crypto_modulerI
accessed_dictinvalidate_corruptgetr+rrrCookieErrorrvaluer-is_new
_create_idrHload	Exceptionrwarn
invalidate)r0rxrIrr|ruryrzrqsave_accessed_timer}rfrgdata_serializerrPrrvrrrencrypt_nonce_bitscrypto_typerrwcookieheadercookie_dataer/r/r1rQs	





zSession.__init__cCsV||_|jdkrt|_n6|jdkr2t|_n t|jtrLtd|n||_dS)NZjsonrz%Invalid value for data_serializer: %s)rrZJsonSerializer
serializerZPickleSerializer
isinstancerr)r0rr/r/r1r~s

zSession._set_serializercCs||kS)Nr/)r0namer/r/r1has_keyszSession.has_keycCs||j|j|j<|jr&|j|j|jd<|jr<d|j|jd<|jrT|j|j|jd<||j|j|jd<||dS)NdomainTrrpath)	rIrrrzrrr_set_cookie_http_onlyr_set_cookie_expires)r0expiresr/r/r1_set_cookie_valuesszSession._set_cookie_valuescCs0|}td|}|t|dt|dfS)Nz%%s, %d-%%s-%Y %H:%M:%S GMTr)	timetuplerHstrftimeweekdaysmonths)vrr/r/r1serialize_cookie_date"szSession.serialize_cookie_datecCs|dkr|j}|dkr"td}nBt|tr:t|}n*t|trJ|}n|dk	rdtdt|j||_|jr||j	|jkr|j
|j|j	<|dkrd|j|j	d<dS|||j|j	d<|S)NFiTz'Invalid argument for cookie_expires: %sr<r)r}r

fromtimestamprrutcnow
ValueErrorreprrrrzrIr)r0rZexpires_dater/r/r1r)s&

zSession._set_cookie_expirescCsH||j|jjdd}t|ts0|d}||jd<||jd<dS)Nr<)headerlatin1
cookie_out
set_cookie)rrrrzoutputrrMrKrx)r0rrr/r/r1_update_cookie_out?s


zSession._update_cookie_outc
Cs\y|jrd|j|jd<Wn<tjk
rV}zdt|kr<tdWdd}~XYnXdS)NTrzInvalid Attribute httponlyz'Python 2.6+ is required to use httponly)rrrrzrrrMrr)r0rr/r/r1rGszSession._set_cookie_http_onlycCs6t|_|rd|_d|_|jr2|dk}|j|ddS)NTF)r)r:rIr
last_accessedr|r)r0set_newZscr/r/r1rPszSession._create_idcCs|dS)Nrtr/)r0r/r/r1createdZszSession.createdcCs||d<|dS)Nrc)r)r0rr/r/r1_set_domain^szSession._set_domaincCs|dS)Nrcr/)r0r/r/r1_get_domainbszSession._get_domaincCs||d<|dS)Nrd)r)r0rr/r/r1	_set_pathgszSession._set_pathcCs|ddS)NrdrE)r)r0r/r/r1	_get_pathkszSession._get_pathcCs|p
|}|jrr|j\}}tt|d|}t|j|j|d|j	
}|j|}|t|j	
||S|j|}t|SdS)z0Serialize, encipher, and base64 the session dictNr)copyrrrosurandomrgenerateCryptoKeysrrgetKeyLengthrdumpsZ
aesEncrypt)r0session_dataZ	nonce_lennonce_b64lennoncerdatar/r/r1
_encrypt_dataps
zSession._encrypt_datacCsn|jrZ|j\}}|d|}t|j|j|d|j}t||d}|j||}nt|}|j	
|S)zIBase64, decipher, then un-serialize the data for the session
        dictNr)rrrrrrrrZ
aesDecryptrloads)r0r__rrrpayloadrr/r/r1
_decrypt_datas
zSession._decrypt_datacCs0d|jd<ttd}|||dS)NTrim)rxr
rrrr)r0rr/r/r1_delete_cookies

zSession._delete_cookiecCs|jr||dS)zXDeletes the session from the persistent storage, and sends
        an expired cookie outN)r|rri)r0r/r/r1deleteszSession.deletecCs"|d|_||dS)zWInvalidates this session, creates a new session id, returns
        to the is_new stateTN)rirrr)r0r/r/r1rszSession.invalidatec	Cs`|j|jf|jdd|j|_t}|jr8d|jd<|jd}z|	y>|jd}|dk	rt|j
rt||}|dkr||d}d|_Wn(t
tfk
r||d}d|_YnX|dkst|dkr||d}d|_|jdk	r||d	|jkrd}n@|jsd	|krd|_n
|d	|_||d	<||||_Wd|jX|r\|dS)
z8Loads the data from this session from persistent storageF)rydigest_filenamesTrsessionN)rtrsr	rs)rvrIryrw	namespacerHr|rxZacquire_read_lockrirrrKeyError	TypeErrorrZrqrrjrrZrelease_read_lockr)r0nowZ	timed_outrr/r/r1rsN








zSession.loadcCs|r|js|jsdSt|dr,|jj|jkrL|j|jf|jdd|j|_|jjddzV|rpt	|j
}nt	|}|jr|
|}|sd|jkr|jd=n
||jd<Wd|jX|jr|jrd|jd<dS)	zSaves the data for this session to persistent storage

        If accessed_only is True, then only the original data loaded
        at the beginning of the request will be saved, with the updated
        last accessed time.

        NrF)ryrT)rNrr)rr{hasattrrrIrvryrwacquire_write_lockdictritemsrrrelease_write_lockr|rx)r0
accessed_onlyrr/r/r1saves*


zSession.savecCs|||jdS)zURevert the session to its original state from its first
        access in the requestN)rirjr)r0r/r/r1revertszSession.revertcCs|jdddS)z
            creates a new session id, retains all session data

            Its a good security practice to regnerate the id after a client
            elevates privileges.

        F)rN)r)r0r/r/r1
regenerate_idszSession.regenerate_idcCs|jdS)a@Locks this session against other processes/threads.  This is
        automatic when load/save is called.

        ***use with caution*** and always with a corresponding 'unlock'
        inside a "finally:" block, as a stray lock typically cannot be
        unlocked without shutting down the whole application.

        N)rr)r0r/r/r1lock"s	zSession.lockcCs|jdS)a$Unlocks this session against other processes/threads.  This
        is automatic when load/save is called.

        ***use with caution*** and always within a "finally:" block, as
        a stray lock typically cannot be unlocked without shutting down
        the whole application.

        N)rr)r0r/r/r1unlock-s	zSession.unlock)N)T)T)N)F)"r4r5r6r7rrQr~rrstaticmethodrrrrrpropertyrrrrrrrrrrrrrrrrrrr/r/r/r1r,ssF+a


	




?
*
c@seZdZdZdddddddddddeddd	fd
dZdd
ZeeZddZeeZddZ	ddZ
ee
e	ZddZddZ
ee
eZd"ddZddZddZddZd d!ZdS)#
CookieSessionaPure cookie-based session

    Options recognized when using cookie-based sessions are slightly
    more restricted than general sessions.

    :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.
    :type timeout: int
    :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 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 crypto_type: The crypto module to use.
    :param samesite: SameSite value for the cookie -- should be either 'Lax',
                     'Strict', or None.
    zbeaker.session.idNTrEFrrmrnc
Kstj|||d|t||_|r6|jjs6td||_||_||_	||_
||_||_|	|_
t|
|_d|jd<|
|_||_||_||_||y|d}Wntk
rd}YnX|	dkrtd|r|stdyt|	|d	|_Wn&tjk
rt|	dd	|_YnXt|d
<d|_|j|jkr|j|jjdk	rd|_y4|j|jj}|tkrptd|| |WnLt!k
r}z,|jrt"#d
|j$|f|%nWdd}~XYnX|j	dk	rt&&}|'d|}|||j	kr||(|_)|*dS)N)rfrgzJNo AES library is installed, can't generate encrypted cookie-only Session.Frrrr<z2No validate_key specified for Cookie only Session.z#timeout requires save_accessed_time)rR_idTzInvalid signaturezjInvalidating corrupt session %s; error was: %s.  Set invalidate_corrupt=False to propagate this exception.rs)+rbrQrirrZhas_aesrrxrzrqr{r}rrrrrrrrr~rrr+rrrrr:rrr-rjrrrrrIrrHrrr_create_cookie)r0rxrzrqrr}rfrgrrrrrrrrrkwargsrrrrZlast_accessed_timer/r/r1rQ]sz





"


zCookieSession.__init__cCs|dS)Nrtr/)r0r/r/r1rszCookieSession.createdcCs|dS)Nrr/)r0r/r/r1rIszCookieSession.idcCs||d<dS)Nrcr/)r0rr/r/r1rszCookieSession._set_domaincCs|dS)Nrcr/)r0r/r/r1rszCookieSession._get_domaincCs||d<dS)Nrdr/)r0rr/r/r1rszCookieSession._set_pathcCs|dS)Nrdr/)r0r/r/r1rszCookieSession._get_pathcCs8|r|js|jsdS|r,|||j|dS)z5Saves the data for this session to persistent storageN)rr{rirjrr)r0rr/r/r1rszCookieSession.savecCs|dddS)z7Delete the 'expires' attribute on this Session, if any._expiresN)pop)r0r/r/r1expireszCookieSession.expirecCs2d|krt|d<d|kr&t|d<t|d<|}t|dkrNtd||j|j<d|krl|d}nd}||}|dk	r||d<|jr|j|j|jd<|j	rd|j|jd	<|j
r|j
|j|jd
<||dd|j|jd
<|j|jj
dd}t|ts|d}||jd<d|jd<dS)Nrtrrsiz!Cookie value is too long to storerrTrrrdrErr<)rrrr)rHr:rrZrrrrzrrrrrrrrrMrKrx)r0r\rrr/r/r1rs8




zCookieSession._create_cookiecCs||dS)z(Delete the cookie, and clear the sessionN)rri)r0r/r/r1rszCookieSession.deletecCs|t|d<dS)z*Clear the contents and start a new sessionrN)rir:)r0r/r/r1rszCookieSession.invalidate)F)r4r5r6r7rrQrrrIrrrrrrrrrrrr/r/r/r1r9s,#R


	%rc@seZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZddZ
ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&S)'
SessionObjecta+Session proxy/lazy creator

    This object proxies access to the actual session object, so that in
    the case that the session hasn't been used before, it will be
    setup. This avoid creating and loading the session from persistent
    storage unless its actually used during the request.

    cKs,||jd<||jd<d|jd<i|jd<dS)N_params_environ_sess_headers)__dict__)r0environparamsr/r/r1rQs


zSessionObject.__init__cCs|jddkr|jd}|jd}ddi|jd<}|d|d<|d	d}|dkrp|d
dkrjt}qt}nt|tstd|||f||jd<|jdS)z'Lazy initial creation of session objectrNrrrrZHTTP_COOKIErrZ
session_classruzNot a Session: )rrrr,
issubclassAssertionError)r0rrreqZsession_clsr/r/r1_sessions


zSessionObject._sessioncCst||S)N)getattrr)r0attrr/r/r1__getattr__-szSessionObject.__getattr__cCst|||dS)N)setattrr)r0rrr/r/r1__setattr__0szSessionObject.__setattr__cCs||dS)N)r__delattr__)r0rr/r/r1r3szSessionObject.__delattr__cCs||S)N)r)r0rzr/r/r1__getitem__6szSessionObject.__getitem__cCs|||<dS)N)r)r0rzrr/r/r1__setitem__9szSessionObject.__setitem__cCs||dS)N)r__delitem__)r0rzr/r/r1r<szSessionObject.__delitem__cCs|S)N)r__repr__)r0r/r/r1r?szSessionObject.__repr__cCst|S)z!Only works for proxying to a dict)iterrkeys)r0r/r/r1__iter__BszSessionObject.__iter__cCs||kS)N)r)r0rzr/r/r1__contains__FszSessionObject.__contains__cCs||kS)N)r)r0rzr/r/r1rIszSessionObject.has_keycCs.|jd}tifd|d|}|jr*dS|S)z"Loads a session given a session IDrF)r|rIN)rr,r)r0rIrrr/r/r1	get_by_idLs

zSessionObject.get_by_idcCsd|jd<dS)NT_dirty)r)r0r/r/r1rTszSessionObject.savecCsd|jd<|dS)NTr)rrr)r0r/r/r1rWs
zSessionObject.deletecCsp|jddr|nN|jdddrX|rF|ql|jddn|rl|dS)aPersist the session to the storage

        Always saves the whole session if save() or delete() have been called.
        If they haven't:

        - If autosave is set to true, saves the the entire session regardless.
        - If save_accessed_time is set to true or unset, only saves the updated
          access time.
        - If save_accessed_time is set to false, doesn't save anything.

        rautorT)rN)rrrrdirty)r0r/r/r1persist[szSessionObject.persistcCs|jddS)z3Returns True if save() or delete() have been calledrF)rr)r0r/r/r1rrszSessionObject.dirtycCs|jddk	S)z4Returns whether or not the session has been accessedrN)r)r0r/r/r1accessedvszSessionObject.accessedN)r4r5r6r7rQrrrrrrrrrrrrrrrrrr/r/r/r1rs&r)1_compatrrrrrrrrrHr
rZ
beaker.cryptorrVr
rXrrrrbeakerrrZbeaker.cacherZbeaker.exceptionsrrZ
beaker.cookierrr__all__objectr.r-r8r:ImportErrorrJrr;r+rrbr,rrr/r/r/r1<module>s>$ 
	 IS