
    6hni                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
JrJr  SSKJr  \R                  (       a  SSKrSSKJrJrJrJrJrJrJr  SS	KJrJrJr  S
 r " S S5      r " S S5      rS r " S S\5      r S r! " S S5      r" " S S\5      r# " S S\5      r$ " S S\5      r% " S S\5      r& " S S\5      r' " S S 5      r( " S! S"\5      r)\RT                  " S#S$9 " S% S&5      5       r+S' r,S6S( jr-S) r.S6S* jr/S+ r0S, r1S7S- jr2S7S. jr3\4" 5       r5 " S/ S0\Rl                  5      r7   S8S1 jr8S2 r9\Rt                  S3 5       r;\Rt                  S4 5       r<S5 r=g)9a~  Generic output formatting for Mercurial

The formatter provides API to show data in various ways. The following
functions should be used in place of ui.write():

- fm.write() for unconditional output
- fm.condwrite() to show some extra data conditionally in plain output
- fm.context() to provide changectx to template output
- fm.data() to provide extra data to JSON or template output
- fm.plain() to show raw text that isn't provided to JSON or template output

To show structured data (e.g. date tuples, dicts, lists), apply fm.format*()
beforehand so the data is converted to the appropriate data type. Use
fm.isplain() if you need to convert or format data conditionally which isn't
supported by the formatter API.

To build nested structure (i.e. a list of dicts), use fm.nested().

See also https://www.mercurial-scm.org/wiki/GenericTemplatingPlan

fm.condwrite() vs 'if cond:':

In most cases, use fm.condwrite() so users can selectively show the data
in template output. If it's costly to build data, use plain 'if cond:' with
fm.write().

fm.nested() vs fm.formatdict() (or fm.formatlist()):

fm.nested() should be used to form a tree structure (a list of dicts of
lists of dicts...) which can be accessed through template keywords, e.g.
"{foo % "{bar % {...}} {baz % {...}}"}". On the other hand, fm.formatdict()
exports a dict-type object to template, which can be accessed by e.g.
"{get(foo, key)}" function.

Doctest helper:

>>> def show(fn, verbose=False, **opts):
...     import sys
...     from . import ui as uimod
...     ui = uimod.ui()
...     ui.verbose = verbose
...     ui.pushbuffer()
...     try:
...         return fn(ui, ui.formatter(pycompat.sysbytes(fn.__name__),
...                   pycompat.byteskwargs(opts)))
...     finally:
...         print(pycompat.sysstr(ui.popbuffer()), end='')

Basic example:

>>> def files(ui, fm):
...     files = [(b'foo', 123, (0, 0)), (b'bar', 456, (1, 0))]
...     for f in files:
...         fm.startitem()
...         fm.write(b'path', b'%s', f[0])
...         fm.condwrite(ui.verbose, b'date', b'  %s',
...                      fm.formatdate(f[2], b'%Y-%m-%d %H:%M:%S'))
...         fm.data(size=f[1])
...         fm.plain(b'\n')
...     fm.end()
>>> show(files)
foo
bar
>>> show(files, verbose=True)
foo  1970-01-01 00:00:00
bar  1970-01-01 00:00:01
>>> show(files, template=b'json')
[
 {
  "date": [0, 0],
  "path": "foo",
  "size": 123
 },
 {
  "date": [1, 0],
  "path": "bar",
  "size": 456
 }
]
>>> show(files, template=b'path: {path}\ndate: {date|rfc3339date}\n')
path: foo
date: 1970-01-01T00:00:00+00:00
path: bar
date: 1970-01-01T00:00:01+00:00

Nested example:

>>> def subrepos(ui, fm):
...     fm.startitem()
...     fm.write(b'reponame', b'[%s]\n', b'baz')
...     files(ui, fm.nested(b'files', tmpl=b'{reponame}'))
...     fm.end()
>>> show(subrepos)
[baz]
foo
bar
>>> show(subrepos, template=b'{reponame}: {join(files % "{path}", ", ")}\n')
baz: foo, bar
    )annotationsN   )_)hexshort)attr)errorpycompattemplatefilters
