Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/mercurial/templater.pyc

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


��c@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZidd?d@fd6d	ddAfd6dddBfd
6dddCfd6dDd6ddEdfd6ddFdfd6dGd6Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Zd!�Zd"�Zd#�Zd$�Zd%�Zd&�Z d'�Z!d(�Z"d)�Z#id*�d6d+�d6d,�d6ed
6ed6ed6Z$ied-6e d.6e!d/6ed06e"d16e#d26ed36Z%d4d5gZ&ej'Z'd6�Z(e)d7�Z*d8e+fd9��YZ,ie,d:6Z-d;e+fd<��YZ.dd=�Z/dd>�Z0dS(Hi�(t_Nitgroupit)tfunct(itlistt,it|it%itsymboltstringtendc
csj|\}}}|}x@||krW||}|j�r=n
|dkrZ|d|fVn�dks�|dkr�|||d!dkr�|dkr�|d7}||}t}nt}|d7}|}x||kri||}|r|dkr|d7}q�n||kr\|s:d	|||!jdd
�|fVPnd	|||!jd�|fVPn|d7}q�Wtjtd�|��n�|j	�s�|d
kr|}|d7}x@||kr�|}|j	�p�|d
ks�n|d7}q�W|||!}	d|	|fV|d8}n2|dkr2|d7}Pntjtd�|��|d7}qWdd|fVdS(Ns(,)%|s"'trisr'sr"is\R
s\\s
string-escapesunterminated stringRR	t}ssyntax errorR(sr'sr"(
tisspacetNonetFalsetTruetreplacetdecodeterrort
ParseErrorRtisalnum(
tdatatprogramtstartRtpostcRtstdtsym((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt	tokenizers^


	


!




c
CsGg}dt|�}}tjtt�}x�|kr&|jd|�}|dkrs|jd||f�Pn|dkr�||ddkr�|jd|||d!df�|d}q.n||kr�jd|||!f�n||d|g}|j|�\}}|j|�q.Wg|D]}	t|	|�^q.S(Nit{R
is\(tlentparserRtelementstfindtappendtparset
compileexp(
ttmpltcontexttparsedRtstoptptntpdtparsereste((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytcompiletemplateOs$ "
cCsD|d}|tkr't|||�Stjtd�|��dS(Nisunknown method '%s'(tmethodsRRR(texpR)tt((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR'gs
cCs1|ddkr|dStjtd���dS(NiR	isexpected a symbol(RRR(R3((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt	getsymboloscCs:|s
gS|ddkr3t|d�|dgS|gS(NiRii(tgetlist(tx((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR6ts
cCsBt|�}||jkr7tjtd�|��n|j|S(Nsunknown function '%s'(R5t_filtersRRR(R3R)tf((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt	getfilter{scCs[|ddkr!t|d|�S|ddkrB|j|d�Stjtd���dS(NiR
iR	sexpected template specifier(R1t_loadRRR(R3R)((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytgettemplate�s
cCs|S(N((R)tmappingR((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt	runstring�scCs|j|�}|dkr3|jj|d�}ntj|d�rO||�St|tj�r{t|�}|||<|S|S(Ntt__call__(	tgetRt	_defaultstutiltsafehasattrt
isinstancettypest
GeneratorTypeR(R)R=tkeytv((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt	runsymbol�s

cCs?t|d|�\}}t|d|�}t|||ffS(Nii(R'R:t	runfilter(R3R)RRtfilt((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytbuildfilter�scCs�|\}}}y|||||��SWn^tttfk
r�t|t�r^|d}n|}tjtd�|j|f��nXdS(Nis8template filter '%s' is not compatible with keyword '%s'(	t
ValueErrortAttributeErrort	TypeErrorREttupleRCtAbortRt	func_name(R)R=RRRLtdt((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyRK�s
cCs?t|d|�\}}t|d|�}t|||ffS(Nii(R'R<trunmap(R3R)RRtctmpl((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytbuildmap�sccs,x%|D]\}}||||�VqWdS(N((R)R=ttemplateRR((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytruntemplate�sccs�|\}}}||||�}tj|d�r?|�}n|j�}xV|D]N}t|t�r�|j|�|jd�|d<t|||�VqR|VqRWdS(NR@tnodetoriginalnode(RCRDtcopyREtdicttupdateRARY(R)R=RRRVRtlmti((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyRU�s

cCs�t|d�}gt|d�D]}t||�^q!}|tkr\t|}||fS|tjkr�tj|}||fS||jkr�|�dkr�tjt	d�|��n|j|}t
|dd|dd|ffSdS(Niisfilter %s expects one argumenti(R5R6R'tfuncsttemplatefiltersR8R!RRRRK(R3R)R-R7targsR9((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt	buildfunc�s,




ccs�t|�dkr*tjtd���n|dd|||dd�}tj|d�svtjtd���n|dd|||dd�}|j|�VdS(Nisget() expects two argumentsiiRAs&get() expects a dict as first argument(R!RRRRCRDRA(R)R=RctdictargRH((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyRA�s""ccs
dt|�kodkns:tjtd���n|dd|||dd�}tj|d�r�|j}g|�D]}||�^q�}nd}t|�dkr�|dd|||dd�}nt}x'|D]}|r�}n|V|Vq�dS(Niis!join expects one or two argumentsiR@t (	R!RRRRCRDtjoinfmtRR(R)R=RctjoinsettjfR7tjoinertfirst((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytjoin�s""	%%
	ccs�t|�dkr*tjtd���nt|dd|||dd��}t|dd|||dd��}t|dd|||dd��}tt||t||���}tj|||�VdS(Nissub expects three argumentsiii(	R!RRRt	stringifyRYR1tretsub(R)R=Rctpattrpltsrc((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyRo�s(((ccsdt|�kodkns:tjtd���nt|dd|||dd��}|r�t|dd|||dd��}t||t||��VnWt|�dkrt|dd|||dd��}t||t||��VndS(Niis!if expects two or three argumentsii(R!RRRRmRYR1(R)R=RcttestR4((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytif_s"(((ccs6dt|�kodkns:tjtd���nt|dd|||dd��}t|dd|||dd��}||kr�t|dd|||dd��}t||t||��VnWt|�dkr2t|dd|||dd��}t||t||��VndS(Niis$ifeq expects three or four argumentsiii(R!RRRRmRYR1(R)R=RcRstmatchR4((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytifeqs"((((ccspt|�dkr*tjtd���nt|dd|||dd��}t||t||��VdS(Nislabel expects two argumentsii(R!RRRRmRYR1(R)R=RcR4((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytlabels(cCs�t|�dkr*tjtd���nt|dd|||dd��}t|dd|||dd��}tj|d|ddg�S(Nisrstdoc expects two argumentsiitstyletkeeptverbose(R!RRRRmtminirsttformat(R)R=RcttextRx((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytrstdoc&s
((cCst|dfS(Ni(R>(R0R((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt<lambda>1scCst|dfS(Ni(RJ(R0R((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR2scCst|d|�S(Ni(R'(R0R((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR3sRAtifRvRlRwR~Rot	templatess../templatesccs�t|t�r|Vn�tj|d�sF|dk	r�t|�Vq�n�x|D]w}t|t�rj|VqMtj|d�s�|dk	r�t|�Vq�qM|dk	rMxt|�D]}|Vq�WqMqMWdS(s=yield a single stream from a possibly nested set of iteratorst__iter__N(REtstrRCRDRt_flatten(tthingR`tj((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR�Is
cCsb|rUt|�dks,|d|dkrAttd���n|dd!jd�S|jd�S(sZparse a string using simple c-like syntax.
    string must be in quotes if quoted is True.iii�sunmatched quotesit
string_escape(R!tSyntaxErrorRR(Rtquoted((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytparsestring[s
&tenginecBs/eZdZiid�Zd�Zd�ZRS(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|...}.cCs(||_||_||_i|_dS(N(t_loaderR8RBt_cache(tselftloadertfilterstdefaults((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt__init__ys			cCs<||jkr1t|j|�|�|j|<n|j|S(s!load, parse, and cache a template(R�R1R�(R�R4((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR;s"cCstt|||j|���S(s�Perform expansion. t is name of map element to expand.
        mapping contains added elements for use during expansion. Is a
        generator.(R�RYR;(R�R4R=((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytprocess�s(t__name__t
__module__t__doc__R�R;R�(((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR�es	tdefaultt	templatercBs;eZiiiddd�Zd�Zd�Zd�ZRS(iic	Cs�|p	d|_|j�|_i|_|r?tjj|�pBd|_tj	j�|_	|j	j
|�||_|||_|_
i|_|s�dStjj|�s�tjtd�|��ntj�}|j|�x|dj�D]\}}	|	s(ttd�|jd|���n|	ddkr�yt|	�|j|<Wq�k
r�}
td|jd|�|
jdf��q��|	f}	d
|	dkr�|	djd
d�}	n|	dtjj|j|	d�f|j|<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.RXR?Nsstyle not found: %ss%s: missing valueis'"s%s: %sR�t:i(tmapfileR\tcachetmaptostpathtdirnametbaseRbR�R^R�tminchunktmaxchunktecachetexistsRCRRRtconfigtreadtitemsR�tsourceR�RctsplitRl(R�R�R�R�R�R�R�tconfRHtvaltinst((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR��s8	!		
%*cCs||jkp||jkS(N(R�R�(R�RH((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt__contains__�scCs�||jkr�y%tj|j|d�|j|<Wq�tk
ri}tjtd�|jd��q�tk
r�}t|jdtd�|j|d|jdf��q�Xn|j|S(s@Get the template for the given template name. Use a local cache.is"%s" not in template mapistemplate file %s: %s(	R�RCtreadfileR�tKeyErrorRRRRctIOError(R�R4R�((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytload�s%#)cKs�||jkr |j|dp#d}||jkr^t||j|j|j�|j|<n|j|}|j||�}|jr�tj	|d|jd|j
�}n|S(NiR�tmintmax(R�R�tenginesR�R�R�R�R�RCtincreasingchunksR�(R�R4R=tttypetproctstream((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR@�s&

	(R�R�R�R�R�R@(((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyR��s
	&		cCs�g}tj�rtj}nt}x�tD]�}|jd�rI|}n0|jd�}tjj	tjj
|�|�}|r�tjj	||�}n|r�tjj|�r�tjj|�Stjj
|�r+|jtjj|��q+q+W|S(sZreturn location of template file or directory (if no name).
    returns None if not found.t/(RCt
mainfrozentsyst
executablet__file__R�t
startswithR�R�RlR�R�tnormpathtisdirR%(tnamet	normpathstmoduleR9R,tfl((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyttemplatepath�s 
	! cCs�|dkrt�}nt|t�r3|g}nt|t�rN|g}nx�|D]�}|sgqUntjj|d�d|g}|jd�xP|D]H}x?|D]7}tjj||�}tjj|�r�||fSq�Wq�WqUWt	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
    R�smap-sNo hgweb templates found in %rN(
RR�RER�R�R�RlR%tisfiletRuntimeError(tstylestpathsRxt	locationsR�tlocationR�((s7/sys/lib/python2.7/site-packages/mercurial/templater.pytstylemap�s"	



(sgroupiR(sfunciR(slisti(Ri(Ri(iNN(ssymbol(sstring(iNN(1ti18nRR�R�RnRCR�RbR"RRFR{RR#RR1R'R5R6R:R<R>RJRMRKRWRYRURdRARlRoRtRvRwR~R2RaR�RmR�RR�tobjectR�R�R�R�R�(((s7/sys/lib/python2.7/site-packages/mercurial/templater.pyt<module>sv$<
	4															
			
				





		
&
E

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.