
    6hr                    "   S r SSKJr  SSKrSSKrSSKJrJrJr  SSK	J
r
  SSKJr  SSKJrJrJrJrJrJrJrJrJr  SS	KJrJr  0 S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S_rScS) jrSdS* jrSeS+ jrSfS, jrS- rS. rS/ r S0 r!S1 r"S2 r#S3 r$S4 r%S5 r&S6 r'S7 r(S8 r)S9 r*S: r+S; r,S< r-S= r.S> r/S? r0S@ r1SA r20 S SB _S$SC _S"SD _S&\)_SESF _S\,_S\*_S\+_SG\/_SH\1_SI\2_SSJ _SSK _SL\-_SSM _SSN _r3\3Ri                  5       r5\3S"   \5S '    " SO SP\Rl                  5      r7SQ r8SR r9 " SS ST5      r: " SU SV\:5      r; " SW SX5      r<SY r=SZ r>S[ r? " S\ S]5      r@ " S^ S_5      rAS` rB Sc     SgSa jjrC Sc     ShSb jjrDg)ia  Slightly complicated template engine for commands and hgweb

This module provides low-level interface to the template engine. See the
formatter and cmdutil modules if you are looking for high-level functions
such as ``cmdutil.rendertemplate(ctx, tmpl)``.

Internal Data Types
-------------------

Template keywords and functions take a dictionary of current symbols and
resources (a "mapping") and return result. Inputs and outputs must be one
of the following data types:

bytes
    a byte string, which is generally a human-readable text in local encoding.

generator
    a lazily-evaluated byte string, which is a possibly nested generator of
    values of any printable types, and  will be folded by ``stringify()``
    or ``flatten()``.

None
    sometimes represents an empty value, which can be stringified to ''.

True, False, int, float
    can be stringified as such.

wrappedbytes, wrappedvalue
    a wrapper for the above printable types.

date
    represents a (unixtime, offset) tuple.

hybrid
    represents a list/dict of printable values, which can also be converted
    to mappings by % operator.

hybriditem
    represents a scalar printable value, also supports % operator.

revslist
    represents a list of revision numbers.

mappinggenerator, mappinglist
    represents mappings (i.e. a list of dicts), which may have default
    output format.

mappingdict
    represents a single mapping (i.e. a dict), which may have default output
    format.

mappingnone
    represents None of Optional[mappable], which will be mapped to an empty
    string by % operation.

mappedgenerator
    a lazily-evaluated list of byte strings, which is e.g. a result of %
    operation.
    )annotationsN)BinaryIOOptionalTuple   )_)FileNotFoundError)	configencodingerrorparserpycompattemplatefilterstemplatefuncstemplateutilutil)resourceutil
