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

aNG,@s&dZddlmZddlZddlZddlZddlZddlZddlZyddl	Z	Wne
k
rhddlZ	YnXyddlm
Z
Wn e
k
rddl
m
Z
YnXddlmZddlmZGdddeZGd	d
d
eZdadaejdd
aGdddeZGdddeZeZeeeeefddZdS)a
Creates a session object in your WSGI environment.

Use like:

..code-block:: Python

    environ['paste.session.factory']()

This will return a dictionary.  The contents of this dictionary will
be saved to disk when the request is completed.  The session will be
created when you first fetch the session dictionary, and a cookie will
be sent in that case.  There's current no way to use sessions without
cookies, and there's no way to delete a session except to clear its
data.

@@: This doesn't do any locking, and may cause problems when a single
session is accessed concurrently.  Also, it loads and saves the
session for each request, with no caching.  Also, sessions aren't
expired.
)SimpleCookieN)md5)wsgilib)requestc@seZdZdddZddZdS)SessionMiddlewareNcKs||_||_dS)N)application
factory_kw)selfrglobal_confrr>/opt/alt/python37/lib/python3.7/site-packages/paste/session.py__init__/szSessionMiddleware.__init__csbt|f|j|d<gdfdd	}|||}fdd}fdd}t|||S)	Nzpaste.session.factorycs:js ||gdd<||S||||S)N)createdappendset_cookie_header)statusheadersexc_info)remember_headerssession_factorystart_responserrsession_start_response8s

z:SessionMiddleware.__call__.<locals>.session_start_responsecs@jr<r<\}}|td}|||j|dfdS)NzLYou cannot get the session after content from the app_iter has been returned)rrr
ValueError	__class__)rrexc)rrrrrstart@s
z)SessionMiddleware.__call__.<locals>.startcsjrdS)N)usedcloser)rrrrIsz)SessionMiddleware.__call__.<locals>.close)N)SessionFactoryrrrZadd_start_close)r	environrrZapp_iterrrr)rrrr__call__3s	zSessionMiddleware.__call__)N)__name__
__module____qualname__r
r rrrrr-s
rc@sHeZdZdddZddZdd	Zd
dZddd
ZddZddZ	dS)r_SID_NcKs8d|_d|_||_||_d|_|p$t|_||_||_dS)NF)	rrrcookie_namesessionFileSession
session_classsession_class_kw
expiration)r	rr&r)session_expirationr*rrrr
Rs
zSessionFactory.__init__cCsd|_|jdk	r|jSt|j}d}||jrx||jj|_	y|j
|j	fddi|j}Wntk
rvYnX|dkrd|_
||_	|j
|j	fddi|j}|||_|S)NTcreateF)rr'datarget_cookiesrhas_keyr&valuesidr)r*KeyErrorrmake_sidclean_up)r	cookiesr'rrrr as(



zSessionFactory.__call__cCs.|jdk	rdSt|j}||jr*dSdS)NTF)r'rr/rr0r&)r	r6rrrhas_sessionxs
zSessionFactory.has_sessioncCs2dddttddDd|S)NcSsg|]}d|qS)z%02dr).0xrrr
<listcomp>sz+SessionFactory.make_sid.<locals>.<listcomp>-)jointime	localtime	unique_id)r	rrrr4szSessionFactory.make_sidc	Csttg}ttdr(|t|dk	r>|t|tt|}y|	St
k
rg}x"|D]}|dt|qpWd
|SXdS)a
        Generates an opaque, identifier string that is practically
        guaranteed to be unique.  If an object is passed, then its
        id() is incorporated into the generation.  Relies on md5 and
        returns a 32 character long string.
        timesNz%02xr8)r?randomhasattrosrrBidrstr	hexdigestAttributeErrordigestordr>)r	Z
