;ò x!bCc@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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys getServiceId.scCs |iSdS(N(sselfsDEFAULTServiceIdValue(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys getSessionId6scCsdS(s'session.load(requestHandler) -> SessionN((sselfs reqHandlerssession((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysload;scCsdS(s-session.session(requestHandler, self) -> NoneN((sselfs reqHandlerssession((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pyssave=scCsdS(sUsession.revert(requestHandler, self) -> None ~reverts the session to last saved copy.N((sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysexpireBscCsdS(sb session.newSessionId(self.requestHandler) -> String ~ returns a new sessionId, preferably unique.N((sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys newSessionIdJs(s__name__s __module__s__doc__sDEFAULTServiceIdKeysDEFAULTSessionIdKeysDEFAULTServiceIdValues getServiceIdsgetDefaultServiceIds getSessionIdsloadssavesrevertsexpires newSessionId(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysinitVs    cCs>|iƒ|_|iƒ|_|iƒ o|iƒndS(sh self.setup()-> None ~ template method used to define relationship between session and requestHandlerN(sselfs getServiceIds serviceIds getSessionIds sessionIdsisNewsload(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysisNewiscCsL|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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys getServiceIdns   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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys getSessionIdvs     cCs|ii|ƒdS(N(sselfsimplspurges reqHandler(sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysload‹s"      cCsO|tjo|iƒ}nt|_d|_|ii||ƒ||_dS(s$ session.save()-> None ~ saves self.sopenN(s reqHandlersNonesselfsstatussimplssave(sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pyssave s   cCs |iSdS(sP session.getExpire()-> float ~ returns when it will expire in secs since epoche.N(sselfs expiresWhen(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys setSession¹s (s__name__s __module__s__doc__sNones__init__sinitssetupsisNews getServiceIds getSessionIdspurgesloadssaves getExpiresexpires setSession(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysSessionMs          s BrowserLoadercBs/tZed„Zd„Zd„Zd„ZRS(NcCsdS(N((sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pyspurgeÆscCst|i|ƒƒSdS(N(sloadsssessions getSessionIds reqHandler(sselfs reqHandlerssession((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pyssaveÊs  cCshSdS(N((sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys newSessionIdÕs(s__name__s __module__sNonespurgesloadssaves newSessionId(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys BrowserLoaderÅs   s FileLoadercBsPtZdZdfZd„Zd„Zed„Zd„Zd„Z d„Z RS( NsPSOSessionFileLoader_sPathcCs;|i|ƒ}|i|ƒ}tii||ƒ}|SdS(s\session.getFileName(requestHandler) -> String ~ returns a fully qualified session file name.N( sselfsgetPaths reqHandlerspathssessions getSessionIdsfilesossjoinsfilename(sselfs reqHandlerssessionsfilenamesfilespath((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys getFileNameÛs cCs|it|ƒidƒSdS(s\ session.getPath(requestHandler) -> String ~ returns the path where sessions will be stored.sPathN(sselfs getDirectivess FileLoaders reqHandlersget(sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysgetPathâscCsdS(N((sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pyspurgeæscCs)tiit|i|ƒƒƒ}|SdS(s\session.newSessionId(requestHandler) -> String ~ returns a new sessionId, preferably unique.N(sosspathsbasenamesmktempsselfs getServiceIds reqHandlersid(sselfs reqHandlersid((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pyssaveòs( s__name__s __module__s DIRECTIVEtAGs DIRECTIVESs getFileNamesgetPathsNonespurges newSessionIdsloadssave(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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 }tSq¼XndS(sg self.getCookie(requestHandler) -> String | None ~ returns the session cookie if found otherwise noneis=s;iÿÿÿÿN(s reqHandlers getEnvirons getCookieKeyscookiesstartsselfs getServiceIdslook4sindexslensfindsendsstrips ExceptionsesNone(sselfs reqHandlersendsstartslook4scookiese((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysgetAttrs0s 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((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys setSession8s( s__name__s __module__s DIRECTIVEtAGs DIRECTIVESs getCookies getSessionIdswhensNonesexpiresgetAttrss setSession(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/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__(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysCookieFileImplDs s FileSessioncBstZdZd„ZRS(sH Default session bridge, using CookieFileImpl as the implementaion classcCsti||tƒƒdS(N(sSessionsinitsselfs reqHandlersCookieFileImpl(sselfs reqHandlersimp((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysinitKs(s__name__s __module__s__doc__sinit(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys FileSessionIs sCookieBrowserImplcBstZdZRS(sj session implementation, using actual browser cookie to store the session. This is not a first choice.(s__name__s __module__s__doc__(((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pysCookieBrowserImplOs (s __version__sweakrefsrefstimesstrftimesgmtimescPicklesloadsdumpsdumpssloadsstempfilesmktempsutilsMixInslogssyssossdictsmapClasssUserDicts SessionImplsSessions BrowserLoaders FileLoaders CookieSessionsCookieFileImpls FileSessionsCookieBrowserImpl(sloadsCookieFileImplsdumps FileSessionsmktempslogs FileLoaders SessionImplsmapClasss __version__srefsUserDicts BrowserLoadersgmtimessyss CookieSessionsMixInsCookieBrowserImplsdumpssSessionstimesloadssossstrftime((s:/home/groups/p/ps/pso/htdocs/tutorial/Login/pso/session.pys?s&     'x L