stringutil   ()   N)   groupr      ))   funcr   r   N   .)   NN)r   r   N   %)   NN)r   r   N   |)r   NN)r   r   N   *)   NN)r   r    N   /)r    NN)r!   r    N   +)   NN)r"   r#   N   -)r#   N)   negate   )r$   r#   N   =)   NN)   keyvaluer(   N   ,)   NN)   listr+   Nr   )r   NNNN   integer)r   r-   NNN   symbol)r   r.   NNN   string)r   r/   NNN   template)r   r0   NNN   endc              #    #    Un[         R                  " U 5      n XB:  Ga  X   nUR                  5       (       a  GOoUS;   a	  USU4v   GO`US;   a   US-   n[        XX%5      u  ptSXv4v   US-  nGO:US:X  aj  XUS-    S;   a_  XS-      nUS-   =pdXB:  a-  X   nUS	:X  a  US-  nM  X:X  a  S
XU U4v   GOUS-  nXB:  a  M-  [        R
                  " [        S5      U5      eUR                  5       (       a=  UnXB:  a&  X   nUR                  5       (       d  OUS-  nXB:  a  M&  SXU U4v   US-  nGOxUS	:X  a  XUS-    S;   d  US:X  a  XUS-    S;   a  US:X  a  US-  nS
n	OSn	XUS-    n
US-   =pdXB:  a  U R                  SXB5      (       a  US-  nM#  U R                  XU5      (       aC  [        R                  " XU 5      nU	S:X  a  [        US[        U5      5      S   nXU4v   US-  nOUS-  nXB:  a  M  [        R
                  " [        S5      U5      eUR                  5       (       d  US;   aH  UnUS-  nXB:  a,  X   nUR                  5       (       d  US:X  d  OUS-  nXB:  a  M,  XU nSX4v   US-  nO-XS:X  a  SSU4v   g[        R
                  " [        S5      U5      eUS-  nXB:  a  GM  U(       a   [        R
                  " [        S5      U5      eSSU4v   g7f)zZParse a template expression into a stream of tokens, which must end
with term if specifieds   (=,).%|+-*/Ns   "'r   r0      rr+   )s   r's   r"   \r/      unterminated stringr-   )s   \'s   \"r(   )s   r\'s   r\"s   \\\r#   r      _r.   r1   s   syntax errors   unterminated template expansion)r   bytestrisspace_parsetemplater   
ParseErrorr   isdigit
startswithr   unescapestrlenisalnum)programstartendtermposcsdatadtokenquotesyms               5/usr/lib/python3/dist-packages/mercurial/templater.pytokenizerM   z   sT     Cw'G
)L99;;. dC. &[aA&w3:ID((1HC$Y7q1^Ca AAgA)L:1HC6$gna88q ) &&q)?'@!DDYY[[A)Lyy{{q	 )
 w~q111HCJcAg&*::DycAg&*<< Dyq!##'*EAgA) %%i::1HC%%e#66 "--gn=D+-dAs4yA!D **1HCq' )* &&q)?'@!DDYY[[AIA1HC)L		qDyq	 )
 C.Cc%%1HCY4%%""1_#5s;;qA )B q!CDeLL4
s(   B=K'A K'#CK';A1K'.AK'8/K'c                   / n[        XX#5       H[  u  pVnUS:X  a  UR                  XV45        M   US:X  a  UR                  U5        M9  US:X  a  XG4s  $ [        R                  " SU-  5      e   [        R                  " S5      e)a  
>>> _parsetemplate(b'foo{bar}"baz', 0, 12)
([('string', 'foo'), ('symbol', 'bar'), ('string', '"baz')], 12)
>>> _parsetemplate(b'foo{bar}"baz', 0, 12, quote=b'"')
([('string', 'foo'), ('symbol', 'bar')], 9)
>>> _parsetemplate(b'foo"{bar}', 0, 9, quote=b'"')
([('string', 'foo')], 4)
>>> _parsetemplate(br'foo\"bar"baz', 0, 12, quote=b'"')
([('string', 'foo"'), ('string', 'bar')], 9)
>>> _parsetemplate(br'foo\\"bar', 0, 10, quote=b'"')
([('string', 'foo\\')], 6)
r/   r0   r1   s   unexpected type: %s!   unterminated scanning of template)_scantemplateappendr   ProgrammingError)tmplrA   stoprJ   parsedtypvalrD   s           rL   r9   r9      s     F&tD@#)MM3*%KMM#F];(()?#)EFF A 
 
 !E
FF    c              #     #    Sn[        U S[        U 5      US9 H  u  p4nU(       a  X%4-   v   US:X  a    gX54nM!     [        R                  " S5      e7f)a  Scan (type, start, end) positions of outermost elements in template

If raw=True, a backslash is not taken as an escape character just like
r'' string in Python. Note that this is different from r'' literal in
template in that no template fragment can appear in r'', e.g. r'{foo}'
is a literal '{foo}', but ('{foo}', raw=True) is a template expression
'foo'.

>>> list(scantemplate(b'foo{bar}"baz'))
[('string', 0, 3), ('template', 3, 8), ('string', 8, 12)]
>>> list(scantemplate(b'outer{"inner"}outer'))
[('string', 0, 5), ('template', 5, 14), ('string', 14, 19)]
>>> list(scantemplate(b'foo\\{escaped}'))
[('string', 0, 5), ('string', 5, 13)]
>>> list(scantemplate(b'foo\\{escaped}', raw=True))
[('string', 0, 4), ('template', 4, 13)]
Nr   )rawr1   rO   )rP   r>   r   rR   )rS   rZ   lastrV   rW   rD   s         rL   scantemplater\      s\     $ D&tQD	sC#-&=:D D 
 
 !E
FFs   AAc              #    ^ ^^#    SU-   n[         R                  [        R                  /U   nUm[         R                   " [        5      n TT:  Ga1  [        UUU 4S j[        R                  " U5       5       S S9nUS:  a  SU" T TT 5      T4v   TmOT XS-    n	Sn
U(       d#  UT-
  [        T TU R                  S5      5      -
  n
U
S	-  S:X  a  SU" T TUS-
   5      U	-   T4v   US-   mM  UT:  a  SU" T TU 5      T4v   X:X  a  S
SUS-   4v   gUR                  [        T US-   TS5      5      u  nmT R                  ST5      (       d   [        R                  " [        S5      T5      eSX4v   TS-  mTT:  a  GM1  U(       a   [        R                  " [        S5      U5      e S
ST4v   g! [        R                   a  n[        UT 5        e SnAff = f7f)zEParse template string into chunks of strings and template expressions   {c              3  J   >#    U  H  nTR                  UTT5      v   M     g 7fN)find).0rE   rD   rT   rS   s     rL   	<genexpr> _scantemplate.<locals>.<genexpr>%  s#     M2LQ1c4((2Ls    #c                    U S:  U 4$ )Nr    )ns    rL   <lambda>_scantemplate.<locals>.<lambda>&  s    q1uajrX   )keyr   r/   r   r4   r+   r1   N   }   invalid tokenr0   r5   )r   r=   r   identityelementsminr7   r>   rstripparserM   r<   r   r:   r   _addparseerrorhint)rS   rA   rT   rJ   rZ   sepcharsunescapeprg   rE   bsparseresinstrD   s   ` `          @rL   rP   rP     s    e|H""H$5$56s;H
ChA*DjM(2B2B82LM(A 1u (4D>":C@@QQAB#gT#a[%7%7%>!??Av{ (4a!e+<"="A3GG!e3w (4A;"7==ztQU++GGHT1q5$$EFMHc ??4--&&q)9':C@@,,1HCG DjJ ""1%;#<eDD 
 4
  4&s>   AGC	F3 GA+F3 'F3 *	G3GGGGc                    U R                   c  g U R                   nUS U R                  S5      nUR                  SS5      nUS-   SUS-   U-   -  -   S-   [        S5      -   U l        g )N   
s   \n    r   s   ^ s   here)locationcountreplacer   hint)rx   rS   locoffsets       rL   rr   rr   P  sn    }}
--C $3Ze$F<<v&D
 utsQw'7885@1W:MDIrX   c                    [        U [        5      (       d  U $ U S   nUS:w  a  U4[        S U SS  5       5      -   $ [        U 5      S:X  d   e[        S U S    5       5      nU(       d  g[        U5      S:X  a  US   S   S	:X  a  US   $ U4U-   $ )
a  Expand list of templates to node tuple

>>> def f(tree):
...     print(pycompat.sysstr(prettyformat(_unnesttemplatelist(tree))))
>>> f((b'template', []))
(string '')
>>> f((b'template', [(b'string', b'foo')]))
(string 'foo')
>>> f((b'template', [(b'string', b'foo'), (b'symbol', b'rev')]))
(template
  (string 'foo')
  (symbol 'rev'))
>>> f((b'template', [(b'symbol', b'rev')]))  # template(rev) -> str
(template
  (symbol 'rev'))
>>> f((b'template', [(b'template', [(b'string', b'foo')])]))
(string 'foo')
r   r0   c              3  8   #    U  H  n[        U5      v   M     g 7fr`   _unnesttemplatelistrb   xs     rL   rc   &_unnesttemplatelist.<locals>.<genexpr>w  s     FX033X   r   Nr+   c              3  8   #    U  H  n[        U5      v   M     g 7fr`   r   r   s     rL   rc   r   z  s     7w!"1%%wr   )r/   rX   r/   )
isinstancetupler>   )treeopxss      rL   r   r   `  s    & dE""	aB	[uuFT!"XFFFFt9>>	7tAw7	7B	RA"Q%(i/!uurzrX   c                x    [        U S[        U 5      5      u  pU[        U 5      :X  d   S5       e[        SU45      $ )zParse template string into treer   s$   unquoted template should be consumedr0   )r9   r>   r   )rS   rU   rD   s      rL   rq   rq     s>     q#d)4KF#d)DDDV455rX   c                j     [        U 5      $ ! [        R                   a  n[        X5        e SnAff = f)a  Parse a template expression into tree

>>> parseexpr(b'"foo"')
('string', 'foo')
>>> parseexpr(b'foo(bar)')
('func', ('symbol', 'foo'), ('symbol', 'bar'))
>>> from . import error
>>> from . import pycompat
>>> try:
...   parseexpr(b'foo(')
... except error.ParseError as e:
...   pycompat.sysstr(e.message)
...   e.location
'not a prefix: end'
4
>>> try:
...   parseexpr(b'"foo" "bar"')
... except error.ParseError as e:
...   pycompat.sysstr(e.message)
...   e.location
'invalid token'
7
N)
_parseexprr   r:   rr   )exprrx   s     rL   	parseexprr     s3    0$ 4&s   
 2-2c           	         [         R                   " [        5      nUR                  [        U S[	        U 5      5      5      u  p#U[	        U 5      :w  a   [
        R                  " [        S5      U5      e[        U5      $ )Nr   rl   )	r   rn   rq   rM   r>   r   r:   r   r   )r   ru   r   rD   s       rL   r   r     s]    hAq#d)45ID
c$iq!12C88t$$rX   c                0    [         R                  " U S5      $ )N)r-   r/   r.   )r   prettyformatr   s    rL   r   r     s    t%GHHrX   c                l    U (       d  [         R                  " [        S5      5      eU S   nX#   " X5      $ )z1Compile parsed template tree to (func, data) pairs   missing argumentr   r   r:   r   )expcontext
curmethodsts       rL   
compileexpr     s2    q!4566AA=&&rX   c                h    U S   S:X  a  U S   $ [         R                  " [        S5      U S   -  5      e)Nr   r.   r   s   expected a symbol, got '%s'r   )r   s    rL   	getsymbolr     s7    
1v1v


1;<s1vE
FFrX   c                V    U (       d  / $ U S   S:X  a  [        U S   5      U S   /-   $ U /$ )Nr   r,   r   r+   getlist)r   s    rL   r   r     s5    	twqt}!v%%3JrX   c                    U S   S;   a  [        X[        5      $ U S   S:X  a  UR                  U S   5      $ [        R                  " [        S5      5      e)z[Compile given template tree or load named template from map file;
returns (func, data) pairr   )r0   r/   r.   r   s   expected template specifier)r   methods_loadr   r:   r   r   r   s     rL   gettemplater     sV     1v))#00
1v }}SV$$


1;<
==rX   c                F    [         R                  " [        S5      U-  5      e)Ns$   recursive reference '%s' in template)r   
InputErrorr   )r   mappingrj   s      rL   _runrecursivesymbolr     s    


1DEK
LLrX   c                v    U SS   Vs/ s H  n[        X![        5      PM     nn[        R                  U4$ s  snf Nr   )r   r   r   runtemplate)r   r   ectmpls       rL   buildtemplater     s9    69!"g>gZG,gE>$$e,, ?s   6c                l   [        U S   5      nX!R                  ;   a6  UR                  U   n[        U S   U[        5      n[        R
                  XC44$ X!R                  ;   a1  UR                  U   n[        U S   U[        X%R                  5      nXV4$ [        R                  " [        S5      U-  5      e)Nr+   r      unknown function '%s')r   _filtersr   r   r   	runfilter_funcs_buildfuncargs_argspecr   r:   r   )r   r   rg   filtargfargss          rL   buildfilterr     s    #a&A"Q'2&&44NNNN1c!fgw::Fy


156:
;;rX   c                n    [        U S   U[        5      n[        U S   U5      n[        R                  X#44$ Nr   r+   )r   r   r   r   runmap)r   r   dargtargs       rL   buildmapr     s7    c!fgw/Ds1vw'D$..rX   c                l    [        U S   U[        5      n[        U S   5      n[        R                  X#44$ r   )r   r   r   r   	runmember)r   r   r   membs       rL   buildmemberr     s5    c!fgw/DSVD""TL11rX   c                N    [        U S   U[        5      n[        R                  U4$ r   )r   exprmethodsr   	runnegate)r   r   r   s      rL   buildnegater     s%    
SVWk
2C""C((rX   c                z    [        U S   U[        5      n[        U S   U[        5      n[        R                  X#U44$ r   )r   r   r   runarithmetic)r   r   funcleftrights        rL   buildarithmeticr     s<    c!fg{3Ds1vw4E&&U(;<<rX   c                   [        U S   5      nX!R                  ;   a1  UR                  U   n[        U S   U[        X#R                  5      nX44$ X!R
                  ;   ak  [        U S   U[        US S9n[        U5      S:w  a"  [        R                  " [        S5      U-  5      eUR
                  U   n[        R                  US   U44$ [        R                  " [        S5      U-  5      e)Nr   r+   )argspecs   filter %s expects one argumentr   r   )r   r   r   r   r   r   r>   r   r:   r   r   r   )r   r   rg   r   r   s        rL   	buildfuncr     s    #a&ANNNN1c!fg{AzzJyc!fg{AtLt9>""1%F#G!#KLLQ&&a!55


156:
;;rX   c                  ^^ UU4S jnUU4S jnU(       d  U" [        U 5      5      $ [        R                  " U5      =u  pxpn[        R                  " [        U 5      UUSSS9n[        R
                  " 5       nU(       a  U" UR                  U5      5      X'   U
(       a  U" UR                  U
5      5      X'   UR                  U" U5      5        U$ )a  Compile parsed tree of function arguments into list or dict of
(func, data) pairs

>>> context = engine(lambda t: (templateutil.runsymbol, t))
>>> def fargs(expr, argspec):
...     x = _parseexpr(expr)
...     n = getsymbol(x[1])
...     return _buildfuncargs(x[2], context, exprmethods, n, argspec)
>>> list(fargs(b'a(l=1, k=2)', b'k l m').keys())
['l', 'k']
>>> args = fargs(b'a(opts=1, k=2)', b'**opts')
>>> list(args.keys()), list(args[b'opts'].keys())
(['opts'], ['opts', 'k'])
c                b   > [         R                  " UU4S jU R                  5        5       5      $ )Nc              3  F   >#    U  H  u  pU[        UTT5      4v   M     g 7fr`   r   )rb   kr   r   r   s      rL   rc   6_buildfuncargs.<locals>.compiledict.<locals>.<genexpr>(  s$      
@JQ
1gz23
s   !)r   sortdictitems)r   r   r   s    rL   compiledict#_buildfuncargs.<locals>.compiledict'  s'    }} 
@B

 
 	
