; HfCc@s`dZdklZdklZlZlZdklZlZl Z l Z dk l Z dk lZlZdkZdkZy eZWndkZeiZnXdfdYZd efd YZd efd YZd efdYZdefdYZdeeefdYZdefdYZdeeefdYZdS(s$Revision: 1.15 $(sref(stimesstrftimesgmtime(sloadsdumpsdumpssloads(smktemp(sMixInslogNs SessionImplcBshtZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z RS( sabstract implementaion classs PSOServiceIds PSOSessionIds SESSION_IDcCs|i|i|iSdS(ssession.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/Lists/pso/session.pys getServiceId.scCs |iSdS(N(sselfsDEFAULTServiceIdValue(sself((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pysgetDefaultServiceId3scCs|i|iSdS(ssession.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/Lists/pso/session.pys getSessionId6scCsdS(s'session.load(requestHandler) -> SessionN((sselfs reqHandlerssession((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pysload;scCsdS(s-session.session(requestHandler, self) -> NoneN((sselfs reqHandlerssession((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/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/Lists/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/Lists/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/Lists/pso/session.pys newSessionIdJs(s__name__s __module__s__doc__sDEFAULTServiceIdKeysDEFAULTSessionIdKeysDEFAULTServiceIdValues getServiceIdsgetDefaultServiceIds getSessionIdsloadssavesrevertsexpires newSessionId(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pys SessionImpl&s        sSessioncBstZdZedZdZdZdZedZedZ edZ edZ ed Z d Z ed Zed ZRS( sSession BridgecCs+ti||i|||idS(ssession = 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/Lists/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/Lists/pso/session.pysinitVs    cCs>|i|_|i|_|i o|indS(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/Lists/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/Lists/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/Lists/pso/session.pys getServiceIdns   cCs|tjo|i}n|i o|i|i||_|i o\|ii||_|i o/d|_|ii ||_|i |qd|_qn|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/Lists/pso/session.pys getSessionIdvs     cCs|ii|dS(N(sselfsimplspurges reqHandler(sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pyspurgescCs|tjo|i}nyt|ii||}|oK|i}|tj o |tjod|_ dSn|i |n d|_ Wn1t j o%}dk }|id|_ 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/Lists/pso/session.pysloads"      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/Lists/pso/session.pyssaves   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/Lists/pso/session.pys getExpirescCs)||_|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/Lists/pso/session.pysexpires 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/Lists/pso/session.pys setSessions (s__name__s __module__s__doc__sNones__init__sinitssetupsisNews getServiceIds getSessionIdspurgesloadssaves getExpiresexpires setSession(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pysSessionMs          s BrowserLoadercBs/tZedZdZdZdZRS(NcCsdS(N((sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pyspurgescCst|i|SdS(N(sloadsssessions getSessionIds reqHandler(sselfs reqHandlerssession((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pysloadscCsdGHy^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/Lists/pso/session.pyssaves  cCshSdS(N((sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pys newSessionIds(s__name__s __module__sNonespurgesloadssaves newSessionId(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pys BrowserLoaders   s FileLoadercBsPtZdZdfZdZdZedZdZdZ dZ 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/Lists/pso/session.pys getFileNames cCs|it|idSdS(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/Lists/pso/session.pysgetPathscCsdS(N((sselfs reqHandler((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pyspurgescCs)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/Lists/pso/session.pys newSessionIds!cCs#tt|i||dSdS(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/Lists/pso/session.pysloadscCs2|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/Lists/pso/session.pyssaves( s__name__s __module__s DIRECTIVEtAGs DIRECTIVESs getFileNamesgetPathsNonespurges newSessionIdsloadssave(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pys FileLoaders      s CookieSessioncBsbtZdZdddddddfZd Zd Zd Zed Zd Z dZ RS(NsPSOCookieSession_sexpiressPathsCommentsDomainsMax-AgessecuresVersioncCs|i|i}|oyd}|i|d}|i|}|t |7}|i d|}|djo||}n|||!}|i SWqt j o }tSqXndS(sg self.getCookie(requestHandler) -> String | None ~ returns the session cookie if found otherwise noneis=s;iN(s reqHandlers getEnvirons getCookieKeyscookiesstartsselfs getServiceIdslook4sindexslensfindsendsstrips ExceptionsesNone(sselfs reqHandlersendsstartslook4scookiese((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pys getCookies  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/Lists/pso/session.pys getSessionIdscCst|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/Lists/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/Lists/pso/session.pysexpire&s cCs#t|do |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/Lists/pso/session.pysgetAttrs0s cCs{|i|_|ii|it||id}|o|i |n|i |i |i |idS(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/Lists/pso/session.pys setSession8s( s__name__s __module__s DIRECTIVEtAGs DIRECTIVESs getCookies getSessionIdswhensNonesexpiresgetAttrss setSession(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pys CookieSessions    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/Lists/pso/session.pysCookieFileImplDs s FileSessioncBstZdZdZRS(sH Default session bridge, using CookieFileImpl as the implementaion classcCsti||tdS(N(sSessionsinitsselfs reqHandlersCookieFileImpl(sselfs reqHandlersimp((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/pso/session.pysinitKs(s__name__s __module__s__doc__sinit(((s:/home/groups/p/ps/pso/htdocs/tutorial/Lists/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/Lists/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/Lists/pso/session.pys?s&     'x L