ó aòNc@sdZddlmZddlZddlZddlZddlZddlZddlZyddl Z Wne k rddl Z nXyddl m Z Wn!e k rÅddl m Z nXddlmZddlmZdefd„ƒYZd efd „ƒYZdaeaejd dƒadefd„ƒYZdefd„ƒYZeƒZeeeeed„ZdS(s² 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. iÿÿÿÿ(t SimpleCookieN(tmd5(twsgilib(trequesttSessionMiddlewarecBseZdd„Zd„ZRS(cKs||_||_dS(N(t applicationt factory_kw(tselfRt global_confR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyt__init__/s csƒt||j‰ˆ|d/opt/alt/python27/lib/python2.7/site-packages/paste/session.pytsession_start_response8s    cs]ˆjrYˆrYˆ\}}|jˆjƒƒtdƒ}ˆ|||j|dfƒndS(NsLYou cannot get the session after content from the app_iter has been returned(R R R t ValueErrort __class__tNone(R Rtexc(RRR(s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pytstart@s   csˆjrˆjƒndS(N(tusedtclose((R(s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyRIs (tSessionFactoryRRRRtadd_start_close(RtenvironRRtapp_iterRR((RRRs>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyt__call__3s  N(t__name__t __module__RR R(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR-s RcBsSeZdd d d„Zd„Zd„Zd„Zd d„Zd„Zd „Z RS( t_SID_i<i cKsRt|_t|_||_||_d|_|p6t|_||_ ||_ dS(N( tFalseR RRt cookie_nameRtsessiont FileSessiont session_classtsession_class_kwt expiration(RRR$R'tsession_expirationR(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR Rs      cCsýt|_|jdk r%|jjƒStj|jƒ}d}|j|j ƒr›||j j |_ y"|j |j dt |j}Wq›tk r—q›Xn|dkràt|_|jƒ|_ |j |j dt|j}n|jƒ||_|jƒS(Ntcreate(tTrueRR%RtdataRt get_cookiesRthas_keyR$tvaluetsidR'R#R(tKeyErrorR tmake_sidtclean_up(RtcookiesR%((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyRas(       cCs?|jdk rtStj|jƒ}|j|jƒr;tStS(N( R%RR,RR.RR/R$R#(RR5((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyt has_sessionxs cCsEdjgtjtjƒƒd D]}d|^q ƒd|jƒS(Ntis%02dt-(tjointtimet localtimet unique_id(Rtx((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR3€scCsÕtjƒtjƒg}ttdƒr=|jtjƒƒn|dk r_|jt|ƒƒntt |ƒƒ}y|j ƒSWnOt k rÐg}x+|j ƒD]}|jdt |ƒƒq¢Wdj|ƒSXdS(s 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. ttimess%02xR7N(R:trandomthasattrtosR R>RtidRtstrt hexdigesttAttributeErrortdigesttordR9(Rt for_objecttrtmd5_hashRDtchar((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR<…s  cCstƒ}|j||j/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR œs  cCs#|jdk r|jjƒndS(N(R%RR(R((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR§sNiÐ( R R!RR RR6R3R<R R(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyROs     tsecondsii<R&cBsYeZeejƒddd„Zd„Zd„Zd„Z d„Z d„Z d„Z RS( i@ cCs‘|r't|tƒr't|dƒ}n||_|s?t‚n||_||_|s{tjj |j ƒƒs{t‚q{nd|_ ||_ dS(Ni(t isinstancet basestringtinttchmodR2tsession_file_pathR1RARMtexiststfilenameRt_dataR)(RR1R+RZRYR)((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR ²s      cCstjj|j|jƒS(N(RARMR9RZR1(R((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR\ÆscCsr|jdk r|jStjj|jƒƒrbt|jƒdƒ}tj|ƒ|_|j ƒn i|_|jS(Ntrb( R]RRARMR[R\topentcPickletloadR(Rtf((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR-És  cCs¨|jdk r¤|jƒ}tjj|ƒ}|jsO|r¡tj|ƒq¡q¤t|dƒ}tj |j|ƒ|j ƒ| r¤|j r¤tj ||j ƒq¤ndS(Ntwb( R]RR\RARMR[tunlinkR_R`tdumpRRY(RR\R[Rb((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyRÔs   cCsŠz|tjd|jdƒ}tjjƒ}xMtj|jƒD]9\}}}x'|D]}|j|d|d|ƒqTWq>WWdta XdS(NRUi<texp_timetnow( tdatetimet timedeltaR)RgRAtwalkRZt_clean_up_fileR#t cleaning_up(RRfRgtroottdirstfilesRb((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyt _clean_upâs" %c Csê|jdƒ}t|ƒdkr%dS|d}yptjt|dd!ƒt|dd!ƒt|dd!ƒt|dd!ƒt|dd!ƒt|dd !ƒƒ}Wntk r³dSX|||krætjtjj|j |ƒƒndS( NR8iiiiii i i( RQtlenRhRXRRAtremoveRMR9RZ(RRbRfRgttt sess_time((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyRkïs   cCs‚tjjƒ}trdSt s0tt|kr~ts~tay)|atjd|jƒ}|j ƒWq{t a‚q{Xq~ndS(Nttarget( RhRgRlt last_cleanupt cleanup_cycleR,t threadingtThreadRpRR#(RRgRs((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR4sN( R R!R#ttempfilet gettempdirRR R\R-RRpRkR4(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR&°s     t _NoDefaultcBseZd„ZRS(cCsdS(Ns((R((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyt__repr__s(R R!R}(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyR|sc Cså|tkr!|jdd ƒ}nt|ƒ}|tkrN|jddƒ}nt|ƒ}|tkr{|jddƒ}n|tkrœ|jdd ƒ}n|tkr½|jd dƒ}nt|d|d|d |d|d |ƒS(s 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*i<i R)i0tsession_cookie_nameR"RZs/tmpt session_chmodR$RYiÐi@ N(t NoDefaulttgetRXRR(tappRR*R)R$RZRY((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pytmake_session_middlewares %         i„(t__doc__tCookieRR:R?RARhRxRzR`t ImportErrortpicklethashlibRtpasteRRtobjectRRRRvR#RlRiRwR&R|R€Rƒ(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/session.pyts<        "]h