m 'Ec @sddd!ZdkZdklZdklZdklZlZl Z l Z dk l Z dk lZd klZd klZd klZd klZdkZd kTdklZdkZdkZdkZdkZdkZdk Z dk!Z!dk"l#Z#dk$l%Z%dk&l&Z&l'Z'dk(l)Z)l*Z*l+Z+dk,Z,ei-ddZ.ei-ddZ/e!i0di1Z2e!i0di1Z3e!i0di1Z4gZ5ei6de7Z8dZ9dddfZ:dZ;dZ<e,i=dZ>e9d d!ddfd"d d#d#d#e?d$ Z@d%eAfd&YZBdeeeee efd'YZCd(efd)YZDeiEeiFeie.eiGeieiHd*ZIeie/eiJeiHd+ZKd,ZLeiMd-ZNeiOd.d/ZPeiQeCdS(0s$Revision: 1.20 $i iN(s Persistent(s TimeStamp(sImplicitsaq_bases aq_parentsaq_inner(sOwned(s RoleManager(sTabs(sItem(sUNIQUE(sClassSecurityInfo(t*(sDEBUG(sescape(squote(surlparses urlunparse(sregisterBeforeTraversesunregisterBeforeTraversesqueryBeforeTraverses+/s-.s [\?&;,<> ]s[;,<>& ]s (\w*\.){2,}sdtml/addIdManagertbrowser_id_managertformtcookiesturlsAdd Browser Id ManagertBrowserIdManagersZope.BrowserIdManagertt_ZopeIdt/ic Csnt||||||||| } |i || |i |} | dj o|i|| ddSndS(t t update_menuiN(Rtidttitletidnametlocationt cookiepatht cookiedomaintcookielifedayst cookiesecuretauto_url_encodingtobtselft _setObjectt_getObtREQUESTtNonet manage_main( RR R R RRRRRRRR((tA/data/zmath/zope/lib/python/Products/Sessions/BrowserIdManager.pytconstructBrowserIdManager6s   tBrowserIdManagerErrcBstZRS(N(t__name__t __module__(((RRDsc Bs]tZdZdZhdd<ddZ+e ied?d@Z,e iedAdBZ-e iedCdDZ.e iedEdFZ/e iedGdHZ0e iedIdJZ1e iedGdKZ2e iedLdMZ3e iedNdOZ4e iedPdQZ5de6i6e6i7e6i8dRZ9dSZ:dTZ;dUZ<dVZ=dWZ>RS(Zs browser id management class sBrowser Id ManagertlabeltSettingstactiontmanage_browseridmgrtSecurityt manage_accesst Ownershipt manage_ownersmisc_/Sessions/idmgr.gift meta_typeiR R ticontbobobase_modification_timet title_or_idtManagert AnonymousiRRRRRc Cs}t||_t||_|i||i||i||i ||i ||i||i| dS(N(tstrR RR tsetBrowserIdNameR tsetBrowserIdNamespacesRt setCookiePathRtsetCookieDomainRtsetCookieLifeDaysRtsetCookieSecureRtsetAutoUrlEncodingR( RR R R RRRRRR((Rt__init__cs      cCs|idS(s Maybe add our traversal hook N(RtupdateTraversalData(Rtitemt container((Rtmanage_afterAddqscCs|idS(s( Remove our traversal hook if it exists N(RtunregisterTraversalHook(RR8R9((Rtmanage_beforeDeleteust hasBrowserIdcCs|iddodSndS(s Returns true if there is a current browser id, but does not create a browser id for the current request if one doesn't already exist tcreateiiN(Rt getBrowserId(R((RR=zsR?cCsJ|i}t|dd}|dj o,t|ptdt|n|Sn|i}|i }x|D]}|djoqmnt||d}|djoqmn|i|d}|dj o+t|o||_||_|SqqmqmW|oDt}d|jo|i||n||_d|_|SndS(s Examines the request and hands back browser id value or None if no id exists. If there is no browser id and if 'create' is true, create one. If cookies are are an allowable id namespace and create is true, set one. Stuff the id and the namespace it was found in into the REQUEST object for further reference during this request. t browser_id_s0Ill-formed browserid in REQUEST.browser_id_: %sRRN(RRtgetattrRtbidtisAWellFormedBrowserIdRtescapetbrowserid_namettktbrowserid_namespacestnstnamet current_nstgetR@tbrowser_id_ns_R>tgetNewBrowserIdt _setCookie(RR>RHRIRBRRFRJ((RR?s:               tflushBrowserIdCookiecCs:d|ijo tdn|id|idddS(s0 removes the bid cookie from the client browser RsfCookies are not now being used as a browser id namespace, thus the browserid cookie cannot be flushed.tdeletedtremoveiN(RRGRRNR(R((RROs tsetBrowserIdCookieByForcecCs4d|ijo tdn|i||idS(R RseCookies are not now being used as a browser id namespace, thus the browserid cookie cannot be forced.N(RRGRRNRBR(RRB((RRRs tisBrowserIdFromCookiecCs?|ip tdnt|iddjodSndS(s4 returns true if browser id is from REQUEST.cookies sThere is no current browser id.RLRiN(RR?RRAR(R((RRSs   tisBrowserIdFromFormcCs?|ip tdnt|iddjodSndS(s1 returns true if browser id is from REQUEST.form sThere is no current browser id.RLRiN(RR?RRAR(R((RRTs   tisBrowserIdFromUrlcCs?|ip tdnt|iddjodSndS(sE returns true if browser id is from first element of the URL sThere is no current browser id.RLRiN(RR?RRAR(R((RRUs   tisBrowserIdNewcCs3|ip tdnt|idddjS(s returns true if browser id is 'new', meaning the id exists but it has not yet been acknowledged by the client (the client hasn't sent it back to us in a cookie or in a formvar). sThere is no current browser id.RLN(RR?RRARR(R((RRVs  t encodeUrlt querystringc Cs|i|}|djo tdn|i}|djo7d|jod|||fSqd|||fSnNt |\}}} } } }d||| f} t||| | | |fSdS(s encode a URL with the browser id as a postfixed query string element or inlined into the url depending on the 'style' parameter sThere is no current browser id.RXt?s %s&%s=%ss%s?%s=%ss/%s/%s%sN(RR?R>RBRRtgetBrowserIdNameRItstyleRturlparsetprotothosttpathtparamstquerytfragt urlunparse( RRR[R>RbRBRIR]R^R`RaR_((RRWs     sdtml/manageIdManagertmanage_changeBrowserIdManagerc Cst||_|i||i||i||i ||i ||i ||i||i| dj o$d} | ii|i| ndS(R s6/manage_browseridmgr?manage_tabs_message=Changes savedN(R.R RR/R R1RR2RR3RR4RR0RR5RR7RRtmsgtRESPONSEtredirectt absolute_url( RR R RRRRRRRRe((RRds         R/cCsXt|tdjo|o t| ptdtt|n||_dS(s sets browser id name string RsBad id name string %sN(ttypetktbadidnamecharsinRRDtreprRRE(RRj((RR/s.RZcCs|iS(R N(RRE(R((RRZ!sR0cCsHx2|D]*}|tjotdt|qqWt||_dS(sB accepts list of allowable browser id namespaces sBad browser id namespace %sN(RHRItALLOWED_BID_NAMESPACESRRlttupleRRG(RRHRI((RR0&s  tgetBrowserIdNamespacescCs|iS(R N(RRG(R((RRo2sR1cCsQt|tdjo t| ptdtt|n||_dS(s* sets cookie 'path' element for id cookie RsBad cookie path %sN(RiR_tbadcookiecharsinRRDRlRt cookie_path(RR_((RR17s't getCookiePathcCs|iS(R N(RRq(R((RRr>sR3cCsUt|tdtdfjotdtt|nt||_dS(s( offset for id cookie 'expires' element if1.0s7Bad cookie lifetime in days %s (requires integer value)N(RitdaysRRDRltintRtcookie_life_days(RRs((RR3Cs%tgetCookieLifeDayscCs|iS(R N(RRu(R((RRvMsR2cCst|tdj otdtt|n|pd|_dSnt|ptdt| nt|otdt| n||_dS(s, sets cookie 'domain' element for id cookie Rs Cookie domain must be string: %sNspCookie domain must contain at least two dots (e.g. ".zope.org" or "www.zope.org") or it must be left blank. : %ss"Bad characters in cookie domain %s( RitdomainRRDRlRt cookie_domaint twodotsinRp(RRw((RR2Rs   tgetCookieDomaincCs|iS(R N(RRx(R((RRzhsR4cCs| |_dS(s, sets cookie 'secure' element for id cookie N(tsecureRt cookie_secure(RR{((RR4mstgetCookieSecurecCs|iS(R N(RR|(R((RR}rscCs| |_dS(s$ sets 'auto url encoding' on or off N(RR(RR((RR5wstgetAutoUrlEncodingcCs|iS(R N(RR(R((RR~|stisUrlInBidNamespacescCs d|ijS(sS Returns true if 'url' is in the browser id namespaces for this browser id RN(RRG(R((RRstgetHiddenFormFieldcCs d}||i|ifS(s Convenience method which returns a hidden form element representing the current browser id name and browser id s*N(tsRRZR?(RR((RRscCs8d } |o d} n8|io-||id} |d|| } nhd|i<d|i <d|i <d| <}|i oP|i dd } | d jod Snti| d d d jod Sqn|ii}h} ||i