o k`'@sddlZddlmZddlmZddlTddlmZddlm Z ddl m Z m Z ddl mZmZmZdd lmZdd lmZGd d d eZdS) N)cached) ConfigSection)*)lazy)tag)_N_)IWikiChangeListenerIWikiMacroProvider WikiSystem) WikiParser)"split_url_into_path_query_fragmentc@seZdZdZeeeeddZdZ e de j e jZe dZddZd d Zd d Zd dZddZddZddZddZddZddZeddZddZdd Zd!d"Zd#d$Z e!d%d&Z"d'S)( InterWikiMapzInterWiki map manager. interwikiaEvery option in the `[interwiki]` section defines one InterWiki prefix. The option name defines the prefix. The option value defines the URL, optionally followed by a description separated from the URL by whitespace. Parametric URLs are supported as well. '''Example:''' {{{ [interwiki] MeatBall = http://www.usemod.com/cgi-bin/mb.pl? PEP = http://www.python.org/peps/pep-$1.html Python Enhancement Proposal $1 tsvn = tsvn: Interact with TortoiseSvn }}} InterMapTxtz#(%s)[ \t]+([^ \t]+)(?:[ \t]+#(.*))?z\$\dcCs||jvSN)upper interwiki_mapselfnsr5/usr/lib/python3/dist-packages/trac/wiki/interwiki.py __contains__9zInterWikiMap.__contains__cCs|j|Sr)rrrrrr __getitem__<rzInterWikiMap.__getitem__cCs t|jSr)listrrrrrkeys?s zInterWikiMap.keyscsfdd}ttj||S)z8Replace "$1" by the first args, "$2" by the second, etc.cs@t|dd}d|krtkrnn|dSdS)Nr)intgrouplen)matchnumargsrrsetargEs,z$InterWikiMap._expand..setarg)resubr _argspec_re)rtxtr'r(rr&r_expandCs zInterWikiMap._expandcCs,|s|S|||}||kr||dS|S)z9Like expand, but also append first arg if there's no "$".r)r-)rr,r'expandedrrr_expand_or_appendJs zInterWikiMap._expand_or_appendcCs||\}}}tdgddttj|D}t|\}}}|dkr,|d|d}n|g}|||}t|\} } } |rK| rKd| |ddf} n| pN|} |pR| } | | | } || s`d} | ||} | |krqt d ||d } | | fS) ztReturn `(url, title)` for the given InterWiki `ns`. Expand the colon-separated `target` arguments. rcSsg|] }t|ddqS)rN)r!).0arrr Wsz$InterWikiMap.url..:rz%s&%sNr z%(target)s in %(name)s)targetname) maxr)findallrr+r splitr/ _is_safe_urlr-r)rrr4urltitle maxargnumqueryfragmentr'ntargetnquery nfragment expanded_urlexpanded_titlerrrr:Qs.       zInterWikiMap.urlcC|jtjkr |`dSdSrr5r _page_namerrpagerrrwiki_page_addedp zInterWikiMap.wiki_page_addedcCrDrrE)rrHversiontcommentauthorrrrwiki_page_changedtrJzInterWikiMap.wiki_page_changedcCrDrrErGrrrwiki_page_deletedxrJzInterWikiMap.wiki_page_deletedcCrDrrErGrrrwiki_page_version_deleted|rJz&InterWikiMap.wiki_page_version_deletedc Csddlm}i}||jtjj}d}|dD]9}|rI|dr#d}qt tj |}|rH| \}}} | }| r=| n|} ||| f|| <q|drPd}q|jD])\}} | dd} | r| d }t| dkrt| d n|} ||| f|| <qV|S) zVMap from upper-cased namespaces to (namespace, prefix, title) values. r)WikiPageF z----TNr)trac.wiki.modelrRenvrrFtextr8 startswithr)r$ _interwiki_regroupsstriprinterwiki_sectionoptionsr#) rrRmapcontentin_maplinemprefixr:r;valuerrrrs4     zInterWikiMap.interwiki_mapccs dVdS)N InterWikirrrrr get_macross zInterWikiMap.get_macroscCs dtdfS)Nmessagesz.zwiki interwiki)class_) sortedrappendr/rtablernthemr) r formatterr5r^ interwikiskrbr:r;rrr expand_macros   zInterWikiMap.expand_macrocCs*t|jjpd|vp|ddd|jvS)Nr3rr)r rUrender_unsafe_contentr8 _safe_schemes)rr:rrrr9s zInterWikiMap._is_safe_urlcCstt|jjSr)setr rU safe_schemesrrrrr|szInterWikiMap._safe_schemesN)#__name__ __module__ __qualname____doc__ implementsr r rr[rFr)compiler LINK_SCHEMEUNICODErXr+rrrr-r/r:rIrOrPrQrrrergrzr9rr|rrrrrs>   r)r) trac.cacher trac.configr trac.core trac.utilrtrac.util.htmlrtrac.util.translationrr trac.wiki.apir r r trac.wiki.parserr trac.wiki.formatterr Componentrrrrrs