;ò )äHEc@sKdkTdklZlZlZlZlZlZlZl Z dk Z dk Z dk Z dk Z dkZdklZlZdklZlZdklZdklZdklZdkZdklZyd klZeƒZWnej oeiZnXyse e i!ie"d ƒƒi#ƒZ$e i%d e$ƒZ&e'e&i(d ƒƒe'e&i(d ƒƒe'e&i(dƒƒfZ)WndddfZ)nXdk*l+Z+dk,l-Z-l.Z.l/Z/dk0Z0dk1l2Z2ydk3l4Z5Wnej o e5Z5nXdZ6dfd„ƒYZ7ee7ƒd„Z8d„Z9d„Z:d„Z;dk<l=Z=d„Z>ddfdd fd!d"fdd#fd!d$fd%d&ffd'„Z?d(„Z@d)„ZAd*„ZBd+„ZCd,„ZDd-„d.„ZEd/„ZFeGd0„ZHdkIZIdk Z d1fd2„ƒYZJd3„ZKd4„ZLd5„ZMd6„ZNd7„ZOd8„ZPdS(9(s*(ssplitsjoinsfindslowersrfindsatoisstripslstripN(squotesunquote(sgetSecurityManagersClassSecurityInfo(sabsattr(sInitializeClass(s SimpleItem(sDateTime(s SyntaxErrors version.txts'(?i)zope\s*([0-9]+)\.([0-9]+)\.([0-9]+)iiii (s __version__(sPREFER_USERNAME_COOKIEs PAGE_METADATAs BORING_PAGES(s_(sgets 1999/11/05s PageUtilscBstZdZeƒZeidƒd„Zed„ZeZ ed„Z edd„Z d„Z d„Z d „Zd dd „Zd dd „Zeieidƒdded„Zd„Zd„Zeieidƒd„Zeieidƒd„Zeieidƒd„Zeieidƒd„Zeieidƒd„Zeieidƒd„Zd„Zeieid ƒd!„ZeZeieid"ƒd#„Z e Z!eieid$ƒd%„Z"d&„Z#d'„Z$d(d)„Z%eieid*ƒd+„Z&eieid,ƒdd-„Z'eieid.ƒd/„Z(eieid0ƒd1„Z)eieid2ƒd3„Z*eieid4ƒd5„Z+eieid6ƒd7„Z,eieid8ƒd9„Z-eieid:ƒd;„Z.eieid<ƒd=„Z/eieid>ƒd?„Z0eieid@ƒdA„Z1eieidBƒdC„Z2eieidDƒdE„Z3eieidDƒdF„Z4eieidDƒdG„Z5eieidDƒdH„Z6eieidIƒdJ„Z7eieidKƒedL„Z8dM„Z9RS(Ns8 Miscellaneous utility methods for zwiki pages. sViewcCstƒi||ƒSdS(N(sgetSecurityManagerscheckPermissions permissionsobject(sselfs permissionsobject((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyscheckPermission1scCs>|pt|dtƒ}|i|ƒpt|ddƒ SdS(NsREQUESTsedits_need_usernamei(sREQUESTsgetattrsselfsNonesrequestHasUsername(sselfsREQUEST((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyscheckSufficientId6scCs@|pt|dtƒ}|i|ƒ}|o ||ijSdS(sV Check REQUEST has either an authenticated user or a username cookie. sREQUESTN(sREQUESTsgetattrsselfsNones usernameFromsusernames REMOTE_ADDR(sselfsREQUESTsusername((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysrequestHasUsername?sicCs÷|pt|dtƒ}| odSnt}|idƒ}|o3|iƒ}|t|i i ƒjo t}qxn|i idtƒ}|idtƒ}|o|ipd}to|p|p |p|Sn|p|p |p|SdS(s Get the best available user id from the current visitor's REQUEST. We use the first of: - a MAILIN_USERNAME set by mailin.py - an authenticated username - a zwiki_username cookie - the client's IP address, unless disabled Or, if PREFER_USERNAME_COOKIE in Defaults.py is true, we'll let the cookie take precedence. This means an authenticated user could pretend to be someone else by setting the cookie, but it's useful for this case: a simple community wiki protected by a single common login, multiple users distinguished by their zwiki_username. We'll find REQUEST ourself if necessary (helps backwards compatibility with old skin templates). sREQUESTssAUTHENTICATED_USERszwiki_usernamesMAILIN_USERNAMEN(sREQUESTsgetattrsselfsNonesauthenticated_namesgetsusers getUserNamesstrs acl_userss_nobodyscookiess cookie_names mailin_names ip_addresss REMOTE_ADDRsip_addrsPREFER_USERNAME_COOKIE(sselfsREQUESTs ip_addresssip_addrs cookie_namesusers mailin_namesauthenticated_name((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys usernameFromGs  cCst|iƒƒSdS(s4 Give the size of this page's text. N(slensselfstext(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyssizemscCs(|iƒt|iƒƒ|iƒSdS(sR Give the total size of this page's text plus cached render data. N(sselfssizeslens preRenderedscachedDtmlSize(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys cachedSizesscCsAtt|ddƒƒ}td„|ƒ}tt|dƒƒSdS(sJ Estimate the size of this page's cached DTML parse data. s _v_blocksscCst|ƒtdƒjS(Ns(stypesx(sx((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys~sN(sflattenDtmlParsesgetattrsselfsstringssfilterslensjoin(sselfsstrings((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyscachedDtmlSizeysiÈcCs´t|ƒt|ƒf\}}|iƒ}tidd|ƒiƒ}|o t t |dƒ| dƒ}nt |ƒ|jo'|| }tidd|ƒd}nt |ƒSdS(sa Give a short plaintext summary of this page's content. We generate this by excerpting the first paragraph. Specifically, we take the page's document part, strip html tags, and return up to the specified number of characters or paragraphs, replacing the last word with an ellipsis if we had to truncate. s <(?=\S)[^>]+>ss s\w*$s...N( sintssizes paragraphssselfs documentPartstsressubsstripsjoinssplitslens html_quote(sselfssizes paragraphsst((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyssummarys   iôc CsAtidd|i|iƒi|id|d|ƒƒƒƒSdS(sÛ Give a summary of this page's content, as rendered html. Similar to summary(), but this one tries to apply the page's formatting rules and do wiki linking. We remove any enclosing