templatekw	templatertemplateutilutil)cborutildateutil
stringutilc                V    [        U [        S5      [        [        [        [
        45      $ )zCheck if the given object can be directly passed in to formatter's
write() and data() functions

Returns False if the object is unsupported or must be pre-processed by
formatdate(), formatdict(), or formatlist().
N)
isinstancetypeboolintfloatbytes)objs    5/usr/lib/python3/dist-packages/mercurial/formatter.pyisprintabler      s      cDJc5%@AA    c                  \    \ rS rSrSrSr\S 5       r\S 5       r\S 5       r	\S 5       r
Srg	)
_nullconverter   z=convert non-primitive data types to be processed by formatterFc                    U $ )z$wrap nested data by appropriate type datatmplseps      r   
wrapnested_nullconverter.wrapnested   s	     r   c                $    U u  p#[        U5      U4$ z(convert date tuple to appropriate format)r   )datefmttstzs       r   
formatdate_nullconverter.formatdate   s     B}r   c                    [        U 5      $ z:convert dict or key-value pairs to appropriate dict format)dict)r$   keyvaluer,   r&   s        r   
formatdict_nullconverter.formatdict   s    
 Dzr   c                    [        U 5      $ z+convert iterable to appropriate list format)list)r$   namer,   r&   s       r   
formatlist_nullconverter.formatlist   s     Dzr   r"   N__name__
__module____qualname____firstlineno____doc__storecontextstaticmethodr'   r/   r6   r<   __static_attributes__r"   r   r   r   r      sZ    G L       r   r   c                      \ rS rSrSrS rS rS rS rS r	SS jr
SS
 jrSS jrS rS rS rS rS rS rS rSS jrS rSrg	)baseformatter   Fc                X    Xl         X l        X0l        X@l        S U l        [
        U l        g N)_ui_topic_opts
_converter_itemr   hexfunc)selfuitopicopts	converters        r   __init__baseformatter.__init__   s$    
#
r   c                    U $ rK   r"   rR   s    r   	__enter__baseformatter.__enter__   s    r   c                ,    Uc  U R                  5         g g rK   )end)rR   exctypeexcvalue	tracebacks       r   __exit__baseformatter.__exit__   s    ?HHJ r   c                    g)z0show a formatted item once all data is collectedNr"   rZ   s    r   	_showitembaseformatter._showitem       r   c                L    U R                   b  U R                  5         0 U l         g)z begin an item in the format listNrP   re   rZ   s    r   	startitembaseformatter.startitem   s    ::!NN
r   c                8    U R                   R                  X5      $ r*   )rO   r/   )rR   r+   r,   s      r   r/   baseformatter.formatdate   s    ))$44r   Nc                <    U R                   R                  XX4U5      $ r2   )rO   r6   )rR   r$   r4   r5   r,   r&   s         r   r6   baseformatter.formatdict   s    ))$UEEr   c                :    U R                   R                  XX45      $ r9   )rO   r<   )rR   r$   r;   r,   r&   s        r   r<   baseformatter.formatlist   s     ))$c??r   c                X   [         R                  " U5      n[        S U 5       5      (       d   eU R                  R                  (       a`  SU;   a  SU;  a  US   R                  5       US'   SU;   a  SU;  a  US   R                  5       US'   U R                  R                  U5        gg)z=insert context objects to be used to render template keywordsc              3  *   #    U  H	  oS ;   v   M     g7f)>      ctx   fctx   repoNr"   ).0ks     r   	<genexpr>(baseformatter.context.<locals>.<genexpr>   s     ADq22Ds   ru   rt   rv   N)	r
   byteskwargsallrO   rD   	changectxreporP   update)rR   ctxss     r   contextbaseformatter.context   s    ##D)ADAAAAA??''$6#5#G}668V~'"5 $V 1 1 3WJJd# (r   c                    [        5       $ )z#set of field names to be referenced)setrZ   s    r   datahintbaseformatter.datahint   s	    ur   c                f    [         R                  " U5      nU R                  R                  U5        g)z8insert data into item that's not shown in default outputN)r
   r{   rP   r   rR   r$   s     r   r$   baseformatter.data   s$    ##D)

$r   c                    UR                  5       n[        U5      [        U5      :X  d   XS45       eU R                  R                  [	        XS5      5        g)z3do default text output while assigning data to itemNsplitlenrP   r   zip)rR   fieldsdeftext	fielddatarU   	fieldkeyss         r   writebaseformatter.write   sB    LLN	9~Y/G)1GG/

#i34r   c                    UR                  5       n[        U5      [        U5      :X  d   eU R                  R                  [	        Xd5      5        g)z4do conditional write (primarily for plain formatter)Nr   )rR   condr   r   r   rU   r   s          r   	condwritebaseformatter.condwrite   s:    LLN	9~Y///

#i34r   c                    g)z$show raw text for non-templated modeNr"   rR   textrU   s      r   plainbaseformatter.plain  rg   r   c                    g)zcheck for plain formatter usageFr"   rZ   s    r   isplainbaseformatter.isplain	  s    r   c                    / nU R                   R                  XBU5      U R                  U'   [        U R                  U R                   U5      $ )z9sub formatter to store nested data in the specified field)rO   r'   rP   _nestedformatterrL   )rR   fieldr%   r&   r$   s        r   nestedbaseformatter.nested  s=     OO66t3G

5$//4@@r   c                @    U R                   b  U R                  5         gg)zend output for the formatterNri   rZ   s    r   r^   baseformatter.end  s    ::!NN "r   )rO   rP   rN   rM   rL   rQ   )s   %a %b %d %H:%M:%S %Y %1%2)s   keys   valueN    )Nr   Nr   )r?   r@   rA   rB   strict_formatrW   r[   rb   re   rj   r/   r6   r<   r   r   r$   r   r   r   r   r   r^   rF   r"   r   r   rH   rH      sa     M?5F@
$ 
553Ar   rH   c                     [        XU[        S9$ )zformatter that prints nothing)rV   )rH   r   )rS   rT   rU   s      r   nullformatterr     s    DNCCr   c                  $    \ rS rSrSrS rS rSrg)r   i  z6build sub items and store them in the parent formatterc                <    [         R                  XS0 US9  X0l        g )Nr   )rT   rU   rV   )rH   rW   _data)rR   rS   rV   r$   s       r   rW   _nestedformatter.__init__!  s%    CbI 	 	
 
