
     h:*                        S r SSKJr  SSKrSSKJrJrJrJr   " S S\	5      r
 " S S\	5      r " S	 S
5      r " S S5      rg)zA simple Python template renderer, for a nano-subset of Django syntax.

For a detailed discussion of this code, see this chapter from 500 Lines:
http://aosabook.org/en/500L/a-template-engine.html

    )annotationsN)AnyCallableNoReturncastc                      \ rS rSrSrSrg)TempliteSyntaxError   z*Raised when a template has a syntax error. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       o/root/racknerd_01/codex-conversation/amazon-q-terraform/.venv/lib/python3.13/site-packages/coverage/templite.pyr	   r	      s    4r   r	   c                      \ rS rSrSrSrg)TempliteValueError   z7Raised when an expression won't evaluate in a template.r   Nr   r   r   r   r   r      s    Ar   r   c                  f    \ rS rSrSrSSS jjrSS jrSS jrSS jrSr	SS jr
SS	 jrSS
 jrSrg)CodeBuilder   zBuild source code conveniently.c                    / U l         Xl        g Ncodeindent_level)selfindents     r   __init__CodeBuilder.__init__"   s    -/	"r   c                F    SR                  S U R                   5       5      $ )N c              3  8   #    U  H  n[        U5      v   M     g 7fr   )str).0cs     r   	<genexpr>&CodeBuilder.__str__.<locals>.<genexpr>'   s     1y!s1vvy   )joinr   r    s    r   __str__CodeBuilder.__str__&   s    ww1tyy111r   c                Z    U R                   R                  SU R                  -  US/5        g)zgAdd a line of source to the code.

Indentation and newline will be added for you, don't provide them.

 
N)r   extendr   )r    lines     r   add_lineCodeBuilder.add_line)   s(     			# 1 114>?r   c                f    [        U R                  5      nU R                  R                  U5        U$ )z!Add a section, a sub-CodeBuilder.)r   r   r   append)r    sections     r   add_sectionCodeBuilder.add_section1   s)    d//0		!r      c                B    U =R                   U R                  -  sl         g)z0Increase the current indent for following lines.Nr   INDENT_STEPr.   s    r   r!   CodeBuilder.indent9       T---r   c                B    U =R                   U R                  -  sl         g)z0Decrease the current indent for following lines.Nr?   r.   s    r   dedentCodeBuilder.dedent=   rB   r   c                Z    U R                   S:X  d   e[        U 5      n0 n[        X5        U$ )z:Execute the code, and return a dict of globals it defines.r   )r   r'   exec)r    python_sourceglobal_namespaces      r   get_globalsCodeBuilder.get_globalsA   s5       A%%%D	+-]-r   r   N)r   )r!   intreturnNone)rM   r'   )r5   r'   rM   rN   )rM   r   rM   rN   )rM   dict[str, Any])r   r   r   r   r   r"   r/   r6   r;   r@   r!   rD   rJ   r   r   r   r   r   r      s0    )#2@ K..	 r   r   c                  X    \ rS rSrSrSS jrSS jrSS jrSS jrSSS jjr	SS	 jr
S
rg)TempliteM   a   A simple template renderer, for a nano-subset of Django syntax.

Supported constructs are extended variable access::

    {{var.modifier.modifier|filter|filter}}

loops::

    {% for var in list %}...{% endfor %}

and ifs::

    {% if var %}...{% endif %}

