;ò þaCc@s`dZdklZdklZlZlZdklZlZl Z l Z dk l Z dk lZlZdkZdkZy eZWndkZeiZnXdfd„ƒYZd efd „ƒYZd efd „ƒYZd efd„ƒYZdefd„ƒYZdeeefd„ƒYZdefd„ƒYZdeeefd„ƒYZdS(s$Revision: 1.15 $(sref(stimesstrftimesgmtime(sloadsdumpsdumpssloads(smktemp(sMixInslogNs SessionImplcBshtZdZdZdZdZd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z RS( sabstract implementaion classs PSOServiceIds PSOSessionIds SESSION_IDcCs|i|i|iƒƒSdS(s“session.getServiceId(requestHandler) -> String ~ The service id, set in the HTTP directive, is returned. This will default to the script's nameN(s reqHandlers getEnvironsselfsDEFAULTServiceIdKeysgetDefaultServiceId(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getServiceId.scCs |iSdS(N(sselfsDEFAULTServiceIdValue(sself((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysgetDefaultServiceId3scCs|i|iƒSdS(s±session.getSessionId(requestHandler) -> String | None ~ The current session id returned. If none return None. By default will look for a HTTP directive ServiceIdN(s reqHandlers getEnvironsselfsDEFAULTSessonIdKey(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getSessionId6scCsdS(s'session.load(requestHandler) -> SessionN((sselfs reqHandlerssession((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysload;scCsdS(s-session.session(requestHandler, self) -> NoneN((sselfs reqHandlerssession((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyssave=scCsdS(sUsession.revert(requestHandler, self) -> None ~reverts the session to last saved copy.N((sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysrevert?scCsdS(s› session.expire(requestHandler, when) -> None ~ if when is evals to a number will expire the session in when seconds, otherwise will try and parse when as a date. For more on this format see RFC2068 section 3.3.1 [also RCF822 and RCF1123] N((sselfs reqHandlerswhen((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysexpireBscCsdS(sb session.newSessionId(self.requestHandler) -> String ~ returns a new sessionId, preferably unique.N((sself((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys newSessionIdJs(s__name__s __module__s__doc__sDEFAULTServiceIdKeysDEFAULTSessionIdKeysDEFAULTServiceIdValues getServiceIdsgetDefaultServiceIds getSessionIdsloadssavesrevertsexpires newSessionId(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys SessionImpl&s        sSessioncBs’tZdZed„Zd„Zd„Zd„Zed„Zed„Z ed„Z ed„Z ed „Z d „Z ed „Zed „ZRS( sSession BridgecCs+ti|ƒ|i||ƒ|iƒdS(s�session = Session(requestHandler, SessionImplmentor()) ~ ctor's a session with the given request handler and session implementation instanceN(smapClasss__init__sselfsinits reqHandlersimplssetup(sselfs reqHandlersimpl((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys__init__Os cCs@t|_t|_d|_||_t|ƒ|_t|_dS(sI self.init(reqHandler, impl)-> None ~ template init method called by CTORsnewN( sNonesselfs sessionIds serviceIdsstatussimplsrefs reqHandlers expiresWhen(sselfs reqHandlersimpl((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysinitVs    cCsM|iƒ|_|iƒ|_dG|iƒGH|iƒ o|iƒndS(sh self.setup()-> None ~ template method used to define relationship between session and requestHandlersis new:N(sselfs getServiceIds serviceIds getSessionIds sessionIdsisNewsload(sself((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyssetupas cCs|idjSdS(s– session.new()-> 1|0 ~ returns 1 if session was created on this request, otherwise 0 used to define relationship between session and requestHandlersnewN(sselfsstatus(sself((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysisNewjscCsL|tjo|iƒ}n|i o|ii|ƒ|_n|iSdS(s[ session.getServiceId()-> String ~ returns serviceId, request passed on to the implementor.N(s reqHandlersNonesselfs serviceIdsimpls getServiceId(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getServiceIdos   cCs¹|tjo|iƒ}n|i o†|i|i|ƒƒ|_|i o\|ii|ƒ|_|i o/d|_|ii |ƒ|_|i |ƒqªd|_q®n|iSdS(s\ session.getSessionId()-> String ~ returns either the current sessionId or a new session id.snewsopenN( s reqHandlersNonesselfs sessionIds getEnvirons getServiceIdsimpls getSessionIdsstatuss newSessionIdspurge(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getSessionIdws     cCs|ii|ƒdS(N(sselfsimplspurges reqHandler(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyspurge‡scCsÍ|tjo|iƒ}nyt|ii||ƒ}|oK|iƒ}|tj o |tƒjod|_ dSn|i |ƒn d|_ Wn1t j o%}dk }|iƒd|_ nXhSdS(s7 session.load()-> None ~ loads a session into its self.snewN(s reqHandlersNonesselfsimplsloadssessions getExpiresexpiresstimesstatussupdates Exceptionses tracebacks print_exc(sselfs reqHandlers tracebacksesexpiresssession((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysloadŒs"      cCsO|tjo|iƒ}nt|_d|_|ii||ƒ||_dS(s$ session.save()-> None ~ saves self.sopenN(s reqHandlersNonesselfsstatussimplssave(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyssave¡s   cCs |iSdS(sP session.getExpire()-> float ~ returns when it will expire in secs since epoche.N(sselfs expiresWhen(sself((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getExpireªscCs)||_|ii||iƒ|ƒdS(s� session.expire(when)-> None ~ expires session at time.time() + when, if eval(when) evalutes, otherwise tries to parse when and expire session at when. For more on this format see RFC2068 section 3.3.1 [also RCF822 and RCF1123] N(swhensselfs expireWhensimplsexpires reqHandler(sselfswhen((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysexpire®s cCs4|tjo|iƒ}n|ii||ƒdS(sA session.setSession() -> None ~ adds session to request handler. N(s reqHandlersNonesselfsimpls setSession(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys setSessionºs (s__name__s __module__s__doc__sNones__init__sinitssetupsisNews getServiceIds getSessionIdspurgesloadssaves getExpiresexpires setSession(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysSessionMs         s BrowserLoadercBs/tZed„Zd„Zd„Zd„ZRS(NcCsdS(N((sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyspurgeÇscCst|i|ƒƒSdS(N(sloadsssessions getSessionIds reqHandler(sselfs reqHandlerssession((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysloadÈscCs�dGHy^dG|G|i|ƒGt|ƒGH|i|i|ƒt|ƒƒdG|i|i|ƒƒGHWn#dk}|idti ƒnXdS(Nssavings
savings
savedsfile( s reqHandlerssessions getServiceIdsdumpss setCookies getCookies tracebacks print_excssyssstdout(sselfs reqHandlerssessions traceback((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyssaveËs  cCshSdS(N((sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys newSessionIdÖs(s__name__s __module__sNonespurgesloadssaves newSessionId(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys BrowserLoaderÆs   s FileLoadercBsetZdZdfZeiieƒƒZd„Z d„Z e d„Z d„Z d„Zd„ZRS( NsPSOSessionFileLoader_sPathcCs;|i|ƒ}|i|ƒ}tii||ƒ}|SdS(s\session.getFileName(requestHandler) -> String ~ returns a fully qualified session file name.N( sselfsgetPaths reqHandlerspathssessions getSessionIdsfilesossjoinsfilename(sselfs reqHandlerssessionsfilenamesfilespath((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getFileNameÝs cCs#|it|ƒid|iƒSdS(s\ session.getPath(requestHandler) -> String ~ returns the path where sessions will be stored.sPathN(sselfs getDirectivess FileLoaders reqHandlersgetsPATH(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysgetPathäscCsdS(N((sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyspurgeèscCs)tiit|i|ƒƒƒ}|SdS(s\session.newSessionId(requestHandler) -> String ~ returns a new sessionId, preferably unique.N(sosspathsbasenamesmktempsselfs getServiceIds reqHandlersid(sselfs reqHandlersid((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys newSessionIdës!cCs#tt|i||ƒdƒƒSdS(s[session.load(requestHandler) -> session ~ returns session. All thrown expections passed on.sr+bN(sloadsopensselfs getFileNames reqHandlerssession(sselfs reqHandlerssession((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysloadðscCs2|i||ƒ}t|dƒ}t||ƒdS(sW session.save(requestHandler) -> None ~ saves session. All thrown expections passed on.sw+bN(sselfs getFileNames reqHandlerssessionsfilesopensfsdump(sselfs reqHandlerssessionsfsfile((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyssaveôs(s__name__s __module__s DIRECTIVEtAGs DIRECTIVESsosspathsdirnamesmktempsPATHs getFileNamesgetPathsNonespurges newSessionIdsloadssave(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys FileLoaderÙs      s CookieSessioncBsbtZdZdddddddfZd „Zd „Zd „Zed „Zd „Z d„Z RS(NsPSOCookieSession_sexpiressPathsCommentsDomainsMax-AgessecuresVersioncCsØ|i|iƒƒ}|o¸y€d}|i|ƒd}|i|ƒ}|t |ƒ7}|i d|ƒ}|djo||}n|||!}|i ƒSWqÔt j o%}dk}|iƒ|GHtSqÔXndS(sg self.getCookie(requestHandler) -> String | None ~ returns the session cookie if found otherwise noneis=s;iÿÿÿÿN(s reqHandlers getEnvirons getCookieKeyscookiesstartsselfs getServiceIdslook4sindexslensfindsendsstrips Exceptionses tracebacks print_excsNone(sselfs reqHandlersends tracebacksstartslook4scookiese((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getCookieþs$    cCs|i|ƒSdS(spself.getSessionId(requestHandler) -> String | None ~ The current session id returned. If none return None.N(sselfs getCookies reqHandler(sselfs reqHandler((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys getSessionIdscCsªt|dƒ o h|_n|tj o{y?tt|ƒƒ}tƒ|}tdt |ƒƒ|id None ~ utility method to build the correct cookie expire attributes.sattrss%a, %d %b %Y %H:%M:%S GMTsexpiressMax-AgeN( shasattrsselfsattrsswhensNonesevalsstrstimesstrftimesgmtimeshas_key(sselfswhen((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pyswhens     cCs|i|ƒ|i|ƒdS(s  self.expire(session, requestHandler, when)-> None ~ expires session at time.time() + when, if eval(when) evalutes, otherwise tries to parse when and expire session at when. For more on this format see RFC2068 section 3.3.1 [also RCF822 and RCF1123] N(sselfswhens reqHandlers setSessionssession(sselfssessions reqHandlerswhen((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysexpire+s cCs#t|dƒo |iSnhSdS(sk self.getAttrs() -> Dictionary of cookie attributes ~ utility method for setting up the session cookiesattrsN(shasattrsselfsattrs(sself((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysgetAttrs5s cCs{|iƒ|_|ii|it|ƒƒ|idƒ}|o|i |ƒn|i |i ƒ|i ƒ|iƒ�dS(sŠ self.setSession(session, reqHandler) -> None ~ adds session to request handler. Handles setting the cookie when the session is new. sPSOSessionExpiresN(sselfsgetAttrssattrssupdates getDirectivess CookieSessions reqHandlers getEnvironsvalueswhens setCookiessessions getServiceIds getSessionId(sselfssessions reqHandlersvalue((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys setSession=s( s__name__s __module__s DIRECTIVEtAGs DIRECTIVESs getCookies getSessionIdswhensNonesexpiresgetAttrss setSession(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys CookieSessionús    sCookieFileImplcBstZdZRS(s˜ Default session implementation, using temporary files to store the session, and using a browser cookie to pass the session id accross requests.(s__name__s __module__s__doc__(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysCookieFileImplIs s FileSessioncBstZdZd„ZRS(sH Default session bridge, using CookieFileImpl as the implementaion classcCsti||tƒƒdS(N(sSessionsinitsselfs reqHandlersCookieFileImpl(sselfs reqHandlersimp((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysinitPs(s__name__s __module__s__doc__sinit(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys FileSessionNs sCookieBrowserImplcBstZdZRS(sj session implementation, using actual browser cookie to store the session. This is not a first choice.(s__name__s __module__s__doc__(((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pysCookieBrowserImplTs (s __version__sweakrefsrefstimesstrftimesgmtimescPicklesloadsdumpsdumpssloadsstempfilesmktempsutilsMixInslogssyssossdictsmapClasssUserDicts SessionImplsSessions BrowserLoaders FileLoaders CookieSessionsCookieFileImpls FileSessionsCookieBrowserImpl(sloadsCookieFileImplsdumps FileSessionsmktempslogs FileLoaders SessionImplsmapClasss __version__srefsUserDicts BrowserLoadersgmtimessyss CookieSessionsMixInsCookieBrowserImplsdumpssSessionstimesloadssossstrftime((s8/home/groups/p/ps/pso/htdocs/pso-tutorial/pso/session.pys?s&     'y!O