. s(?si)^

(.*)

\n?$s\1ssizes paragraphsN( sressubsselfs renderLinksInspageTypesformatssummaryssizes paragraphs(sselfssizes paragraphs((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysrenderedSummary“s s excerptAtidc Cs|p |iƒ}tidd|ƒ}tidti|ƒ|ƒ} | o|o´| i ƒ| i ƒd}t ||dddƒ}t||ddt|ƒƒ} t||| !ƒ}|o<tidtit|ƒƒdt| iƒƒ|ƒ}n|Snt|| ƒSdS( sp Return a highlighted search result excerpt from this page (or text). This method searches this page's text, or the provided text, for the first occurrence of expr (cleaned up) and returns the surrounding text chunk, html quoted, and optionally with the matches enclosed in styled spans. If no match is found, it just returns a chunk from the beginning. It should mimic the search strategy of SearchPage, but that depends on catalog configuration and it currently doesn't do a very good job, so the excerpts and highlights can be misleading. s\*ss(?i)iiisM%sN(stextsselfsressubsexprsstringssearchsescapesmsstartsendsmiddlesmaxssizesexstartsminslensexends html_quotesexcerpts highlightsgroup( sselfsexprssizes highlightstextsexstartsexcerptsstringsmiddlesexendsm((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys excerptAt s ! c Cs¬dtfd„ƒY}||ƒ}xvtddgD]d}y2t||ttt|d|ƒ|t ƒƒƒWq3t t fj ot||t ƒq3Xq3Wd|_ |SdS(sæ Make a catalog-brain-like object containing page's principal metadata. Given a real page object, this returns a PageBrain which emulates a catalog brain object (search result), for use when there is no catalog. All PAGE_METADATA fields will be included, plus a few more for backwards compatibility with old skin templates. Warning: fields such as the parents list may be copies-by-reference, and should not be mutated. s PageBraincBstZd„Zd„ZRS(NcCs ||_dS(N(sobjsselfs_obj(sselfsobj((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys__init__ÎscCs |iSdS(N(sselfs_obj(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys getObjectÏs(s__name__s __module__s__init__s getObject(((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys PageBrainÍs spage_urls title_or_idsaq_basesN( s SimpleItems PageBrainspagesbrains PAGE_METADATAsattrssetattrsabsattrsgetattrsNones ImportErrorsAttributeErrors linkTitle(sselfspagesattrsbrains PageBrain((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys metadataForÁs   ) cCsVxKtD]C}t||ƒ o,|iƒ}|o|i|ƒSqJtSqqW|SdS(s Ensure brain has all the expected metadata, looking in ZODB if needed. This should only happen with catalog brains, where the catalog does not have all the metadata Zwiki expects. We can't add fields to catalog brains, so in that case we'll return a PageBrain instead. If the catalog says eg page id is None, we don't do anything about that; we'll return it in the metadata. If getObject() returns None (a stale catalog entry), we return None. N( s PAGE_METADATAsattrshasattrsbrains getObjectspsselfs metadataForsNone(sselfsbrainsattrsp((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysensureCompleteMetadataInßs   s isZwikiPagecCst|dtƒ|ijSdS(Ns meta_type(sgetattrsobjectsNonesselfs meta_type(sselfsobject((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys isZwikiPageõss zwiki_versioncCstSdS(s3 Return the zwiki product version. N(s __version__(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys zwiki_versionùss htmlquotecCst|ƒSdS(N(s html_quotestext(sselfstext((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys htmlquotess htmlunquotecCst|ƒSdS(N(s html_unquotestext(sselfstext((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys htmlunquotessurlquotecCst|ƒSdS(N(squotestext(sselfstext((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysurlquote ss urlunquotecCst|ƒSdS(N(sunquotestext(sselfstext((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys urlunquotescCs2d|ii|iƒ tt|ƒƒdfSdS(Ns<%s %s at 0x%s>i(sselfs __class__s__name__sidshex(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys__repr__sspageUrlcCs"|iƒdt|iƒƒSdS(s"Return the url for this wiki page.s/N(sselfswiki_urlsquotesid(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyspageUrlsswikiUrlcCs8y|iƒiƒSWnttfj o dSnXdS(s&Return the url for this wiki's folder.sN(sselfsfolders absolute_urlsKeyErrorsAttributeError(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyswikiUrls swikiPathcCsGy#tidd|iƒiƒƒSWnttfj o dSnXdS(s1Return the path part of this wiki's url. s .*?//.*?/s/sN(sressubsselfsfolders absolute_urlsKeyErrorsAttributeError(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyswikiPath%s #cCs(|iƒ}|o |iƒpdSdS(Ns(sselfs defaultPagespspageUrl(sselfsp((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysdefaultPageUrl.s cCsi|i|ƒ}|o|iƒo |iƒo|iƒSn(|o|iƒiƒd|SndSdS(sQ Return the url of an existing dtml page, or of a method, or ''. s/sN( sselfs pageWithNamespagenamesps dtmlAllowedshasDynamicContentspageUrls methodnames defaultPage(sselfspagenames methodnamesp((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysurlForDtmlPageOrMethod2s!scCs+|i|ƒ}|o |iƒp|SdS(sE Return the url of an existing page, or the default. N(sselfs pageWithNamespagenamespspageUrlsdefault(sselfspagenamesdefaultsp((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysurlForPageOrDefault;sshomeUrlcCs|id|iƒƒSdS(Ns FrontPage(sselfsurlForPageOrDefaultswikiUrl(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyshomeUrlEss contentsUrlcCs7|iƒd}|o|d|iƒ7}n|SdS(sD Return the url of zwiki's contents method. In general, we try to keep these urls stable, so as to minimise useless work done for web robots. For the contents page, this was tricky because we like it to know what page we were looking at (for you are here), and to scroll there. Here's what we do now: - use front page url as our fixed base - add #PageId so the browser will scroll; most robots ignore this part, we think - have the contents page figure out"you are here" from the http referer s /contentss#N(sselfsdefaultPageUrlsurlsscrollspageId(sselfsscrollsurl((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys contentsUrlIs s changesUrlcCs|iddƒSdS(Ns RecentChangess recentchanges(sselfsurlForDtmlPageOrMethod(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys changesUrl_ss discussionUrlcCs;|idƒp |idƒ}|o |iƒpdSdS(NsUserDiscussionsGeneralDiscussions(sselfs pageWithNamespspageUrl(sselfsp((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys discussionUrlcssindexUrlcCs|iddƒSdS(NsAllPagess(sselfsurlForDtmlPageOrMethod(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysindexUrlhss uploadsUrlcCsdSdS(Ns((sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys uploadsUrllsspreferencesUrlcCs|iddƒSdS(Ns UserOptionss useroptions(sselfsurlForDtmlPageOrMethod(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyspreferencesUrlpsshelpUrlcCs|iddƒSdS(NsHelpPageshelppage(sselfsurlForDtmlPageOrMethod(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyshelpUrltss searchUrlcCs|iddƒSdS(Ns SearchPages searchwiki(sselfsurlForDtmlPageOrMethod(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys searchUrlxss creationTimecCs;yt|iƒSWn#ttfj ottƒSnXdS(sO Return our creation time as a DateTime, guessing if necessary N(sDateTimesselfs creation_timesAttributeErrorsDateTimeSyntaxErrorsZWIKI_BIRTHDATE(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys creationTime|s s lastEditTimecCs;yt|iƒSWn#ttfj ottƒSnXdS(sP Return our last edit time as a DateTime, guessing if necessary N(sDateTimesselfslast_edit_timesAttributeErrorsDateTimeSyntaxErrorsZWIKI_BIRTHDATE(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys lastEditTimeŠs sfoldercCs tt|d|ƒdtƒSdS(së return this page's containing folder We used to use self.aq_parent everywhere, now self.aq_inner.aq_parent to ignore acquisition paths. Work for pages without a proper acquisition wrapper too. saq_inners aq_parentN(sgetattrsselfsNone(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysfolder”ssagecCs|i|iƒSdS(sM return a string describing the approximate age of this page N(sselfs asAgeStrings creation_time(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysageŸsslastEditIntervalcCs$t|iƒiƒ|iƒƒSdS(s? return the number of days since page creation N(sintsselfsgetPhysicalRootsZopeTimes creationTime(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys ageInDays¦scCs|i|iƒSdS(sU return a string describing the approximate interval since last edit N(sselfs asAgeStringslast_edit_time(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyslastEditInterval®scCs$t|iƒiƒ|iƒƒSdS(s; return the number of days since last edit N(sintsselfsgetPhysicalRootsZopeTimes lastEditTime(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyslastEditIntervalInDaysµscCs(t|iƒiƒ|iƒdƒSdS(s< return the number of hours since last edit iN(sintsselfsgetPhysicalRootsZopeTimes lastEditTime(sself((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pyslastEditIntervalInHours½ss asAgeStringcCsî| odSnt|ƒtjot|ƒ}n|iƒiƒ|}d} d}d}t t i |ƒƒ} | d}| d} | d}t t i || | ƒƒ}t t i || | ||ƒƒ}t t|| | ||||ƒƒ}d} |o@| hd |<d |d jo td ƒp td ƒ<} n | o@| hd | <d | d jo tdƒp tdƒ<} nY|o@| hd |<d |d jo tdƒp tdƒ<} n| o@| hd | <d | d jo tdƒp tdƒ<} nË|o@| hd |<d |d jo tdƒp tdƒ<} n„|o@| hd |<d |d jo tdƒp tdƒ<} n=| hd |<d |d jo tdƒp tdƒ<} | SdS(sì return a string describing the approximate elapsed period since time time may be a DateTime or suitable string. Returns a blank string if there was a problem. Based on the dtml version in ZwikiTracker. s some timef0.041666666666666664f0.00069444444444444447f1.1574074074074073e-05iiims%(nb)d %(period)ssnbsperiodisyearssyearsmonthssmonthsweekssweeksdayssdayshoursshoursminutessminutessecondsssecondN(stimestypes StringTypesDateTimesselfsgetPhysicalRootsZopeTimeselapseds hourfactors minutefactors secondsfactorsintsmathsfloorsdayssweekssmonthssyearsshourssminutessroundssecondss datepatterns_ss(sselfstimes minutefactorsweeksssecondsselapsedshourss secondsfactorsyearss hourfactorsmonthssdayssss datepatternsminutes((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys asAgeStringÅs>   %*@@@@@@<sincludecKsH|p|i}|i|ƒ}|o|ddd||SndSdS(sÚ Convenience method for including the body of one page within another. Renders without the skin, passes REQUEST in case authentication is needed, fails silently if page does not exist. sbareisREQUESTsN(sREQUESTsselfspageWithNameOrIdspagespskw(sselfspagesREQUESTskwsp((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysincludeós cCsgt|dtƒ}|iƒ|jodSn|iƒ}x#|D]}||jodSq@q@WdSdS(s— Is this page one which should be quieter, eg test pages ? Boring pages are pages which we don't usually want to see in blog listings, rss feeds etc. (?) or hear mail from unless subscribed directly. These are TestPage, SandBox and their offspring, by default. You can configure different pages in a boring_pages lines folder property, one per line. s boring_pagesiiN(sgetattrsselfs BORING_PAGESsboringspageNamesancestorsAsLists ancestorssp(sselfs ancestorssboringsp((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysisBoringÿs    (:s__name__s __module__s__doc__sClassSecurityInfossecuritysdeclareObjectProtectedscheckPermissionsNonescheckSufficientIdsuserIsIdentifiedsrequestHasUsernames usernameFromssizes cachedSizescachedDtmlSizessummarysrenderedSummarysdeclareProtecteds PermissionssViews excerptAts metadataForsensureCompleteMetadataIns isZwikiPages zwiki_versions htmlquotes htmlunquotesurlquotes urlunquotes__repr__spageUrlspage_urlswikiUrlswiki_urlswikiPathsdefaultPageUrlsurlForDtmlPageOrMethodsurlForPageOrDefaultshomeUrls contentsUrls changesUrls discussionUrlsindexUrls uploadsUrlspreferencesUrlshelpUrls searchUrls creationTimes lastEditTimesfoldersages ageInDaysslastEditIntervalslastEditIntervalInDaysslastEditIntervalInHourss asAgeStringsincludesisBoring(((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys PageUtils's       &    !                               - cGsMg}x!|D]}|it|ƒƒq Wtidtidi|ƒƒdS(NsZWikis ( stmpsargssargsappendsstrszLOGsLOGsBLATHERsjoin(sargsstmpsarg((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysBLATHERs cGsMg}x!|D]}|it|ƒƒq Wtidtidi|ƒƒdS(NsZWikis ( stmpsargssargsappendsstrszLOGsLOGsWARNINGsjoin(sargsstmpsarg((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysWARNs cGsMg}x!|D]}|it|ƒƒq Wtidtidi|ƒƒdS(NsZWikis ( stmpsargssargsappendsstrszLOGsLOGsDEBUGsjoin(sargsstmpsarg((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysDEBUG s cCs@tiƒ\}}}z tti|||ƒdƒSWd~XdS(Ns(ssyssexc_infostypesvalstbsjoins tracebacksformat_exception(svalstypestb((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysformattedTraceback%s (sescapecCstt|ƒƒSdS(N(sescapesstrss(ss((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys html_quote+ss&s&s<ss‹s›s"s"cCs]t|ƒ}xF|D]>\}}t||ƒdjott||ƒ|ƒ}qqW|SdS(Ni( sstrssstextscharacter_entitiessresnamesfindsjoinssplit(ssscharacter_entitiessnamestextsre((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys html_unquote,s    cCs3ti||ƒ}|o||iƒ Sn|SdS(N(sressearchspatternsstrsmsstart(spatternsstrsm((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys stringBefore9scCs3ti||ƒ}|o||iƒ Sn|SdS(N(sressearchspatternsstrsmsend(spatternsstrsm((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysstringBeforeAndIncluding>scCs3ti||ƒ}|o||iƒSndSdS(Ns(sressearchspatternsstrsmsend(spatternsstrsm((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys stringAfterCscCs3ti||ƒ}|o||iƒSndSdS(Ns(sressearchspatternsstrsmsstart(spatternsstrsm((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysstringAfterAndIncludingHscCsbg}xQ|D]I}t|ƒttfjo|itt|ƒƒƒq |i |ƒq W|SdS(s3 Flatten a recursive list/tuple structure. N( sflatLists recursiveListsistypesListTypes TupleTypesextendsflattenslistsappend(s recursiveListsflatListsi((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysflatten]scCs9t|ƒtgƒjo|gpt|d„|gƒS(NcCs||||ƒS(N(sasFsb(sasbsF((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysgs(stypesLsreducesF(sLsF((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysgscCs |||ƒS(N(sfsl(slsf((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysgscCsèg}t|ƒttfjo`t|ƒdjo|it|dƒƒnt|ƒdjo|it|dƒƒqànbt|dƒo|it|i ƒƒn8t|dƒo|it|i ƒƒn|i |ƒ|SdS(sK Roughly flatten a DTML parse structure, for estimating it's size. iissectionsim_selfN( sflatListstypesisListTypes TupleTypeslensextendsflattenDtmlParseshasattrssectionsim_selfsappend(sisflatList((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysflattenDtmlParsexs c Cs›tidƒ}t|d„t|dƒƒ}d}|t jo h}n |i ƒ}g}xú|D]ò}|o|ddjo|d }n| oPnt|dƒ}t|ƒdjo(|i|dt|ddƒfƒnf|djo||fSnK|d|d f\}}|i|dt|dt|ƒfdƒfƒ|d}qcWx |D]} | d|| d©ss iiÿÿÿÿs s:iN(srescompilescrsmapssplitsbodyslinessisheaderssNonescopyshdrlistslinestokensslensappendsjoinslastslstripshdr( sbodysheadersslastsislinesshdrliststokensscrslineshdr((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysparseHeadersBodyŠs6    ( 0sPopen3cBstZdZddd„ZRS(sí This is a deadlock-safe version of popen, that returns an object with errorlevel, out (a string) and err (a string). (capturestderr may not work under windows.) Example: print Popen3('grep spam',' here spam ').out sicCstiƒ}d||f}|o4tiƒ}t|dƒi|ƒ|d|}n|otiƒ}|d|}nt i |ƒd?|_ t|dƒiƒ|_t i|ƒ|ot i|ƒn|o)t|dƒiƒ|_t i|ƒndS(Ns ( %s ) > %ssws isr(stempfilesmktempsoutfilescommandsinputsinfilesopenswrites capturestderrserrfilesosssystemsselfs errorlevelsreadsoutsremoveserr(sselfscommandsinputs capturestderrserrfilesoutfilesinfile((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys__init__Ós"    (s__name__s __module__s__doc__s__init__(((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysPopen3Ìs cCstd„t|ƒƒSdS(sž Strip whitespace elements from a list of strings, such as a lines property. Accept a list or tuple, return a list. (Zope 2.7 props are tuples.) cCs |iƒS(N(sxsstrip(sx((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysìsN(sfilterslistslines(slines((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys stripListæscCstid|ƒodSdS(s- True if s looks like an IP address. s [0-9\.\s]*$iN(sresmatchss(ss((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys isIpAddressîscCs0t|ƒtjo d|jodSndSdS(s0 True if s looks like an email address. s@iiN(stypesss StringType(ss((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysisEmailAddressôs cCst|ƒ SdS(sC True if s looks like a username (for Mail.py's purposes). N(sisEmailAddressss(ss((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys isUsernameûscCs|i|ƒdS(s@ Add a function to a list of hook actions to be called. N(shookssappendsfn(shookssfn((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pysaddHook!scCsQt}x@|D]8}y||ƒp|}Wq tdtƒƒq Xq W|SdS(s× Call each of a list of functions with arg, returning any error code. Hook functions are called with one argument. We catch and log any exceptions, and return the last non-null return code if any. s4could not call hook, skipping (traceback follows) %sN(sNoneserrshooksshooksargsBLATHERsformattedTraceback(shookssargserrshook((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys callHooks's(Qstypessstringssplitsjoinsfindslowersrfindsatoisstripslstripsossressyss tracebacksmathsurllibsquotesunquotes AccessControlsgetSecurityManagersClassSecurityInfos App.CommonsabsattrsGlobalssInitializeClasssOFS.SimpleItems SimpleItemszLOGsDateTimes SyntaxErrorsDateTimeSyntaxErrors ImportErrorsopenspaths SOFTWARE_HOMEsreadsvsmatchsmsintsgroups ZOPEVERSIONsProducts.ZWikis __version__sDefaultssPREFER_USERNAME_COOKIEs PAGE_METADATAs BORING_PAGESs PermissionssI18ns_s transactionsgetsget_transactionsZWIKI_BIRTHDATEs PageUtilssBLATHERsWARNsDEBUGsformattedTracebackscgisescapes html_quotes html_unquotes stringBeforesstringBeforeAndIncludings stringAftersstringAfterAndIncludingsflattensflatten2sflattenDtmlParsesNonesparseHeadersBodystempfilesPopen3s stripLists isIpAddresssisEmailAddresss isUsernamesaddHooks callHooks(;sunquotes ZOPEVERSIONsstringAfterAndIncludingslstrips SyntaxErrorsescapesformattedTracebacks BORING_PAGESsDateTimesaddHooks stringAftersflattensstripsflattenDtmlParsesfindsisEmailAddresssPREFER_USERNAME_COOKIEstempfiles stringBeforesparseHeadersBodysstringBeforeAndIncludingsZWIKI_BIRTHDATEsressplitsabsattrs html_unquotes PageUtilss __version__smathsDateTimeSyntaxErrorsWARNs isIpAddresssquotesClassSecurityInfosInitializeClasssflatten2ssyss SimpleItemsget_transactionsatois callHookssDEBUGs isUsernames stripLists_s PAGE_METADATAsBLATHERslowersjoinsgetSecurityManagers tracebacksmsPopen3srfindsvszLOGs Permissionssoss html_quote((s5/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/Utils.pys?sp7-       !@    ÿì       B       @      &