Comments are within curly-hash markers::

    {# This will be ignored #}

Lines between `{% joined %}` and `{% endjoined %}` will have lines stripped
and joined.  Be careful, this could join words together!

Any of these constructs can have a hyphen at the end (`-}}`, `-%}`, `-#}`),
which will collapse the white space following the tag.

Construct a Templite with the template text, then use `render` against a
dictionary context to create a finished string::

    templite = Templite('''
        <h1>Hello {{name|upper}}!</h1>
        {% for topic in topics %}
            <p>You are interested in {{topic}}.</p>
        {% endif %}
        ''',
        {"upper": str.upper},
    )
    text = templite.render({
        "name": "Ned",
        "topics": ["Python", "Geometry", "Juggling"],
    })

c           
     	  ^^ 0 U l         U H  nU R                   R                  U5        M      [        5       U l        [        5       U l        [        5       mTR                  S5        TR                  5         TR                  5       nTR                  S5        TR                  S5        TR                  S5        TR                  S5        / mS0UU4S jjn/ n[        R                  " SU5      nS=pU GH  n
U
R                  S	5      (       Ga  S
u  pU
S   S:H  nU(       a  SnU
R                  S5      (       a  MH  U
R                  S5      (       a7  U R                  XU R                  5       5      nTR                  SU-  5        M  U" 5         XU R                  5       R                  5       nUS   S:X  ak  [        U5      S:w  a  U R!                  SU
5        UR                  S5        TR                  SU R                  US   5      -  5        TR                  5         GM0  US   S:X  a  [        U5      S:w  d	  US   S:w  a  U R!                  SU
5        UR                  S5        U R#                  US   U R                  5        TR                  SUS    SU R                  US   5       S35        TR                  5         GM  US   S:X  a  UR                  S5        Sn	GM  US   R                  S 5      (       a  [        U5      S:w  a  U R!                  S!U
5        US   SS" nU(       d  U R!                  S#U
5        UR%                  5       nUU:w  a  U R!                  S$U5        US:X  a  Sn	GM  TR'                  5         GM  U R!                  S%US   5        GM  U	(       a'  [        R(                  " S&S'U
R                  5       5      n
OU(       a  U
R+                  5       n
U
(       d  GM  TR                  [-        U
5      5        GM     U(       a  U R!                  S(US)   5        U" 5         U R                  U R                  -
   H  nUR                  S*U S+U< S,35        M     TR                  S-5        TR'                  5         [/        [0        [2        [4        [6        4   [0        S.[6        4   /[4        4   TR9                  5       S/   5      U l        g")1zConstruct a Templite with the given `text`.

`contexts` are dictionaries of values to use for future renderings.
These are good for filters and global values.

z&def render_function(context, do_dots):zresult = []zappend_result = result.appendzextend_result = result.extendzto_str = strc                    > [        T 5      S:X  a  TR                  ST S   -  5        O2[        T 5      S:  a#  TR                  SSR                  T 5      -  5        T SS2	 g)z%Force `buffered` to the code builder.   zappend_result(%s)r   zextend_result([%s]), N)lenr6   r-   )bufferedr   s   r   flush_output'Templite.__init__.<locals>.flush_output   sS    8}!1HQK?@X"3dii6IIJr   z(?s)({{.*?}}|{%.*?%}|{#.*?#})F{)   -z{#z{{z
to_str(%s)r   ifr]   zDon't understand ifzif %s:rV   forr=   inzDon't understand forzfor c_z in    :joinedTendzDon't understand endNzToo many endszMismatched end tagzDon't understand tagz\s*\n\s*r%   zUnmatched action tagc_z = context[]zreturn ''.join(result).render_functionrO   )contextupdatesetall_vars	loop_varsr   r6   r!   r;   resplit
startswith
_expr_codestripr9   rX   _syntax_error	_variablepoprD   sublstripreprr   r   dictr'   r   rJ   _render_function)r    textcontextsrl   	vars_coderZ   	ops_stacktokenssquash	in_joinedtokenstartrg   exprwordsend_what
start_whatvar_namerY   r   s                     @@r   r"   Templite.__init__x   s     GLL(   #&%#&5 }>?$$&	m$5656n% 	 	 	 :DA""E$$"
)s*C##D))%%d++??5s+;+A+A+CDDOOL4$78 !N!,224::<EQx4'u:? ../DeL!((.hq1J&JKqU*u:?eAh$.> ../EuM!((/uQx@$U1XJd4??583L2MQO qX-!((2$(	q,,U33u:? ../EuM#(8AB<( ..F%.]]_
%1 ../CXN#x/(-I KKM**+A58L FF;EKKMBE!LLNE5OODK0 B 5y}E6HH:[AFG 7 	./ $c3h#s(!34 01!
r   c                   SU;   aW  UR                  S5      nU R                  US   5      nUSS  H'  nU R                  X@R                  5        SU SU S3nM)     U$ SU;   aK  UR                  S5      nU R                  US   5      nS	R	                  S
 USS  5       5      nSU S	U S3nU$ U R                  XR                  5        SU-  nU$ )z(Generate a Python expression for `expr`.|r   rV   Nri   ().rW   c              3  8   #    U  H  n[        U5      v   M     g 7fr   )r{   )r(   ds     r   r*   &Templite._expr_code.<locals>.<genexpr>  s     7hT!WWhr,   zdo_dots(zc_%s)rr   rt   rw   ro   r-   )r    r   pipesr   funcdotsargss          r   rt   Templite._expr_code   s    $;JJsOE??58,Dab	t]]3D64&* "  D[::c?D??47+D997d12h77DdV2dV1-D  NN4/D=Dr   c                $    [        U SU< 35      e)z6Raise a syntax error using `msg`, and showing `thing`.z: )r	   )r    msgthings      r   rv   Templite._syntax_error  s    !SEE9"566r   c                    [         R                  " SU5      (       d  U R                  SU5        UR                  U5        g)zTrack that `name` is used as a variable.

Adds the name to `vars_set`, a set of variable names.

Raises an syntax error if `name` is not a valid name.

z[_a-zA-Z][_a-zA-Z0-9]*$zNot a valid nameN)rq   matchrv   add)r    namevars_sets      r   rw   Templite._variable  s3     xx2D99148Tr   Nc                    [        U R                  5      nU(       a  UR                  U5        U R                  X R                  5      $ )zrRender this template by applying it to `context`.

`context` is a dictionary of values to use in this rendering.

)r|   rl   rm   r}   _do_dots)r    rl   render_contexts      r   renderTemplite.render  s8     dll+!!'*$$^]]CCr   c           	         U H(  n [        X5      n[        U5      (       d  M!  U" 5       nM*     U$ ! [         a3     X   n N0! [        [        4 a  n[	        SU< SU 35      UeSnAff = ff = f)z(Evaluate dotted expressions at run-time.zCouldn't evaluate r   N)getattrAttributeError	TypeErrorKeyErrorr   callable)r    valuer   dotexcs        r   r   Templite._do_dots$  s    C+    " !JE!8, ,,UIQse<s&   1
A.AA*A%%A**A.)r}   ro   rl   rp   )r~   r'   r   rP   rM   rN   )r   r'   rM   r'   )r   r'   r   r   rM   r   )r   r'   r   zset[str]rM   rN   r   )rl   zdict[str, Any] | NonerM   r'   )r   r   r   r'   rM   r   )r   r   r   r   r   r"   rt   rv   rw   r   r   r   r   r   r   rR   rR   M   s)    (T|
|$7

Dr   rR   )r   
__future__r   rq   typingr   r   r   r   
ValueErrorr	   r   r   rR   r   r   r   <module>r      sG    # 	 0 0	* 		 	+  + \e er   