Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/mercurial/templater.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
�c@s�ddklZddkZddkZddkZddkZddkZddkZddgZei	Z	e
d�Zdefd��YZ
he
d<Zd	efd
��YZdd�Zdd�ZdS(
i�(t_Nt	templatess../templatescCsj|oVt|�djp|d|djottd���n|dd!id�Sn|id�S(sZparse a string using simple c-like syntax.
    string must be in quotes if quoted is True.iii�sunmatched quotesit
string_escape(tlentSyntaxErrorRtdecode(tstquoted((s&/sys/lib/python/mercurial/templater.pytparsestrings
(tenginecBsPeZdZeid�Zhhd�Zd�Zd�Zd�Z	d�Z
RS(s�template expansion engine.

    template expansion works like this. a map file contains key=value
    pairs. if value is quoted, it is treated as string. otherwise, it
    is treated as name of template file.

    templater is asked to expand a key in map. it looks up key, and
    looks for strings like this: {foo}. it expands {foo} by looking up
    foo in map, and substituting it. expansion is recursive: it stops
    when there is no more {foo} to replace.

    expansion also allows formatting and filtering.

    format uses key to expand each item in list. syntax is
    {key%format}.

    filter uses function to transform value. syntax is
    {key|filter1|filter2|...}.s{([\w\|%]+)}|#([\w\|%]+)#cCs(||_||_||_h|_dS(N(tloadertfilterstdefaultstcache(tselfR
RR((s&/sys/lib/python/mercurial/templater.pyt__init__/s			ccs�|i|�}|i||�g}x�|o�y|di�}Wn#tj
o|id�q'nXt|t�o	|Vq'|djo	dVq't|d�o|i	dt
|��q't|�Vq'WdS(s�Perform expansion. t is name of map element to expand. map contains
        added elements for use during expansion. Is a generator.itt__iter__N(R
t_processtnextt
StopIterationtpopt
isinstancetstrtNonethasattrtinserttiter(Rtttmapttmpltiterstitem((s&/sys/lib/python/mercurial/templater.pytprocess5s

	
	c	cs�|id�\}}||�}t|d�p ttd�||f��n|i�}x,|D]$}|i|�|i||�VqdWdS(Nt%Rserror expanding '%s%%%s'(tsplitRRRtcopytupdateR!(	RtexprtgetRtkeytformattvtlmti((s&/sys/lib/python/mercurial/templater.pyt_formatIs 
c	
s�||ijo�|id�}|d�y0g}|dD]}||i|q;~�Wn/tj
o#}ttd�|d��nX��fd�}||i|<n|i||�S(Nt|iisunknown filter '%s'cs-|��}x�D]}||�}qW|S(N((R'txtf(Rtval(s&/sys/lib/python/mercurial/templater.pytapply[s
(R
R#RtKeyErrorRR(	RR&R'Rtpartst_[1]R0R,R2((R1Rs&/sys/lib/python/mercurial/templater.pyt_filterSs
0c	#s���fd�}x�|o��ii|�}|p
|VPn|id�\}}|i�}|dp|d}|o
|| Vn||}d|jo�i||��Vqd|jo�i||��Vq||�VqWdS(s'Render a template. Returns a generator.csY�i|�}|djo�ii|d�}nt|d�o|��}n|S(NRt__call__(R'RRR(R(R*(RR(s&/sys/lib/python/mercurial/templater.pyR'fs
iiR"R.N(ttemplate_retsearchtspantgroupsR-R6(	RRRR'tmtstarttendtvariantsR&((RRs&/sys/lib/python/mercurial/templater.pyRcs"




(t__name__t
__module__t__doc__tretcompileR8RR!R-R6R(((s&/sys/lib/python/mercurial/templater.pyR	s		
	tdefaultt	templatercBs;eZhhhddd�Zd�Zd�Zd�ZRS(iicCs�|pd|_|i�|_h|_|otii|�pd|_ti	i�|_	|i	i
|�||_|||_|_
h|_|pdSntii|�ptitd�|��nti�}|i|�x�di�D]�\}}	|	ddjo\yt|	�|i|<Wq�tj
o2}
td|id|�|
idf��q�Xq�|	f}	d	|	d
jo|	d
id	d
�}	n|	dtii|i|	d
�f|i|<q�S(s�set up template engine.
        mapfile is name of file to read map definitions from.
        filters is dict of functions. each transforms a value into another.
        defaults is dict of default map definitions.ttemplateRNsstyle not found: %sis'"s%s: %sREt:i(tmapfileR$R
RtostpathtdirnametbasettemplatefiltersRR%RtminchunktmaxchunktenginestexiststutiltAbortRtconfigtreadtitemsRRtsourcetargsR#tjoin(RRIRRR
RORPtconfR(R1tinst((s&/sys/lib/python/mercurial/templater.pyR�s6	#		
,cCs||ijp
||ijS(N(R
R(RR(((s&/sys/lib/python/mercurial/templater.pyt__contains__�scCs�||ijo|y(t|i|d�i�|i|<Wq�tj
oA}t|idtd�|i|d|idf��q�Xn|i|S(s@Get the template for the given template name. Use a local cache.iistemplate file %s: %s(R
topenRRVtIOErrorRYR(RRR\((s&/sys/lib/python/mercurial/templater.pytload�s(+cKs�||ijo|i|dpd}|ii|�}|djo0t||i|i|i�}||i|<n|i||�}|io%t	i
|d|id|i�}n|S(NiREtmintmax(RRQR'RR`RRR!RORStincreasingchunksRP(RRRtttypetproctstream((s&/sys/lib/python/mercurial/templater.pyR7�s(

(R@RARR]R`R7(((s&/sys/lib/python/mercurial/templater.pyRF�s
	$		
cCsg}ttd�o
ti}nt}x�tD]�}|id�o
|}n1|id�}tiitii	|�|�}|otii||�}n|o'tii
|�otii|�Sq0tii|�o|i
tii|��q0q0W|S(sZreturn location of template file or directory (if no name).
    returns None if not found.tfrozent/(Rtsyst
executablet__file__RKt
startswithR#RJRZRLRRtnormpathtisdirtappend(tnamet	normpathstmoduleR0tptfl((s&/sys/lib/python/mercurial/templater.pyttemplatepath�s"

!!cCs�|djo
t�}nt|t�o
|g}n|o tii|d�d|gpg}|id�xO|D]G}x>|D]6}tii||�}tii|�o|Sq�q�WqxWt	d|��dS(s�Return path to mapfile for a given style.

    Searches mapfile in the following locations:
    1. templatepath/style/map
    2. templatepath/map-style
    3. templatepath/map
    Rsmap-sNo hgweb templates found in %rN(
RRuRRRJRKRZRotisfiletRuntimeError(tstyletpathst	locationsRKtlocationRI((s&/sys/lib/python/mercurial/templater.pytstylemap�s	


-
(ti18nRRCRiRJRSRURNRKt	stringifytTrueRtobjectR	RQRFRRuR|(((s&/sys/lib/python/mercurial/templater.pys<module>s$$	
jA

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.