for_objectrZmd5_hashrHcharrrrrAs
zSessionFactory.unique_idcCsjt}|j||j<d||jd<tt|jd}td|||jd<t|dd\}}||fS)N/path<z%a, %d-%b-%Y %H:%M:%S GMTZexpiresz: )	rr2r&r?gmtimer+strftimerGsplit)r	cZgmt_expiration_timenamer1rrrrsz SessionFactory.set_cookie_headercCs|jdk	r|jdS)N)r'r)r	rrrrs
zSessionFactory.close)r$Nr%)N)
r!r"r#r
r r7r4rArrrrrrrOs


rFi)secondsc@sReZdZdeddfddZddZdd	Zd
dZdd
Z	ddZ
ddZdS)r(FNi@cCsZ|rt|trt|d}||_|s&t||_||_|sJtj	|
sJtd|_||_dS)N)
isinstance
basestringintchmodr3session_file_pathr2rErOexistsfilename_datar+)r	r2r-r]r\r+rrrr
s
zFileSession.__init__cCstj|j|jS)N)rErOr>r]r2)r	rrrr_szFileSession.filenamecCsP|jdk	r|jStj|rDt|d}t||_|ni|_|jS)Nrb)	r`rErOr^r_opencPickleloadr)r	frrrr.s

zFileSession.datacCsp|jdk	rl|}tj|}|js4|rlt|n8t|d}t|j||	|sl|j
rlt
||j
dS)Nwb)r`r_rErOr^unlinkrbrcdumprr\)r	r_r^rerrrrs


zFileSession.closecCsfzZtj|jdd}tj}x8t|jD](\}}}x|D]}|j|||dq<Wq,WWddaXdS)NrP)rW)exp_timenowF)	datetime	timedeltar+rjrEwalkr]_clean_up_filecleaning_up)r	rirjrootdirsfilesrerrr	_clean_ups

zFileSession._clean_upcCs|d}t|dkrdS|d}y`tt|ddt|ddt|ddt|ddt|ddt|dd	}Wntk
rdSX|||krttj|j	|dS)
Nr=rr<rX
)
rTlenrkr[rrEremoverOr>r])r	rerirjtZ	sess_timerrrrns 
zFileSession._clean_up_filecCs`tj}trdStr"tt|kr\ts\day|atj|jd}|WndaYnXdS)NT)targetF)	rkrjrolast_cleanup
cleanup_cycle	threadingThreadrsr)r	rjr{rrrr5s
zFileSession.clean_up)r!r"r#tempfile
gettempdirr
r_r.rrsrnr5rrrrr(s
r(c@seZdZddZdS)
_NoDefaultcCsdS)Nz<dynamic default>r)r	rrr__repr__sz_NoDefault.__repr__N)r!r"r#rrrrrrsrcCs|tkr|dd}t|}|tkr0|dd}t|}|tkrL|dd}|tkr`|dd}|tkrt|d	d
}t||||||dS)a
    Adds a middleware that handles sessions for your applications.
    The session is a peristent dictionary.  To get this dictionary
    in your application, use ``environ['paste.session.factory']()``
    which returns this persistent dictionary.

    Configuration:

      session_expiration:
          The time each session lives, in minutes.  This controls
          the cookie expiration.  Default 12 hours.

      expiration:
          The time each session lives on disk.  Old sessions are
          culled from disk based on this.  Default 48 hours.

      cookie_name:
          The cookie name used to track the session.  Use different
          names to avoid session clashes.

      session_file_path:
          Sessions are put in this location, default /tmp.

      chmod:
          The octal chmod you want to apply to new sessions (e.g., 660
          to make the sessions group readable/writable)

    Each of these also takes from the global configuration.  cookie_name
    and chmod take from session_cookie_name and session_chmod
    r,ir+i@Zsession_cookie_namer$r]z/tmpZ
session_chmodN)r,r+r&r]r\)	NoDefaultgetr[r)Zappr
r,r+r&r]r\rrrmake_session_middlewares %r)__doc__ZCookierr?rCrErkrrrcImportErrorpicklehashlibrpasterrobjectrrr}rorlr~r(rrrrrrr<module>s<"]h