r   c                N    U R                   R                  U R                  5        g rK   r   appendrP   rZ   s    r   re   _nestedformatter._showitem'      

$**%r   )r   N)r?   r@   rA   rB   rC   rW   re   rF   r"   r   r   r   r     s    @&r   r   c                b    [        U [        5      (       a  [        U R                  5       5      $ U $ )z'iterate key-value pairs in stable order)r   r3   sorteditems)r$   s    r   
_iteritemsr   +  s%    $djjl##Kr   c                  \    \ rS rSrSrSr\S 5       r\S 5       r\S 5       r	\S 5       r
Srg	)
_plainconverteri2  z(convert non-primitive data types to textFc                .    [         R                  " S5      e)Ns%   plainformatter should never be nested)r	   ProgrammingErrorr#   s      r   r'   _plainconverter.wrapnested7  s    $$%MNNr   c                .    [         R                  " X5      $ )z(stringify date tuple in the given format)r   datestrr+   r,   s     r   r/   _plainconverter.formatdate;  s     **r   c                   ^^ [         R                  mTc  Sm[         R                  mUR                  UU4S j[	        U 5       5       5      $ )z*stringify key-value pairs separated by seps   %s=%sc              3  N   >#    U  H  u  pTT" U5      T" U5      4-  v   M     g 7frK   r"   )rw   rx   vr,   prefmts      r   ry   -_plainconverter.formatdict.<locals>.<genexpr>G  s)      
5ETQC6!9fQi((5Es   "%)r
   identitybytestrjoinr   )r$   r4   r5   r,   r&   r   s      ` @r   r6   _plainconverter.formatdict@  sH     "";C%%Fxx 
5?5E
 
 	
r   c                   ^^ [         R                  mTc  Sm[         R                  mUR                  UU4S jU  5       5      $ )z#stringify iterable separated by seps   %sc              3  :   >#    U  H  nTT" U5      -  v   M     g 7frK   r"   )rw   er,   r   s     r   ry   -_plainconverter.formatlist.<locals>.<genexpr>R  s     6AfQis   )r
   r   r   r   )r$   r;   r,   r&   r   s     ` @r   r<   _plainconverter.formatlistK  s:     "";C%%Fxx6666r   r"   Nr>   r"   r   r   r   r   2  sZ    2LO O + + 
 
 7 7r   r   c                  R    \ rS rSrSrS rS rS rS rS r	S r
S	 rSS jrS rSrg
)plainformatteriU  zthe default text output schemec                   ^ [         R                  XX4[        5        UR                  (       a  [        U l        O[        U l        UTL a  UR                  U l        g U4S jU l        g )Nc                &   > TR                  U 5      $ rK   )r   )srU   outs     r   <lambda>)plainformatter.__init__.<locals>.<lambda>a  s    CIIaLr   )	rH   rW   r   	debugflagr   rQ   r   r   _writerR   rS   r   rT   rU   s     `  r   rW   plainformatter.__init__X  sC    toF<<DL DL9((DK8DKr   c                    g rK   r"   rZ   s    r   rj   plainformatter.startitemc      r   c                    g rK   r"   r   s     r   r$   plainformatter.dataf  r   r   c                .    U R                   " X#-  40 UD6  g rK   r   )rR   r   r   r   rU   s        r   r   plainformatter.writei  s    G'040r   c                >    U(       a  U R                   " X4-  40 UD6  gg)zdo conditional writeNr   )rR   r   r   r   r   rU   s         r   r   plainformatter.condwritel  s    KK+4t4 r   c                *    U R                   " U40 UD6  g rK   r   r   s      r   r   plainformatter.plainq  s    D!D!r   c                    g)NTr"   rZ   s    r   r   plainformatter.isplaint  s    r   Nc                    U $ rK   r"   )rR   r   r%   r&   s       r   r   plainformatter.nestedw  s    r   c                    g rK   r"   rZ   s    r   r^   plainformatter.end{  r   r   )r   rQ   r   )r?   r@   rA   rB   rC   rW   rj   r$   r   r   r   r   r   r^   rF   r"   r   r   r   r   U  s2    (	915
"r   r   c                  &    \ rS rSrS rS rS rSrg)debugformatteri  c                    [         R                  XX4[        5        X l        U R                  R	                  SU R
                  -  5        g )Ns   %s = [
)rH   rW   r   _outr   rM   r   s        r   rW   debugformatter.__init__  s2    tnE			dkk12r   c           	     |    U R                   R                  S[        R                  " U R                  SSS9-  5        g )Ns       %s,
   r   )indentlevel)r   r   r   pprintrP   rZ   s    r   re   debugformatter._showitem  s-    		:,,TZZKK	
r   c                d    [         R                  U 5        U R                  R                  S5        g )Ns   ]
rH   r^   r   r   rZ   s    r   r^   debugformatter.end  s     $		r   r   Nr?   r@   rA   rB   rW   re   r^   rF   r"   r   r   r   r     s    3


 r   r   c                  &    \ rS rSrS rS rS rSrg)pickleformatteri  c                T    [         R                  XX4[        5        X l        / U l        g rK   )rH   rW   r   r   r   r   s        r   rW   pickleformatter.__init__  s     tnE	
r   c                N    U R                   R                  U R                  5        g rK   r   rZ   s    r   re   pickleformatter._showitem  r   r   c                    [         R                  U 5        U R                  R                  [        R
                  " U R                  5      5        g rK   )rH   r^   r   r   pickledumpsr   rZ   s    r   r^   pickleformatter.end  s-    $		TZZ01r   )r   r   Nr   r"   r   r   r   r     s    
&2r   r   c                  *    \ rS rSrSrS rS rS rSrg)cborformatteri  z2serialize items as an indefinite-length CBOR arrayc                    [         R                  XX4[        5        X l        U R                  R	                  [
        R                  5        g rK   )rH   rW   r   r   r   r   BEGIN_INDEFINITE_ARRAYr   s        r   rW   cborformatter.__init__  s/    tnE			778r   c                    U R                   R                  SR                  [        R                  " U R
                  5      5      5        g r   )r   r   r   r   streamencoderP   rZ   s    r   re   cborformatter._showitem  s*    		!6!6tzz!BCDr   c                    [         R                  U 5        U R                  R                  [        R
                  5        g rK   )rH   r^   r   r   r   BREAKrZ   s    r   r^   cborformatter.end  s$    $		'r   r   N)	r?   r@   rA   rB   rC   rW   re   r^   rF   r"   r   r   r
  r
    s    <9
E(r   r
  c                  *    \ rS rSrSrS rS rS rSrg)jsonformatteri  Tc                    [         R                  XX4[        5        X l        U R                  R	                  S5        SU l        g )N   [T)rH   rW   r   r   r   _firstr   s        r   rW   jsonformatter.__init__  s0    tnE			r   c                   U R                   (       a  SU l         OU R                  R                  S5        U R                  R                  S5        Sn[        U R                  R                  5       5       H^  u  p#U(       a  SnOU R                  R                  S5        [        R                  " USS9nU R                  R                  SX$4-  5        M`     U R                  R                  S5        g )	NF   ,s   
 {
Ts   ,
)paranoids
     "%s": %ss   
 })r  r   r   r   rP   r   r   json)rR   firstrx   r   us        r   re   jsonformatter._showitem  s    ;;DKIIOOD!			"4::++-.DA		'$$Q7AIIOOMQF23 / 			 r   c                d    [         R                  U 5        U R                  R                  S5        g )N   
]
r   rZ   s    r   r^   jsonformatter.end  s     $		!r   )r  r   N)	r?   r@   rA   rB   r   rW   re   r^   rF   r"   r   r   r  r    s    M!""r   r  c                  \    \ rS rSrSrSr\S 5       r\S 5       r\S 5       r	\S 5       r
Srg	)
_templateconverteri  z=convert non-primitive data types to be processed by templaterTc                ,    [         R                  " XUS9$ )z$wrap nested data by templatable type)r%   r&   )r   mappinglistr#   s      r   r'   _templateconverter.wrapnested  s     ''SAAr   c                .    [         R                  " U 5      $ )zreturn date tuple)r   r+   r   s     r   r/   _templateconverter.formatdate  s       &&r   c                   ^ ^^^^ [         R                  " [        T 5      5      m U UUUU4S jn[        R                  " T TTTUS9$ )zAbuild object that can be evaluated as either plain string or dictc               3  D   >#    [         R                  T TTTT5      v   g 7frK   )r   r6   )r$   r,   r4   r&   r5   s   r   f(_templateconverter.formatdict.<locals>.f  s     !,,T3sCHHs    )r4   r5   r,   gen)r   sortdictr   r   
hybriddict)r$   r4   r5   r,   r&   r-  s   ````` r   r6   _templateconverter.formatdict  sD     }}Z-.	I 	I &&cCQ
 	
r   c                `   ^ ^^^ [        T 5      m U UUU4S jn[        R                  " T TTUS9$ )zAbuild object that can be evaluated as either plain string or listc               3  B   >#    [         R                  T TTT5      v   g 7frK   )r   r<   )r$   r,   r;   r&   s   r   r-  (_templateconverter.formatlist.<locals>.f  s     !,,T4cBBs   )r;   r,   r/  )r:   r   
hybridlist)r$   r;   r,   r&   r-  s   ```` r   r<   _templateconverter.formatlist  s3     Dz	C 	C &&t$CQGGr   r"   Nr>   r"   r   r   r%  r%    s\    GLB B ' ' 	
 	
 H Hr   r%  c                  Z    \ rS rSrS
S jrS rS r\R                  S 5       r	S r
S rS	rg)templateformatteri  Nc                   [         R                  XX4[        5        X l        UR                  U l        [        UU[        R                  [        U5      [        R                  S9U l        U(       a%  U R                  R                  R                  U5        [        XPR                  / SQ5      U l        [         R"                  " 5       U l        U R'                  S0 5        g )Ndefaults	resourcescache)	   docheader	   docfooter	   separatorr?  )rH   rW   r%  r   ref_trefloadtemplaterr   keywordstemplateresourcesdefaulttempl_tr>  r   templatepartsmap_parts	itertoolscount_counter_renderitem)rR   rS   r   rT   rU   specoverridetemplatess          r   rW   templateformatter.__init__  s    t6HI	XX
(('+))
 GGMM  !23&''E
 ")r*r   c                    U R                   R                  5       n[        U R                  5      =US'   nUS:  a  U R	                  S0 5        U R	                  U R
                  U5        g )Ns   indexr   rA  )rP   copynextrM  rN  rC  )rR   itemindexs      r   re   templateformatter._showitem  sT    zz !%dmm!44X19\2.T*r   c                   XR                   ;  a  g U R                   U   nUR                  5        H"  u  pEUb  M
  [        R                  " U5      X$'   M$     U R                  R                  U R                  R                  X25      5        g rK   )rJ  r   r   wrappedvaluer   r   rH  render)rR   partrU  rB  rx   r   s         r   rN  templateformatter._renderitem  se    {{"kk$JJLDAy&33A6 ! 			s12r   c                L    U R                   R                  U R                  5      $ rK   )rH  symbolsusedrC  rZ   s    r   _symbolsusedtemplateformatter._symbolsused  s    ww""4::..r   c                     U R                   S   $ )z5set of field names to be referenced from the templater   )r_  rZ   s    r   r   templateformatter.datahint  s      ##r   c                R    [         R                  U 5        U R                  S0 5        g )Nr@  )rH   r^   rN  rZ   s    r   r^   templateformatter.end  s     $r*r   )rM  r   rJ  rH  rC  rK   )r?   r@   rA   rB   rW   re   rN  r   propertycacher_  r   r^   rF   r"   r   r   r9  r9    s5    +&+3 
/ /$+r   r9  T)frozenc                      \ rS rSr\R
                  " 5       r\R
                  " 5       r\R
                  " 5       r\R
                  " SS9r	\R
                  " SS9r
Srg)templatespeci$  N)defaultr"   )r?   r@   rA   rB   r   ibrB  r%   mapfilerefargsfprF   r"   r   r   rh  rh  $  s?    
'')C779DggiGggd#G		Br   rh  c                     [        S S S 5      $ rK   rh  r"   r   r   empty_templatespecrp  -  s    dD))r   c                    [        U S S U5      $ rK   ro  )rB  rl  s     r   reference_templatespecrr  1  s    T411r   c                T    [        U [        5      (       a   S5       e[        SU S 5      $ )Ns   tmpl must not be a strr   )r   strrh  )r%   s    r   literal_templatespecru  5  s*    $$$?&??$T4((r   c                    [        U S XS9$ )N)rm  ro  )rT   rk  rm  s      r   mapfile_templatespecrw  :  s    tW44r   c                   U(       d
  [        5       $ SU;   a  [        U5      $ US;   a  [        U5      $ UR                  S5      u  p4nUS;   a?  U(       a8  UR	                  S5      (       a"  [
        R                  " U5        [        X5SS S9$ [        R                  R                  U5      S	   (       dK  [
        R                  " S
U-   5      =(       d    [
        R                  " U5      u  pgU(       a  [        XU5      $ U R                  SU5      (       a  [        U5      $ US:X  aO  U R                  [        S5      [
        R                  " 5       -  5        [         R"                  " [        S5      5      eSU;   d  SU;   a  [        R                  R%                  U5      (       a  [        R                  R'                  U5      R)                  S5      (       a)  [        U[        R                  R+                  U5      5      $ [,        R.                  " US5       nUR1                  5       nSSS5        [        U5      $ [        U5      $ ! , (       d  f       N$= f)a  Find the template matching the given -T/--template spec 'tmpl'

'tmpl' can be any of the following:

 - a literal template (e.g. '{rev}')
 - a reference to built-in template (i.e. formatter)
 - a map-file name or path (e.g. 'changelog')
 - a reference to [templates] in config file
 - a path to raw template file

A map file defines a stand-alone template environment. If a map file
selected, all templates defined in the file will be loaded, and the
template matching the given topic will be rendered. Aliases won't be
loaded from user config, but from the map file.

If no map file selected, all templates in [templates] section will be
available as well as aliases in [templatealias].
   {>      cbor   json   debug   pickle   (>   rz  r{     )N)rl  r   s   map-cmdline.	   templatess   lists   available styles: %s
s   specify a template   /   \s   map-s   rb)rp  ru  rr  	partitionendswithr   	parseexprospathr   try_open_templaterw  configr   r   	stylelistr	   Abortisfilebasename
startswithrealpathr   	posixfileread)	rS   rT   r%   funcfsepftailmapnamerm  r-  s	            r   lookuptemplater  >  s   ( !## t|#D)) 66%d++ t,D!!du~~d/C/CD!%d#2J?? 77==q!!33d"
 /((. 	 ';; 
yyt$$%d++w
,-	0C0C0EEFkk!1233 	277>>$+?+?77D!,,W55'rww/?/?/EFF^^D%(A668D )#D))  %% )(s   I
Ic                  ^ U R                   U R                   0nU R                  (       a  UR                  U4S jU 5       5        U$ U R                   (       a&  U H   nSU R                   U4-  nUT;   d  M  XSU'   M"     U$ )zCreate a mapping of {part: ref}c              3  8   >#    U  H  oT;   d  M
  X4v   M     g 7frK   r"   )rw   pts     r   ry   #templatepartsmap.<locals>.<genexpr>  s     <	1!V	s   	
s   %s:%s)rB  rk  r   )rO  r  	partnamespartsmapr[  rB  s    `    r   rI  rI    sp    $((#H||<	<< O 
Ddhh--Cax!$  Or   c                    UR                   (       a  UR                  (       a   eUR                  (       a5  [        R                  R                  UR                  UR                  UUUS9$ [        XR                   X#US9$ )zLCreate a templater from either a literal template or loading from
a map filer;  )r%   rk  r   frommapfilerm  maketemplater)rS   rO  r<  r=  r>  s        r   rD  rD    sm     		dll++||""..LLGG / 
 	
 
IIU r   c                    U R                  S5      n[        R                  " X#XES9nUR                  R                  S U R                  S5       5       5        U(       a  XR                  S'   U$ )z0Create a templater from a string template 'tmpl's   templatealias)r<  r=  r>  aliasesc              3  V   #    U  H  u  pU[         R                  " U5      4v   M!     g 7frK   )r   unquotestring)rw   rx   r   s      r   ry    maketemplater.<locals>.<genexpr>  s&      4PDAI##A&'4Ps   ')r  r   )configitemsr   r>  r   )rS   r%   r<  r=  r>  r  r  s          r   r  r    sc    nn-.Ge	A GGNN 46NN<4P  Hr   c                  h    \ 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g)rF  i  z@Resource mapper designed for the default templatekw and functionNc                    0 UUS.U l         g )N)   cacherv      ui_resmap)rR   rS   r~   s      r   rW   templateresources.__init__  s    
r   c                t    U R                  5        Vs1 s H  o R                  X5      c  M  UiM     sn$ s  snf rK   )	knownkeys_getsome)rR   mappingrx   s      r   availablekeystemplateresources.availablekeys  s4    ~~'
'!==+DA'
 	
 
s   55c                
    1 Sk$ )N>   r  rt   ru   rv   r     revcacher"   rZ   s    r   r  templateresources.knownkeys  s    GGr   c                    X R                  5       ;  a  g U R                  X5      nU[        L a  U R                  U   " X5      =o1U'   U$ rK   )r  r  _placeholder
_loadermaprR   r  r4   r   s       r   lookuptemplateresources.lookup  sG    nn&&MM''#s3DBBAr   c                f   0 nU R                  U5      (       a  0 US'   U R                  U5      (       a1  U R                  U5      (       a  [        R                  " XS5      nXTS'   SU;  a   U R                  US5      (       a	  [        US'   SU;  a   U R                  US5      (       a	  [        US'   U$ )Nr     nodes   originalnodert   ru      path)_hasnodespecr   	runsymbol_hasliteralr  )rR   r   origmapping
newmappingr  orignodes         r   populatemaptemplateresources.populatemap  s    Z((#%GK [))d.?.?
.K.K#--gGLH'/O$ #(8(8W(M(M*GFO*$)9)9*g)N)N+GGr   c                d    UR                  U5      nUb  U$ U R                  R                  U5      $ rK   )getr  r  s       r   r  templateresources._getsome  s/    KK=H||$$r   c                <    X!;   =(       a    [        X   5      (       + $ )z<Test if a literal value is set or unset in the given mapping)callable)rR   r  r4   s      r   r  templateresources._hasliteral  s    ~<hw|&<"<<r   c                J    UR                  U5      n[        U5      (       a  gU$ )z1Return value of the given name if it is a literalN)r  r  r  s       r   _getliteraltemplateresources._getliteral  s!    KKA;;r   c                $    SU;   =(       d    SU;   $ )z=Test if context revision is set or unset in the given mappingr  rt   r"   )rR   r  s     r   r  templateresources._hasnodespec  s    '!6Vw%66r   c                    U R                  US5      nU R                  US5      nUb  Uc  g  X#   $ ! [        R                   a     g f = f)Nrv   r  )r  r  r	   RepoLookupError)rR   r  r~   nodes       r   _loadctxtemplateresources._loadctx  sU    }}Wg.1<4<	:$$ 		   1 AAc                    U R                  US5      nU R                  US5      nUb  Uc  g  X#   $ ! [        R                   a     g f = f)Nrt   r  )r  r  r	   LookupError)rR   r  ctxr  s       r   	_loadfctxtemplateresources._loadfctx  sU    mmGV,1;$,	9   		r  )rt   ru   r  rK   )r?   r@   rA   rB   rC   rW   r  r  r  r  r  r  r  r  r  r  r  rF   r"   r   r   rF  rF    sL    J


H%=7 Jr   rF  c	           	         UR                   U0n	U(       a  XiSUR                   -  '   U(       a  XySUR                   -  '   U(       a  XSUR                   -  '   [        XX#XIS9$ )zYBuild template formatter that handles customizable built-in templates
such as -Tjson(...)s   %s:docheaders   %s:docfooters   %s:separator)rP  )rB  r9  )
rS   r   rT   rU   rO  r%   	docheader	docfooter	separator	templatess
             r   _internaltemplateformatterr  	  sb     4 I09/DHH,-09/DHH,-09/DHH,-
d r   c                   [        XUR                  SS5      5      nUR                  S:X  aF  UR                  b9  [	        U UUUUSUR                  -  [
        R                  [
        R                  S9$ UR                  S:X  a  [        XX#5      $ UR                  S:X  a+  UR                  b  [	        U UUUUSUR                  -  SS	S
S9	$ UR                  S:X  a  [        XX#5      $ UR                  S:X  a   UR                  b   S5       e[        XX#5      $ UR                  S:X  a   UR                  b   S5       e[        XX#5      $ UR                  (       d"  UR                  (       d  UR                  (       a!  UR                  b   S5       e[        XX#U5      $ U R                  SS5      (       a  [        XX#5      $ U R                  SS5      (       a  [        XX#5      $ [!        XX#5      $ )Ns   templater   rz  s   {dict(%s)|cbor})r%   r  r  r{  s   {dict(%s)|json}s   [
 r"  s   ,
 )r%   r  r  r  r}  zfunction-style not supportedr|  r  s   formatdebugs
   formatjson)r  r  rB  rl  r  r   r  r  r
  r  r   r   r%   rk  r9  
configboolr   )rS   r   rT   rU   rO  s        r   	formatterr  "  s   "TXXk3%?@Dxx7t||7)#dll255nn	
 		
 
W	Re22	W	!9)#dll2

 
	
 
W	Re22	Y	||#D%DD#r44	X	||#D%DD#bu33	TYY$,,||#D%DD# %t<<	un	-	-bu33	um	,	,Re22"5//r   c              #     #    [         R                  " US5       n[        XX#5       nUv   SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f7f)zjCreate a formatter that writes outputs to the specified file

Must be invoked using the 'with' statement.
s   wbN)r   r  r  )rS   filenamerT   rU   r   fms         r   openformatterr  Q  sD      
%	(Cr,H - 
)	(,, 
)	(s/   AA=A	A
A	A
AAc              #     #    U v   g 7frK   r"   )r  s    r   _neverendingr  \  s
     
Hs   c                |    U(       a+  [        U R                  XR                  U R                  5      $ [	        U 5      $ )zCreate a formatter backed by file if filename specified, else return
the given formatter

Must be invoked using the 'with' statement. This will never call fm.end()
of the given formatter.
)r  rL   rM   rN   r  )r  r  s     r   maybereopenr  a  s-     RVVXyy"((CCBr   rK   )NNN)r   r   r   )>rC   
__future__r   
contextlibrK  r  r  typingi18nr   r  r   r   
thirdpartyr   TYPE_CHECKING r	   r
   r   r   r   r   r   utilsr   r   r   r   r   rH   r   r   r   r   r   r   r   r
  r  r%  r9  r   rh  rp  rr  ru  rw  r  rI  rD  r  objectr  resourcemapperrF  r  r  contextmanagerr  r  r  r"   r   r   <module>r     s  bH #   	     
   B >] ]@D

&} 
& 7  7F'] 'T ]   2m 2(M ( "M ">#H #HL/+ /+d t  *2)
5?&D
"  xU	00 U~ 2,0^    
 r   