rX   c                J   > U  Vs/ s H  n[        UTT5      PM     sn$ s  snf r`   r   )r   r   r   r   s     rL   compilelist#_buildfuncargs.<locals>.compilelist,  s$    <>?Bq
1gz2B???s    r)   r.   )keyvaluenodekeynode)r   r   splitargspecbuildargsdictr   r   popupdate)r   r   r   funcnamer   r   r   _poskeysvarkey_keysoptkeytreeargscompargss    ``          rL   r   r     s     

@ 73<(( 170C0CG0LL#Heg## H }}H&x||F';<&x||F';<OOK)*OrX   c                @    [         R                  " [        S5      5      e)Ns*   can't use a key-value pair in this contextr   )r   contents     rL   buildkeyvaluepairr   E  s    


1JK
LLrX   c                P    [         R                  " [        S5      [        S5      S9e)Ns    can't use a list in this contexts   check place of comma and parensr   r   r   s     rL   	buildlistr   I  s'    


	
-.12 rX   c                ,    [         R                  U S   4$ r   )r   
runintegerr   rE   s     rL   rh   rh   R  s    l55qt<rX   c                ,    [         R                  U S   4$ r   )r   	runstringr   s     rL   rh   rh   S      \33QqT:rX   c                ,    [         R                  U S   4$ r   )r   	runsymbolr   s     rL   rh   rh   T  r   rX   r   c                *    [        U S   U[        5      $ r   )r   r   r   s     rL   rh   rh   V  s    :adA{;rX   r   r)   r,   c                    [        XS 5      $ )Nc                
    X-   $ r`   rf   abs     rL   rh   <lambda>.<locals>.<lambda>]      !%rX   r   r   s     rL   rh   rh   ]      q-?@rX   c                    [        XS 5      $ )Nc                
    X-
  $ r`   rf   r  s     rL   rh   r  ^  r  rX   r  r   s     rL   rh   rh   ^  r  rX   r%   c                    [        XS 5      $ )Nc                
    X-  $ r`   rf   r  s     rL   rh   r  `  r  rX   r  r   s     rL   rh   rh   `  r  rX   c                    [        XS 5      $ )Nc                
    X-  $ r`   rf   r  s     rL   rh   r  a  s    !&rX   r  r   s     rL   rh   rh   a  s    q-@ArX   c                  H    \ rS rSrSr\" S5      r\" \5      r	\S 5       r
Srg)_aliasrulesii  z2Parsing and expansion rule set of template aliasess   template aliasc                    U S   S:X  a"  U S   S   S:X  a  U S   S   [        U S   5      4$ U S   S:X  a  U S   S   S:X  a  U S   S   U S   /4$ gg)zFReturn (name, args) if tree is func(...) or ...|filter; otherwise
Noner   r   r   r.   r+   r   Nr   r   s    rL   _trygetfunc_aliasrules._trygetfunco  su     7g$q'!*	"971:wtAw///7d?tAwqzY671:Qy((  7?rX   rf   N)__name__
__module____qualname____firstlineno____doc__r   _sectionstaticmethodr   _parser  __static_attributes__rf   rX   rL   r  r  i  s,    <"#H*%F) )rX   r  c                V    [         R                  U5      n[         R                  X 5      $ )z'Return new tree of aliases are expanded)r  r   expand)r   aliasesaliasmaps      rL   expandaliasesr!  y  s#    ##G,Hh--rX   c                X    [        U 5      S:  d  U S   S;  d  U S   U S   :w  a  U $ U SS $ )z9unwrap quotes if any; otherwise returns unmodified stringr+   r      '"r   )r>   )rF   s    rL   unquotestringr%    s6    
1vzQqT'1Q41R5=Qr7NrX   c                      \ rS rSrSr\R                  r\R                  S 5       r	\R                  S 5       r
\R                  S 5       r\R                  S 5       rSrg)	resourcemapperi  z%Mapper of internal template resourcesc                    g)BReturn a set of available resource keys based on the given mappingNrf   selfr   s     rL   availablekeysresourcemapper.availablekeys      rX   c                    g)'Return a set of supported resource keysNrf   r+  s    rL   	knownkeysresourcemapper.knownkeys  r.  rX   c                    g)z:Return a resource for the key if available; otherwise NoneNrf   r+  r   rj   s      rL   lookupresourcemapper.lookup  r.  rX   c                    g)z[Return a dict of additional mapping items which should be paired
with the given new mappingNrf   r+  r   origmapping
newmappings       rL   populatemapresourcemapper.populatemap  r.  rX   rf   N)r  r  r  r  r  abcABCMeta__metaclass__abstractmethodr,  r2  r6  r<  r  rf   rX   rL   r'  r'    sx    /KKMQ Q 	6 6 	I I 	& &rX   r'  c                  ,    \ rS rSrS rS rS rS rSrg)nullresourcemapperi  c                    [        5       $ r`   setr*  s     rL   r,   nullresourcemapper.availablekeys  	    urX   c                    [        5       $ r`   rE  r1  s    rL   r2  nullresourcemapper.knownkeys  rH  rX   c                    g r`   rf   r5  s      rL   r6  nullresourcemapper.lookup  s    rX   c                    0 $ r`   rf   r9  s       rL   r<  nullresourcemapper.populatemap  s    	rX   rf   N)	r  r  r  r  r,  r2  r6  r<  r  rf   rX   rL   rC  rC    s    rX   rC  c                  j    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rSrg)enginei  ax  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|...}.Nc                    Xl         Uc  0 nX l        [        R                  U l        Uc  0 nUc
  [        5       nX0l        X@l        0 U l        0 U l	        g r`   )
