mò Ä%ÜGc@sGdklZdkZdkZdkZdkZdkZydkZeZWndkZnXdZdefd„ƒYZ dZ dfd„ƒYZ d„Z d fd „ƒYZ d e fd „ƒYZd dd„Zde fd„ƒYZd„Zdefd„ƒYZdefd„ƒYZdd„Zde fd„ƒYZdS((s spyceModuleNs‰Session module provides support for session management - the storage of variables on the server between requests under some short identifier. A user must call setHandler() to determine how the sessions are stored, before using the other session methods. The get(), set() and delete() methods provide access to the session information. The autoSession() method will turn on the automatic session management (loading and saving the session). When automatic session management is turned on the session information, identifier, parameter name and browser method are stored in the variables called auto, autoID, autoName and autoMethod, respectively.tsession1cBsttZd„Zdd„Zdd„Zd„Zd„Zdd„Zdd„Z d„Z d d d „Z d „Z RS( NcCsR|iiƒ|_dt|iƒjotƒ|i_nd|_|i ƒdS(s(Initialise the session module variables.tsessionN( tselft_apitgetServerObjectt _serverobjecttdirtsessionHandlerRegistryRtNonet_handlert_clearAutoSession(R((t</home/holguin2/public_html/spyce/contrib/modules/session1.pytstart"s  cCst|ioV|i|i|i|iƒ|idjo&|iidƒi|i|iƒq`nt |i i ƒdS(s?Save the session, if automatic session management is turned on.tcookieN( RtautoIDtsettautot autoExpiret autoMethodRt getModuletautoNametsessionCleanupRR(RttheError((R tfinish)s  *cOs‡|o|t|i|f|ƒ}|idƒoO|doD|d}t |ƒt fƒjo |f}nt|i |ƒqƒndS(NR( thandlertapplyRt setHandlertargsRtkwargsthas_keyRttypet autoSession(RRRRRR((R tinit0s  cGsµti|dƒ}t|ƒdjod|d}}n|d \}}|o%|ii |||ii ƒƒ}n t |ƒ}t ||f|ƒ|_|iii|iƒ|S(sSelect a session handler.t:iiiN(tstringtsplitt file_nametlenRtfiletnameRRt loadModulet getFilenameRtevalRtparamsR RRtadd(RR$R+RR&R'((R R8s% cCs$|ip d‚n|ii|ƒS(sRetrieve session information.scall setHandler to initialiseN(RR tgettid(RR.((R R-Bs cCsB|ip d‚n|p|i}|iƒn|ii|ƒS(sDelete session information.scall setHandler to initialiseN(RR R.RR tdelete(RR.((R R/Fs  cCs*|ip d‚n|ii|||ƒS(sSet session information.scall setHandler to initialiseN(RR RtstatetexpireR.(RR0R1R.((R RMs cCs!|ip d‚n|iiƒS(s1Clear all session information in current handler.scall setHandler to initialiseN(RR tclear(R((R R2Qs R t spyceSessioncCs>|ip d‚nti|ƒ}|djo"|iidƒi|ƒ|_ ne|djo"|iidƒi |ƒ|_ n6|djo"|iidƒi |ƒ|_ nd‚||_ ||_ ||_d|_|i o0|i|i ƒ|_|ip d|_ qn|i p|id|iƒ|_ ndS(s%Turn on automatic session management.scall setHandler to initialiseR tposttrequestR-s)runtime error: invalid autosession methodN(RR R"tlowertmethodRRR-R'Rtpost1tget1RRR1RRRR(RR1R7R'((R RUs*  " " "       cCs1d|_d|_d|_d|_d|_dS(N(RRRRRRR(R((R R fs     ( t__name__t __module__R RRR RR-R/RR2RR (((R R!s       i2RcBs2tZdZd„Zd„Zd„Zd„ZRS(s&Registry of all used session handlers.cCs h|_dS(N(Rthandlers(R((R t__init__vscCs||i|iƒ(RR((R tremove|s(R:R;t__doc__R=R,R@RA(((R Rts    cCsxtitƒodSnxY|iƒD]K}y.|iƒ}x|D]}|i |ƒqAWWq%|i |ƒq%Xq%WdS(sOIterates through all session handlers and sessions to perform session cleanupN( trandomt randrangetSESSION_EXPIRE_CHECKtregistryR@RtkeystsessionstsR-RA(RFRHRIR((R Rs  tsessionHandlercBsbtZdZd„Zd„Zd„Zd„Zd„Zed„Z d„Z d„Z d „Z RS( saAll session handlers should subclass this, and implement the methods marked: 'not implemented'.cCs|iiƒ|_dS(N(t sessionModuleRt getServerIDRtchildnum(RRK((R R=“scCs d‚dS(Nsnot implemented((R((R R>•scCs d‚dS(Nsnot implemented((RR.((R R-—scCs d‚dS(Nsnot implemented((RR.((R R/™scCs d‚dS(Nsnot implemented((R((R R2›scCs d‚dS(Nsnot implemented((RR0R1R.((R RscCs d‚dS(Nsnot implemented((R((R RGŸscCs |i|ƒS(N(RR-tkey(RRN((R t __getitem__¡scCs |i|ƒS(N(RR/RN(RRN((R t __delitem__£s( R:R;RBR=R>R-R/R2RRRGRORP(((R RJs         t session_dircBsMtZdd„Zd„Zd„Zd„Zd„Zdd„Zd„Z RS(NcCsmti||ƒ|pdk}|iƒii}nt i i |ƒpd|‚n||_d|_ dS(Ns%session directory '%s' does not existtspy( RJR=RRKRtspycet getServertconfigttmptostpathtexiststprefix(RRKRRS((R R=«s  cCsd|i|ifS(NRQ(RRMR(R((R R>´scCsç|pdSntii|i|i|ƒ}d}d}y,t |dƒ}t i |ƒ}|iƒWn7y&|o|iƒnti|ƒWq q XnX|o8tiƒ|djo|i|ƒdSqã|dSndSdS(NtrbR1R0(R.RRWRXtjoinRRRZtfilenametft sessionInfotopentpickletloadtclosetunlinkttimeR/(RR.R^R]R_((R R-¶s,  cCs>y0tii|i|i|ƒ}ti|ƒWnnXdS(N( RWRXR\RRRZR.R]RA(RR.R]((R R/Ês cCs(x!|iƒD]}|i|ƒq WdS(N(RRGR.R/(RR.((R R2Ïs cCsæd}y¬|o2tii|i|i|ƒ}t |dƒ}n)t |i|id|i ƒ\}}}h}ttiƒƒ||d<||dçscCs|t|iƒS(N(RIR%RRZ(RIR((R Rkès(RWtlistdirRRRHtfilterRZtmap(RRH((R RGås( R:R;RR=R>R-R/R2RRG(((R RQªs     twi@Bc Csátitii||ƒƒ}|iƒz§dt i |ƒ}tii||||ƒ}xJtii|ƒo6tt i |ƒƒ}tii||||ƒ}q^Wd}t||ƒ}||||fSWd|iƒXdS(Ns%06d(t spyceLocktfileLockRWRXR\RRZtfilelocktacquireRCRDtmaxR.tuniqueR]RYtstrRR^R`tmodetrelease( RRZRuRwRtRrR^R]R.((R Rgìs "tsessionHandlerDBMcBs\tZd„Zd„Zd„Zd„Zd„Zd„Zd„Zdd„Z d „Z RS( NcCs8ti||ƒ||_d|_d|_d|_dS(Ni( RJR=RRKR]Rtdbmt BINARY_MODEtdbm_type(RRKR]((R R=s    cCsd|i|i|ifS(Ntsession_(RR|RMR](R((R R>scCs d‚dS(Nsneed to implement((R((R t_openscCs(|io|iiƒd|_ndS(N(RRzRcR(R((R t_close s  cCs©|pdSn|iƒz~d\}}|ii|ƒo ti |i|ƒ\}}n|djo*t i ƒ|jo|i |ƒd}n|SWd|i ƒXdS(N(NN( R.RRR~R1R0RzRRatloadsReR/R(RR.R0R1((R R-s      cCsA|iƒz%|ii|ƒo|i|=nWd|iƒXdS(N(RR~RzRR.R(RR.((R R/s  cCs.tii|iƒoti|iƒndS(N(RWRXRYRR]Rd(R((R R2"scCs||iƒz`|pt|i|iƒ}ntitt i ƒƒ||f|i ƒ}||i|<|SWd|iƒXdS(N(RR~R.t generateKeyRzRMRatdumpsRhReR1R0R{tvalueR(RR0R1R.Rƒ((R R%s + cCs-|iƒz|iiƒSWd|iƒXdS(N(RR~RzRGR(R((R RG/s  ( R:R;R=R>R~RR-R/R2RRRG(((R Ryÿs       cCs3t|ƒ}|ip|i||ƒ|_ndS(N(t __import__tmoduletmodtdbm_session_handlerRzR`R]tflags(R‡R…R]RˆR†((R topendb6s  t session_gdbmcBstZd„Zd„ZRS(NcCs ti|||ƒd|_dS(Ntgdbm(RyR=RRKR]R|(RRKR]((R R=<scCst||i|idƒdS(Ntcu(R‰RR|R](R((R R~?s(R:R;R=R~(((R RŠ;s t session_bsddbcBstZd„Zd„ZRS(NcCs ti|||ƒd|_dS(Ntbsddb(RyR=RRKR]R|(RRKR]((R R=CscCst|d|idƒdS(Ntdbhashtc(R‰RR](R((R R~Fs(R:R;R=R~(((R RBs cCszt|ƒd}ti|ƒ}x.|i|t|ƒƒoti|ƒ}q"W|t|ƒ}ti ddƒ||<|S(Nt_i( RvRZRCRDRtRNthashRRaR‚R(R’RZRtRN((R RIst session_usercBsPtZdZed„Zd„Zd„Zd„Zd„Zd„Z d„Z RS(sUser-callback session handlercCsC|iiƒ|_||_||_||_||_||_ dS(N( RKRRLRtserverIDtinfotgetftsetftdelftidsf(RRKR–R—R˜R™R•((R R=Ys     cCsd|i|ifS(NR“(RR”R•(R((R R>`scCs|i|i|ƒS(N(RR–R•R.(RR.((R R-bscCs|i|i|||i|ƒS(N(RR—R•R0R1R”R.(RR0R1R.((R RdscCs|i|i|ƒS(N(RR˜R•R.(RR.((R R/fscCs|i|iƒS(N(RR™R•(R((R RGhscCs(x!|iƒD]}|i|ƒq WdS(N(RRGR.R/(RR.((R R2js ( R:R;RBRR=R>R-RR/RGR2(((R R“Ws       (t spyceModuletreReR"RCRptcPickleRaRBRRERRRJRQRgRyR‰RŠRRR“(RRCR“RgRyRRR"R›RBRœRšRRQRRpR‰RJReRŠRERa((R t? s* $    Q B7