_loaderr   r   funcsr   rC  	_defaults
_resources_cache
_tmplcache)r+  loaderfiltersdefaults	resourcess        rL   __init__engine.__init__  sT    ?G#))H*,I!#rX   c           	        U R                   R                  5       nU R                   R                  U5      nUR                  5        VVs0 s H3  u  pVXS;   d'  UR	                  U R                  U5      5      (       d  M1  XV_M5     nnnUR                  U5        UR                  U R                   R                  XU5      5        U$ s  snnf )z^Create combined mapping from the original mapping and partial
mapping to override the original)rU  r2  r,  r   
isdisjoint_defaultrequiresr   r<  )r+  r:  r;  knownresnewresr   vr   s           rL   
overlaymapengine.overlaymap  s    
 ??,,...z: $))+
+$$T%:%:1%=>	 AD+ 	 
 	z"OO'':F	
 
s   	0C=Cc                z    U R                   R                  U5      nUb  [        U5      (       d  g[        USS5      $ )z?Resource keys required by the specified default symbol functionrf   	_requires)rT  getcallablegetattr)r+  rj   rc  s      rL   r`  engine._defaultrequires  s5    NNs#9HQKKq+r**rX   c                    SnX R                   R                  5       ;  a  UR                  U5      nUc  U R                  R                  U5      nU$ )z:Resolve symbol to value or function; None if nothing foundN)rU  r2  rh  rT  r+  r   rj   rc  s       rL   symbolengine.symbol  sF    oo//11C A9""3'ArX   c                8    U R                   R                  U5      $ )r)  )rU  r,  r*  s     rL   availableresourcekeysengine.availableresourcekeys  s    ,,W55rX   c                6    U R                   R                  5       $ )r0  )rU  r2  r1  s    rL   knownresourcekeysengine.knownresourcekeys  s    ((**rX   c                    U R                   R                  X5      nUc"  [        R                  " [	        S5      U-  5      eU$ )zFReturn internal data (e.g. cache) used for keyword/function
evaluations#   template resource not available: %s)rU  r6  r   ResourceUnavailabler   rm  s       rL   resourceengine.resource  sE     OO""7092289C?  rX   c                    XR                   ;  aD  U R                  U5      n[        U4U R                   U'    [        X [        5      U R                   U'   U R                   U   $ !   U R                   U	 e = f)z!load, parse, and cache a template)rV  rR  r   r   r   )r+  r   r   s      rL   r   engine._load  si    KKQA115DKKN!+AW!=A {{1~KKNs   A# #A3c                    XR                   ;  a(  [        U5      n[        X [        5      U R                   U'   U R                   U   $ )z"Parse and cache a literal template)rW  rq   r   r   r+  rS   r   s      rL   r  engine._parse  s9    &dA$.q$@DOOD!t$$rX   c                \     U R                  U5        g! [        R                   a     gf = f)z:Load, parse, and cache the specified template if availableTF)r   r   TemplateNotFoundr+  r   s     rL   preloadengine.preload  s-    	JJqM,, 		s    ++c                L    U R                  U5      u  p4U R                  X4U5      $ )zPerform expansion. t is name of map element to expand.
mapping contains added elements for use during expansion. Is a
generator.)r   _expand)r+  r   r   r   rG   s        rL   processengine.process$  s$     ZZ]
||D00rX   c                L    U R                  U5      u  p4U R                  X4U5      $ )zPerform expansion over a literal template

No user aliases will be expanded since this is supposed to be called
with an internal template string.
)r  r  )r+  rS   r   r   rG   s        rL   r  engine.expand+  s%     [[&
||D00rX   c           	         U R                   R                  U 0 U5      nU(       a  UR                  U5        Un[        R                  " XU" XU5      5      $ r`   )rU  r<  r   r   flatten)r+  r   rG   r   extramappings        rL   r  engine._expand4  sL     224WE("G##D4t3LMMrX   )rV  rT  r   r   rR  rU  rW  )NNN)r  r  r  r  r  r\  rd  r`  rn  rq  rt  rx  r   r  r  r  r  r  r  rf   rX   rL   rP  rP    sI    "&*+6+%11NrX   rP  c                 &   [        5       n U (       d  [        S5      $ [        R                  " U 5      n/ nU H>  nUR	                  S5      nUS   S;   a  M  US   S:X  d  M*  UR                  US   5        M@     SR                  [        U5      5      $ )	Ns7   no templates found, try `hg debuginstall` for more infor   r$  )s   origs   rejr   s   map-cmdliner   s   , )templatedirr   oslistdirsplitrQ   joinsorted)pathdirlist	stylelistfiler  s        rL   r  r  ?  s    =DKLLjjGI

4 9))8~%U1X&  ::fY'((rX   c                    [         R                  R                  U 5      (       a  [        R                  " U S5      $ [
        R                  " [        S5      U -  [        S5      [        5       -  S9e)N   rbs   style '%s' not founds   available styles: %sr   )	r  r  existsr   	posixfiler   Abortr   r  )mapfiles    rL   _open_mapfiler  N  sU    	ww~~g~~gu--
++	
!"W,&')+5 rX   c                $  ^^^ [         R                  (       a0  UR                  [         R                  5      nSR	                  U5      n[
        R                  R                  U5      m[        R                  " 5       mUUU4S jmU R                  5       nTR                  XSS0TS9  0 n0 n/ nTR                  SS5      nU(       GaW  US   S;  GaM  [
        R                  R                  [
        R                  R	                  TU5      5      n[
        R                  R                  U5      (       d  [        5       n	U	b  [
        R                  R                  [
        R                  R	                  X5      5      n
[
        R                  R                  U
5      (       a  U
nOc[
        R                  R                  [
        R                  R	                  U
S	5      5      n[
        R                  R                  U5      (       a  Un[!        U5      n [#        X5      u  pEnTR%                  S5       H  u  pU(       d0  [&        R(                  " [+        S
5      TR-                  SU5      5      eUS   S;   aK  US   US   :w  a0  [&        R(                  " [+        S5      TR-                  SU5      5      e[/        U5      XL'   M  US:w  d  M  [
        R                  R	                  TU5      X\'   M     UR1                  TR%                  S5      5        XEU4$ )z.Load template elements from the given map filer!   c                  > S nT(       ax  [         R                  R                  [         R                  R                  TU 5      5      n[         R                  R	                  U5      (       a  [
        R                  " US5      nU(       d  [        R                  U ;  a  U n [        R                  " SU 5      nO[        5       nU(       aw  [         R                  R                  [         R                  R                  XP5      5      n[         R                  R	                  U5      (       a  [
        R                  " US5      nU(       a$  UR                  5       nTR                  WUUUT	S9  g g ! [         a    S n N:f = f)Nr  s   mercurial.templates)sectionsremapinclude)r  r  normpathr  isfiler   r  r   ossepr   open_resourcer	   r  readrq   )
relr  r  subresourceabsdirrG   baseconfr  s
          rL   r  _readmapfile.<locals>.includec  s   ''""277<<c#:;Cww~~c"""nnS%8~~S('"."<"<.#K "m''**277<<+ABCww~~c**&*nnS%&@##%DJJ!    ) '"&K's   !E- -E<;E<rX   	   templates)r  r  s   __base__r   r#  s   maps   missing valuer$  s   unmatched quotess   templatealias)r   	iswindowsr  r  r  r  r  dirnamer
   r  rq   rh  r  r  r  r  r  _readmapfiler   r   r:   r   sourcer%  extend)fpr  
name_pathsrG   cachetmapr  rW   r  r  p2p3rj   r  r  r  s                @@@rL   r  r  W  sI   
 ]]8>>2
))J'77??7#D==?D> 779DJJwS,$7JIEDG
((<
-C
s1vV#wwT3 78 ww~~d##-CWW%%bggll3&<=77>>"%%D))"'',,r6*BCBww~~b))!4 +B5WJJ|,"""#T[[s%C  q6V1vR &&)*DKKc,J  's+EJKT3/DI - NN4::./0rX   c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)rX  i  z2Load template fragments optionally from a map filec                z    Uc  0 nUR                  5       U l        0 U l        [        R	                  U5      U l        g r`   )copyr  _mapr  r   	_aliasmap)r+  r  r  s      rL   r\  loader.__init__  s2    =EZZ\
	$--g6rX   c                H    XR                   ;   =(       d    XR                  ;   $ r`   )r  r  r+  rj   s     rL   __contains__loader.__contains__  s    jj 4C99$44rX   c                >   XR                   ;  a8   [        U R                  U   5      u  p#UR                  5       U R                   U'   U R                  U R                   U   5      $ ! [         a4  n[
        R                  " [        S5      UR                  S   -  5      eSnAf[         ap  n[        S5      U R                  U   [        R                  " UR                  S   5      4-  n[        UR                  S   [        R                  " U5      5      eSnAff = f)?Get parsed tree for the given template name. Use a local cache.s   "%s" not in template mapr   Ns   template file %s: %sr   )r  open_templater  r  KeyErrorr   r  r   r   OSErrorr   forcebytestrr   strfromlocalr  )r+  r   r  r  rx   reasons         rL   loadloader.load  s    JJK+DIIaL9 "	

1 {{4::a=))  "3312TYYq\A   K23IIaL++DIIaL97  diilH,A,A&,IJJKs$   7A& &
D0/BD,A+DDc                ~    [        U5      nU R                  (       a   [        R                  U R                  U5      nU$ r`   )rq   r  r  r  r}  s      rL   r  loader._parse  s-    $K>>""4>>15ArX   c                &   U(       d  g US   nUS:X  ab  US   nXBS   ;   a  g US   R                  U5        X@R                  ;   d  X@R                  ;   a!  U R                  U R	                  U5      U5        g US;   a  g US:X  a6  US   R                  [        US   5      5        U R                  US   U5        g US:X  a6  US   R                  [        US   5      5        U R                  US   U5        g USS   H  nU R                  XR5        M     g )Nr   r.   r   >   r/   r-   r   r+   r   )addr  r  _findsymbolsusedr  r   )r+  r   symsr   rF   r   s         rL   r  loader._findsymbolsused  s    !W?QAG|GKKNJJ!yy.%%diilD9((:GKK	$q'*+!!$q'40=GKK	$q'*+!!$q'40abA!!!* rX   c                p    [        5       [        5       4nU R                  U R                  U5      U5        U$ zLook up (keywords, filters/functions) referenced from the name
template 't'

This may load additional templates from the map file.
)rF  r  r  )r+  r   r  s      rL   symbolsusedloader.symbolsused  s.     su~diilD1rX   )r  r  r  N)r  r  r  r  r  r\  r  r  r  r  r  r  rf   rX   rL   rX  rX    s#    <75*$+6rX   rX  c                      \ rS rSr       SS jr\       SS j5       rS r\S 5       r	\S 5       r
\S 5       rS	 rS
 rS rS rS rS rSrg)	templateri  Nc                    [         R                  R                  5       nU(       a  UR                  U5        [	        XE5      U l        [        U R
                  R                  XU5      U l        XgsU l	        U l
        g)a  Create template engine optionally with preloaded template fragments

- ``filters``: a dict of functions to transform a value into another.
- ``defaults``: a dict of symbol values/functions; may be overridden
  by a ``mapping`` dict.
- ``resources``: a resourcemapper object to look up internal data
  (e.g. cache), inaccessible from user template.
- ``cache``: a dict of preloaded template fragments.
- ``aliases``: a list of alias (name, replacement) pairs.

self.cache may be updated later to register additional template
fragments.
N)r   rY  r  r   rX  rR  rP  r  _proc	_minchunk	_maxchunk)	r+  rY  rZ  r[  r  r  minchunkmaxchunk
allfilterss	            rL   r\  templater.__init__  s]    . %,,113
g&e-DLL--zYO
)1&rX   c	           	        U " X4XV/ Xx5      n	U(       d  [        U5      n[        X!5      u  pjnU	R                  R                  R	                  U5        XR                  l        [        R                  U5      U	R                  l        U	$ )z,Create templater from the specified map file)	r  r  rR  r  r   r  r  r   r  )clsr  r  rY  rZ  r[  r  r  r  r   r  r  s               rL   frommapfiletemplater.frommapfile  sk     9RLw'B+B8W			u%		)227;		rX   c                    XR                   ;   $ r`   )rR  r  s     rL   r  templater.__contains__.  s    ll""rX   c                .    U R                   R                  $ r`   )rR  r  r1  s    rL   r  templater.cache1  s    ||!!!rX   c                .    U R                   R                  $ r`   )r  r   r1  s    rL   r   templater._filters6  s    zz"""rX   c                .    U R                   R                  $ r`   )r  rT  r1  s    rL   rZ  templater.defaults:  s    zz###rX   c                8    U R                   R                  U5      $ )r  )rR  r  r  s     rL   r  templater.load>  s    ||  ##rX   c                $    U R                  S5      $ )zLook up (keywords, filters/functions) referenced from the default
unnamed template

This may load additional templates from the map file.
rX   )r  r1  s    rL   symbolsuseddefaulttemplater.symbolsuseddefaultB  s     $$rX   c                8    U R                   R                  U5      $ r  )rR  r  r  s     rL   r  templater.symbolsusedJ  s     ||''**rX   c                &    U R                  SU5      $ )z?Render the default unnamed template and return result as stringrX   )renderr*  s     rL   renderdefaulttemplater.renderdefaultR  s    {{3((rX   c                B    SR                  U R                  X5      5      $ )z?Render the specified named template and return result as stringrX   )r  generate)r+  r   r   s      rL   r  templater.renderV  s    xxa122rX   c                    U R                   R                  X5      nU R                  (       a)  [        R                  " X0R                  U R
                  S9nU$ )zNReturn a generator that renders the specified named template and
yields chunks)ro   max)r  r  r  r   increasingchunksr  )r+  r   r   streams       rL   r  templater.generateZ  sC     ##A/>>**NNF rX   )rR  r  r  r  )NNNNrf         )NNNNNr  r  )r  r  r  r  r\  classmethodr  r  propertyr  r   rZ  r  r  r  r  r  r  r  rf   rX   rL   r  r    s     <<   *# " " # # $ $$%+)3rX   r  c                     [         R                  R                  [         R                  R                  [        R
                  S5      5      n [         R                  R                  U 5      (       a  U $ S$ )z6return the directory used for template files, or None.r  N)r  r  r  r  r   datapathisdir)r  s    rL   r  r  e  sH    77BGGLL)>)>MND77==&&40D0rX   c                4   [         R                  R                  U 5      (       d$  [         R                  R                  U 5      (       a  U [	        U SS94$ Uc
  [        5       nUb+  [         R                  R                  X5      nU[	        USS94$ [        R                  (       a0  U R                  [        R                  5      nSR                  U5      n U R                  S5      nSR                  SS/USS -   5      nU [        R                  " XTS   5      4$ )	zreturns a file-like object for the given template, and its full path

If the name is a relative path and we're in a frozen binary, the template
will be read from the mercurial.templates package instead. The returned path
will then be the relative path.
rb)modeNr!   r   s	   mercurialr  r$  )r  r  r  isabsopenr  r  r   r  r  r  r   r  )nametemplatepathr   r  
name_partspackage_names         rL   r  r  k  s     
ww~~drww}}T22T$T*** "}GGLL,$qt$$$ 
 ZZ/
yy$D!J99lL9JsOKLL""<B@ rX   c                F     [        X5      $ ! [        [        4 a     gf = f)N)NN)r  r  ImportError)r  r  s     rL   try_open_templater    s)    T00[! s   
   r`   )rX   )F)rX   F)r  bytesr  Optional[bytes]returnzTuple[bytes, BinaryIO])r  r  r  r  r  z*Tuple[Optional[bytes], Optional[BinaryIO]])Er  
__future__r   r>  r  typingr   r   r   i18nr   r   r	    r
   r   r   r   r   r   r   r   utilsr   r   rn   rM   r9   r\   rP   rr   r   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   basealiasrulesr  r!  r%  r'  rC  rP  r  r  r  rX  r  r  r  r  rf   rX   rL   <module>r!     s=  :x # 
 	  
 
 

C 	
, 	
,	
 	
, 	
* 	
* 	
* 	
5 	
1 	
- 	
% 1 / /  3!" '#*hVG4G:1hN  F6>%I'G
>M-

</2)
=<+\M<: : 	
 ; 	+ 	+ 	( Y " Y 	
@ 	
@ { 	
@  	
A!( 


!),
 )&'' ) .& &. NN NNb)T nH HVi iX1 26"
".""L 26
./rX   