+
    VBi                        R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^RIHt . R/Ot	]P                  ! R4      t]P                  ! R]P                  4      tR	 t ! R
 R]4      t ! R R]4      t ! R R]4      tR t ! R R4      tR0R ltR0R lt ! R R]4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t]! 4       tAR1R lt]P                  ! R4      t. R2Ot ]P                  ! R4      t!]P                  ! R4      t"R  t#R! t$R3R" lt%R4R# lt&R$ t'R% t(R& t)R' t*R( t+R) t,R* t-R+ t.R,t/R0R- lt0]1R.8X  d
   ]0! 4        R# R# )5a  
A small templating language

This implements a small templating language.  This language implements
if/elif/else, for/continue/break, expressions, and blocks of Python
code.  The syntax is::

  {{any expression (function calls etc)}}
  {{any expression | filter}}
  {{for x in y}}...{{endfor}}
  {{if x}}x{{elif y}}y{{else}}z{{endif}}
  {{py:x=1}}
  {{py:
  def foo(bar):
      return 'baz'
  }}
  {{default var = default_value}}
  {{# comment}}

You use this with the ``Template`` class or the ``sub`` shortcut.
The ``Template`` class takes the template string and the name of
the template (for errors) and a default namespace.  Then (like
``string.Template``) you can call the ``tmpl.substitute(**kw)``
method to make a substitution (or ``tmpl.substitute(a_dict)``).

``sub(content, **kw)`` substitutes the template immediately.  You
can use ``__name='tmpl.html'`` to set the name of the template.

If there are syntax errors ``TemplateError`` will be raised.
N)StringIO)looperTemplateErrorTemplatebunchz\s+in\s+z^[a-z_][a-z0-9_]*$c                     \        V \        4      '       g)   \        V R 4      '       d   \        V 4      # \        V 4      # V # )__str__)
isinstancestrhasattrbytes)vs   &</usr/lib/python3.14/site-packages/Cython/Tempita/_tempita.pycoerce_textr   .   s3    a1i  q6M8OH    c                   4   a  ] tR t^6t o RtRR ltR tRtV tR# )r   z.Exception raised while parsing a template
    Nc                H    \         P                  W4       W n        W0n        R # N)	Exception__init__positionname)selfmessager   r   s   &&&&r   r   TemplateError.__init__:   s    4) 	r   c                   R P                  V P                  4      pV P                  '       d0   V: RV P                  ^ ,          : RV P                  ^,          : 2pV P                  '       d   VRV P                  ,          ,          pV# ) 	 at line  column z in %s)joinargsr   r   )r   msgs   & r   r   TemplateError.__str__?   sa    hhtyy!===T]]1%%t}}Q'79C9998dii''C
r   r   r   r   )	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classdictcell____classdict__s   @r   r   r   6   s     
 r   c                       ] tR t^ItRtR# )_TemplateContinue Nr$   r%   r&   r'   r)   r/   r   r   r.   r.   I       r   r.   c                       ] tR t^MtRtR# )_TemplateBreakr/   Nr0   r/   r   r   r3   r3   M   r1   r   r3   c                     \         P                  P                  \         P                  P                  VP                  4      V 4      pVP
                  P                  W!P                  VP                  R 7      # ))	namespaceget_template)	ospathr   dirnamer   	__class__from_filenamer5   r6   )r   from_templater8   s   && r   get_file_templater=   Q   sY    77<<(:(:;TBD""00//"// 1 1 1r   c                      a  ] tR t^Xt o RRRRR]/tRtRtRR ltRRR]	3R	 lt
]! ]
4      t
R
 tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )r   start_bracesz{{
end_bracesz}}r   utf8Nc
                   Wn         V	'       d!   ^ RIp
V
P                  R\        4       Vf   T	pVf(   V P                  R,          V P                  R,          3pMUV P
                  P                  P                  4       V n        V^ ,          V P                  R&   V^,          V P                  R&   V;V n        V n        \        V\        4      V n        Vf   Ve    \        P                  ! V4      pVP                  pVP                  pRV9   d>   VR,          pVP!                  R4      '       g   VP!                  R4      '       d   VRR pMRV9   d   VR,          pMR	pV'       d   VR
V,          ,          pW n        \'        WWpP                  R7      V n        Vf   / pW0n        WPn        Ve	   W`n        R# R#   \"         d     LOi ; i)    Nzk'delimeters' kwarg is being deprecated in favor of correctly spelled 'delimiters'. Please adjust your code.r?   r@   __file__z.pycz.pyor$   z<string>z:%sr   line_offset
delimiters)contentwarningswarnDeprecationWarningdefault_namespacer:   copyrG   
delimetersr	   r
   _unicodesys	_getframe	f_globalsf_linenoendswith
ValueErrorr   parse_parsedr5   r6   default_inherit)r   rI   r   r5   
stacklevelr6   rY   rF   rG   rO   rJ   callerglobalslinenos   &&&&&&&&&&    r   r   Template.__init__c   s     MMB"
 !'
00@00>@J
 &*^^%E%E%J%J%LD"5?]D"">23=a=D""<0,66$/"7C0<J2+z2 !**(":.D}}V,,f0E0E#CRy7*":.D%DEFN*D	W[UdUdeI"(&#2  '+  s   F: :GGc                    \        VR 4      ;_uu_ 4       pVP                  4       pRRR4       V'       d   XP                  V4      pV ! XWWER7      #   + '       g   i     L4; i)rbN)rI   r   r5   rY   r6   )openreaddecode)clsfilenamer5   encodingrY   r6   fcs   &&&&&&  r   r;   Template.from_filename   sQ    (D!!QA ""A18#2O 	O	 "!s   AA"	c                    R V P                   P                  : R\        \        V 4      4      R,          : RV P                  : R2# )<r      NNz name=>)r:   r$   hexidr   r   s   &r   __repr__Template.__repr__   s2    NN##4M"tyy* 	*r   c                   V'       dg   V'       d   \        R 4      h\        V4      ^8  d   \        R4      h\        V^ ,          R4      '       g   \        RV^ ,          : 24      hV^ ,          pTpV P                  VR&   V P                  '       d   VP                  V P                  4       V P                  V4      w  rEpV'       g   V P                  pV'       d   V P                  WEWc4      pV# )z3You can only give positional *or* keyword argumentsz)You can only give one positional argumentitemszoIf you pass in a single argument, you must pass in a dictionary-like object (with a .items() method); you gave __template_name__)		TypeErrorlenr   r   r5   update
_interpretrY   _interpret_inherit)r   r    kwnsresultdefsinherits   &*,    r   
substituteTemplate.substitute   s    IK K4y1}?A A47G,,Aw!" " aB"&))>>>IIdnn% $ 3g**G,,V7GFr   c                    R p. p/ pV P                  V P                  WVR7       RV9   d   VP                  R4      pMRpRP                  V4      WE3# )T)outr   __inherit__N )_interpret_codesrX   popr   )r   r}   __traceback_hide__partsr   r   s   &&    r   rz   Template._interpret   sY    !dllBED hh}-GGwwu~t,,r   c                F   R pV P                   '       g   \        RRV P                  R7      hV P                  W04      p\        V P                  4      pVP	                  4        F  w  r\        WxV	4       K  	  Wn        VP                  4       pWtR&   VP                  V4      # )Tz:You cannot use inheritance without passing in get_templateNr   r   r   )	r6   r   r   TemplateObjectru   setattrbodyrN   r   )
r   r   r   inherit_templater}   r   templself_r   values
   &&&&&     r   r{   Template._interpret_inherit   s    !   LDII/ / !!"29tyy)::<KDE' (
WWY6
##r   c                    R pV F>  p\        V\        4      '       d   VP                  V4       K,  V P                  WbW44       K@  	  R# TN)r	   r
   append_interpret_code)r   codesr}   r   r   r   items   &&&&&  r   r   Template._interpret_codes   s;    !D$$$

4 $$Ts9	 r   c           	        R pV^ ,          V^,          rvVR8X  d   V P                  V^,          W'4       R# VR8X  d   \        4       hVR8X  d   \        4       hVR8X  dB   V^,          V^,          V^,          rpV P                  WV4      p	V P	                  WWW44       R# VR8X  d   VR,          pV P                  WW44       R# VR8X  d~   V^,          P                  R4      pV P                  V^ ,          W'4      pVR	,           F  pV P                  WV4      pV! V4      pK  	  VP                  V P                  W4      4       R# VR
8X  d2   V^,          V^,          rW9  d   V P                  WV4      pVW/&   R# R# VR8X  d#   V^,          p	V P                  WV4      pVVR&   R# VR8X  d3   V^,          pV^,          pV^,          p\        WVWVR7      ;W&&   WF&   R# VR8X  d   R# Q RT,          4       h)Tpycontinuebreakforcondrl   expr|   NNdefaultr   r   def)r   r}   poscommentNzUnknown code: %r)
_execr.   r3   _eval_interpret_for_interpret_ifsplitr   _reprTemplateDef)r   coder}   r   r   r   r   r   varsr   rI   r   basepartfuncvarr~   r   	signatures   &&&&&              r   r   Template._interpret_code   s   !GT!Wc4<JJtAw(Z#%%W_ ""U]"&q'47DGD::d,DGCV^HEu#4V^GMM#&E::eAh0Db		zz$C0Dz " JJtzz$,-YQa}Dc2   Y7DJJt-E"'DU]7DQIGE$/IE47%9 9BHtzY/(4//1r   c                h   R pV F  p\        V4      ^8X  d   WV^ ,          &   MW\        V4      \        V4      8w  d'   \        R\        V4      \        V4      3,          4      h\        W4       F	  w  rWV	&   K  	   V P                  W4WV4       K  	  R#   \         d     K  \
         d      R# i ; i)Tz&Need %i items to unpack (got %i items)N)rx   rV   zipr   r.   r3   )r   r   r   rI   r}   r   r   r   r   r   r   s   &&&&&&&    r   r   Template._interpret_for  s    !D4yA~"47t9D	)$@t9c$i012 2 $'t?KD$tH $3%%g3=  % ! s   <BB1"B1+B10B1c                    R pV Ft  p\        V\        4      '       d   Q hV^ ,          V^,          rVR8X  d   R p	MV P                  V^,          W(4      p	V	'       g   KY  V P                  V^,          W#V4        R# 	  R# )TelseN)r	   r
   r   r   )
r   r   r}   r   r   r   r   r   r   r~   s
   &&&&&     r   r   Template._interpret_if!  sr    !D!$,,,,Qa#v~DGR5v%%d1gr= r   c                >   R p  \        WP                  V4      pV#   \         d   p\        RT,          4      hRp?ii ; i  \         dP   p\	        TRR4      '       d   TP
                  ^ ,          pM\        T4      pT P                  Ys4      3Tn        h Rp?ii ; i)Tz invalid syntax in expression: %sNr    )evalrM   SyntaxErrorr   getattrr    r   _add_line_info)r   r   r}   r   r   r   earg0s   &&&&    r   r   Template._eval/  s    !	?T#9#92> L  ?!6=? ??  	q&$''vvay"1~))$46AF	s-    A ?:?A BA
BBc                   R p \        WP                  V4       R#   \         d[   pTP                  '       d+   T P	                  TP                  ^ ,          T4      3Tn        h T P	                  RT4      3Tn        h Rp?ii ; ir   )execrM   r   r    r   )r   r   r}   r   r   r   s   &&&&  r   r   Template._exec@  sv    !	--r2 	vvv--affQi=?  --dC8:	s    BAA<<Bc           
     6   R p Vf   R# V P                   '       d    \        V4      pMd\	        V\        4      '       g   \        V4      p\	        V\        4      '       d.   V P                  '       d   VP                  V P                  4      pV P                   '       dY   \	        V\        4      '       dC   V P                  '       g   \        RV,          4      h VP                  V P                  4      pV# V P                   '       gV   \	        V\        4      '       d@   V P                  '       g   \        RV,          4      hVP                  V P                  4      pV#   \         d    \        T4      p Li ; i  \         dU   p\        TP                  TP                  TP                  TP                  TP                  RT,          ,           4      hRp?ii ; i  \         d0   pT P!                  TP"                  ^ ,          T4      3Tn        h Rp?ii ; i)TNr   zHCannot decode bytes value %r into unicode (no default_encoding provided)z in string %rzHCannot encode unicode value %r into bytes (no default_encoding provided))rP   r
   UnicodeDecodeErrorr   r	   r   default_encodingencoderc   rf   objectstartendreasonUnicodeEncodeErrorr   r   r    )r   r   r   r   r   s   &&&  r   r   Template._reprK  s   !&	}}}})JE "%--'.Euc** 111!LL)>)>?E
 }}}E5!9!9,,,,9;@AB B<!LL)>)>?E L ]]]z%'='=,,,,9;@AB B T%:%:;LA * )!%LE)& * <,

?U#::< <<  	))!&&)S9;AF	s^   G G E  A	G 2G E<  E96G 8E99G <GAGGH)*HHc                    V: R V^ ,          : RV^,          : 2pV P                   '       d   VRV P                   ,          ,          pV# )r   r   z in file %sr   )r   r!   r   s   &&&r   r   Template._add_line_infou  s;    QQ!999=499,,C
r   )
rX   rP   rI   rY   rM   rO   rG   r6   r   r5   )NNNNNrC   NN)r$   r%   r&   r'   r   rM   r   rY   r   r=   r;   classmethodrr   r   rz   r{   r   r   r   r   r   r   r   r   r)   r*   r+   s   @r   r   r   X   s      	d&
 O43l 04d&*9JO  .M*
0	-$:)0V&"	(T r   c                     VP                  R 4      pRV9   d   VP                  R4      MRp\        WWR7      pVP                  V4      # )__namerO   N)r   rG   rO   )getr   r   r   )rI   rG   r|   r   rO   tmpls   &&,   r   subr   }  sB    66(D)5);%JG:UD??2r   c                 <    \        WR 7      pVP                  V4      # )r   )r   r   )rI   r   re   r   s   &&& r   paste_script_template_rendererr     s    G+D??4  r   c                   >   a  ] tR tRt o R tR tR tR tR tRt	V t
R# )	r   i  c                P    VP                  4        F  w  r#\        WV4       K  	  R # r   )ru   r   )r   r|   r   r   s   &,  r   r   bunch.__init__  s    88:KDD& &r   c                    W V&   R # r   r/   )r   r   r   s   &&&r   __setattr__bunch.__setattr__  s	    T
r   c                H     W,          #   \          d    \        T4      hi ; ir   )KeyErrorAttributeErrorr   r   s   &&r   __getattr__bunch.__getattr__  s)    	': 	' &&	's   
 !c                    R V 9   d    \         P                  W4      # \         P                  W4      #   \         d    \         P                  T R 4      u # i ; i)r   )dict__getitem__r   )r   keys   &&r   r   bunch.__getitem__  sW    9''22 ##D..  9''i889s   3 !AAc                    R V P                   P                  : RRP                  \        V P	                  4       4       UUu. uF  w  rV: RV: 2NK  	  upp4      : R2# u uppi )rk   r   =rn   )r:   r$   r   sortedru   )r   kr   s   &  r   rr   bunch.__repr__  sM    NN##HH6$**,3GH3G41A&3GHIK 	KHs   A!r/   N)r$   r%   r&   r'   r   r   r   r   rr   r)   r*   r+   s   @r   r   r     s%     ''/K Kr   c                   L   a  ] tR tRt o R
R ltR tR tR tR
R ltR t	R	t
V tR# )r   i  Nc                Z    Wn         W n        W0n        W@n        WPn        W`n        Wpn        R # r   )	_template
_func_name_func_signature_body_ns_pos_bound_self)r   template	func_namefunc_signaturer   r}   r   
bound_selfs   &&&&&&&&r   r   TemplateDef.__init__  s'    !#-
	%r   c           	         R V P                   : RV P                  : RV P                  P                  : RV P                  : R2	# )z<tempita function (z) at :rn   )r   r   r   r   r   rq   s   &r   rr   TemplateDef.__repr__  s.    OOT11NN, 	,r   c                    V ! 4       # r   r/   rq   s   &r   r   TemplateDef.__str__  s	    vr   c                ,   V P                  W4      pV P                  P                  4       pVP                  V4       V P                  e   V P                  VR&   . p/ pV P
                  P                  V P                  WEV4       RP                  V4      # )Nr   r   )	_parse_signaturer   rN   ry   r   r   r   r   r   )r   r    r|   valuesr}   r   subdefss   &*,    r   __call__TemplateDef.__call__  sz    &&t0XX]]_
		&'))BvJ''

BWEwws|r   c           
         Vf   V # V P                  V P                  V P                  V P                  V P                  V P
                  V P                  VR7      # )N)r  )r:   r   r   r   r   r   r   )r   objtypes   &&&r   __get__TemplateDef.__get__  sL    ;K~~NNDOOT-A-AJJ$))  = 	=r   c                R   / pV P                   w  rErg/ pVP                  4        F5  w  rV'       g   W9  d   \        R V	,          4      hW9   d   WV&   K1  WV	&   K7  	  \        V4      p\        V4      pV'       d   V'       d"   V^ ,          V9   d   VP	                  ^ 4       K)  V'       d'   VP	                  ^ 4      p	VP	                  ^ 4      W9&   K_  V'       d   \        V4      W5&   M:\        RRP                  V Uu. uF  p\        V4      NK  	  up4      ,          4      hVP                  4        F?  w  rW9  g   K  V P                  P                  WP                  V P                  4      W9&   KA  	  V F  p	W9  g   K  \        RV	,          4      h	  V'       d   WV&   V# u upi )zUnexpected argument %szExtra position arguments: %sz, zMissing argument: %s)r   ru   rw   listr   tupler   reprr   r   r   r   )r   r    r|   r  sig_argsvar_argsvar_kwdefaultsextra_kwr   r   r   
value_exprs   &&&          r   r  TemplateDef._parse_signature  sq   /3/C/C,F88:KDd2,t35 5#(x !& & Dz>x{f4Q||A#xx{#(; 2ii$ 7$Qa$ 789: : !) 0D!#~~33$)) 5 !1 D!*T13 3  %6N !8s   =F$)r   r   r   r   r   r   r   r   )r$   r%   r&   r'   r   rr   r   r  r  r  r)   r*   r+   s   @r   r   r     s(     &,
	=% %r   r   c                   ,   a  ] tR tRt o R tR tRtV tR# )r   i  c                2    Wn         \        V 4      V n        R # r   )_TemplateObject__nameTemplateObjectGetterr   r   s   &&r   r   TemplateObject.__init__  s    '-r   c                T    R V P                   P                  : RV P                  : R2# )rk   r   rn   )r:   r$   r"  rq   s   &r   rr   TemplateObject.__repr__  s     NN33T[[AAr   )r   r   N)r$   r%   r&   r'   r   rr   r)   r*   r+   s   @r   r   r     s     .B Br   r   c                   2   a  ] tR tRt o R tR tR tRtV tR# )r#  i  c                    Wn         R # r   )#_TemplateObjectGetter__template_obj)r   template_objs   &&r   r   TemplateObjectGetter.__init__   s    *r   c                8    \        V P                  V\        4      # r   )r   r)  Empty)r   attrs   &&r   r    TemplateObjectGetter.__getattr__  s    t**D%88r   c                T    R V P                   P                  : RV P                  : R2# )rk   z around rn   )r:   r$   r)  rq   s   &r   rr   TemplateObjectGetter.__repr__  s    #'>>#:#:D<O<OPPr   )__template_objN)	r$   r%   r&   r'   r   r   rr   r)   r*   r+   s   @r   r#  r#    s     +9Q Qr   r#  c                   D   a  ] tR tRt o R tR tR tR tR tR t	Rt
V tR	# )
_Emptyi
  c                    V # r   r/   )r   r    r|   s   &*,r   r  _Empty.__call__  s    r   c                    R # r   r/   rq   s   &r   r   _Empty.__str__      r   c                    R # )r-  r/   rq   s   &r   rr   _Empty.__repr__  s    r   c                    R # r8  r/   rq   s   &r   __unicode___Empty.__unicode__  r:  r   c                    \        R4      # )Nr/   )iterrq   s   &r   __iter___Empty.__iter__  s    Bxr   c                    R # Fr/   rq   s   &r   __bool___Empty.__bool__  s    r   r/   N)r$   r%   r&   r'   r  r   rr   r>  rB  rF  r)   r*   r+   s   @r   r4  r4  
  s(      r   r4  c                
   Vf/   \         P                  R,          \         P                  R,          3pRp. p^ pV^,           ^3p\        P                  ! \        P                  ! V^ ,          4      : R\        P                  ! V^,          4      : 24      p	V	P                  V 4       EF  p
V
P                  ^ 4      p\        W
P                  4       Wx4      pW^ ,          8X  d%   V'       d   \        RV^ ,          ,          VVR7      hW^,          8X  d%   V'       g   \        RV^,          ,          VVR7      hW^ ,          8X  d/   WV
P                  4        pV'       d   VP                  V4       R	pM%VP                  WV
P                  4        V34       RpV
P                  4       pTpEK  	  V'       d   \        R
V^,          ,          WR7      hWR pV'       d   VP                  V4       V'       d   \        V4      pV# )a  
Lex a string into chunks:

    >>> lex('hey')
    ['hey']
    >>> lex('hey {{you}}')
    ['hey ', ('you', (1, 7))]
    >>> lex('hey {{')
    Traceback (most recent call last):
        ...
    TemplateError: No }} to finish last expression at line 1 column 7
    >>> lex('hey }}')
    Traceback (most recent call last):
        ...
    TemplateError: }} outside expression at line 1 column 7
    >>> lex('hey {{ {{')
    Traceback (most recent call last):
        ...
    TemplateError: {{ inside expression at line 1 column 10

Nr?   r@   Fr   z%s inside expressionr   z%s outside expressionTzNo %s to finish last expressionr#   )r   rM   recompileescapefinditergroupfind_positionr   r   r   r   trim_lex)sr   trim_whitespacerF   rG   in_exprchunkslastlast_postoken_rematchr   r   r   s   &&&&&         r   lexrX  %  s   , 11.A11,?B
GFDa#Hzzbii
1&>&(ii
1&>@ AH""1%{{1~Ayy{D;a= W 6A F),%)+ + ]"7 7*Q- G),%)+ + a= %++-(Dd#GMM1%++-0(;<Gyy{) &* =
1M!%: 	:U8Dd&!Mr   z.^(?:if |elif |for |def |inherit |default |py:)z\n\r?[\t ]*$z	^[\t ]*\nc                   Rp\        V 4       EFz  w  r#\        V\        4      '       d   K  V^ ,          p\        P	                  V4      '       g   V\
        9  d   KO  V'       g   RpMW^,
          ,          pV^,           \        V 4      8  d   RpMW^,           ,          p\        V\        4      '       d   \        V\        4      '       g   K  V'       * ;'       g    \        P	                  V4      pV^8X  d   VP                  4       '       g   RpVe'   V^,           V8X  d   VP                  4       '       g   RpV'       g   EK8  V'       dO   \        P	                  V4      '       g4   V\        V 4      ^,
          8X  g   EKu  VP                  4       '       d   EK  V'       dk   V^8X  d   VP                  4       '       d   VR8X  d   RW^,
          &   M:\        P	                  V4      pVRVP                  4       ^,            pWPV^,
          &   V'       g   EK  TpV\        V 4      ^,
          8X  d%   VP                  4       '       g   RW^,           &   EKH  \        P	                  V4      pWhP                  4       R pW`V^,           &   EK}  	  V # )aA  
Takes a lexed set of tokens, and removes whitespace when there is
a directive on a line by itself:

   >>> tokens = lex('{{if x}}\nx\n{{endif}}\ny', trim_whitespace=False)
   >>> tokens
   [('if x', (1, 3)), '\nx\n', ('endif', (3, 3)), '\ny']
   >>> trim_lex(tokens)
   [('if x', (1, 3)), 'x\n', ('endif', (3, 3)), 'y']
Nr   TrT  )	enumerater	   r
   statement_researchsingle_statementsrx   trail_whitespace_restriplead_whitespace_rer   r   )	tokens	last_trimicurrentr   prev
next_chunkprev_okms	   &        r   rO  rO  j  s    I'
gs##qz""4((T9J-JDa%=Dq5CKJAJ:s++!$,,(>>188>6$**,,G Y]a%7

GG#5#<#<Z#H#H#f+/)*2B2B2D2D!VDJJLL"f,$&Fq5M+2248AQ/D$(1q5Mz	Fa'
0@0@0B0B$&Fq5M*11*=A!+EEGH!5J$.1q5MU (V Mr   c                    V P                  RW!4      pV^ 8  d   WP                  RW!4      ,
          pMV^,          W,
          ,           pV^ ,          V,           V3# )z/Given a string and index, return (line, column)
)countrfind)stringindex
last_indexrU  linescolumns   &&&&  r   rN  rN    sQ    LLz1EqydJ>>! 23QK%((r   c                    Vf/   \         P                  R,          \         P                  R,          3p\        WW#R7      p. pV'       d!   \        WA4      w  rdVP	                  V4       K(  V# )a  
Parses a string into a kind of AST

    >>> parse('{{x}}')
    [('expr', (1, 3), 'x')]
    >>> parse('foo')
    ['foo']
    >>> parse('{{if x}}test{{endif}}')
    [('cond', (1, 3), ('if', (1, 3), 'x', ['test']))]
    >>> parse('series->{{for x in y}}x={{x}}{{endfor}}')
    ['series->', ('for', (1, 11), ('x',), 'y', ['x=', ('expr', (1, 27), 'x')])]
    >>> parse('{{for x, y in z:}}{{continue}}{{endfor}}')
    [('for', (1, 3), ('x', 'y'), 'z', [('continue', (1, 21))])]
    >>> parse('{{py:x=1}}')
    [('py', (1, 3), 'x=1')]
    >>> parse('{{if x}}a{{elif y}}b{{else}}c{{endif}}')
    [('cond', (1, 3), ('if', (1, 3), 'x', ['a']), ('elif', (1, 12), 'y', ['b']), ('else', (1, 23), None, ['c']))]

Some exceptions::

    >>> parse('{{continue}}')
    Traceback (most recent call last):
        ...
    TemplateError: continue outside of for loop at line 1 column 3
    >>> parse('{{if x}}foo')
    Traceback (most recent call last):
        ...
    TemplateError: No {{endif}} at line 1 column 3
    >>> parse('{{else}}')
    Traceback (most recent call last):
        ...
    TemplateError: else outside of an if block at line 1 column 3
    >>> parse('{{if x}}{{for x in y}}{{endif}}{{endfor}}')
    Traceback (most recent call last):
        ...
    TemplateError: Unexpected endif at line 1 column 25
    >>> parse('{{if}}{{endif}}')
    Traceback (most recent call last):
        ...
    TemplateError: if with no expression at line 1 column 3
    >>> parse('{{for x y}}{{endfor}}')
    Traceback (most recent call last):
        ...
    TemplateError: Bad for (no "in") in 'x y' at line 1 column 3
    >>> parse('{{py:x=1\ny=2}}')
    Traceback (most recent call last):
        ...
    TemplateError: Multi-line py blocks must start with a newline at line 1 column 3
r?   r@   rE   )r   rM   rX  
parse_exprr   )rP  r   rF   rG   ra  r~   rf  s   &&&&   r   rW   rW     sa    d 11.A11,?B
;NFF
'5
j!Mr   c                 ^   \        V ^ ,          \        4      '       d   V ^ ,          V R,          3# V ^ ,          w  r4VP                  4       pVP                  R4      '       d   VR,          P	                  R4      pVP                  R4      '       g   VP                  R4      '       dG   VP	                  R4      pRV9   d%   VP                  RR4      pVP                  RR4      pVR,          pMRV9   d   \        R	WAR
7      hRWC3V R,          3# VR9   d!   RV9  d   \        RWAR
7      hW43V R,          3# VP                  R4      '       d   \        WV4      # VP                  R4      '       g   VR8X  d*   \        RVP                  4       ^ ,          ,          WAR
7      hVR9   d   \        RV,          WAR
7      hVR9   d   \        RV,          WAR
7      hVP                  R4      '       d   \        WV4      # VP                  R4      '       d   \        WV4      # VP                  R4      '       d   \        WV4      # VP                  R4      '       d   \        WV4      # VP                  R4      '       d   RW@^ ,          ^ ,          3V R,          3# RW@^ ,          ^ ,          3V R,          3# )rC   r   py:   NNz 	rj  z
r   z.Multi-line py blocks must start with a newliner   r   r   zcontinue outside of for loopif elif r   z%s outside of an if blockz%s with no expressionzUnexpected %sfor default inherit def #r   r   )r   r   )ifelifr   )endifendforenddef)r	   r
   r_  
startswithlstripreplacer   
parse_condr   	parse_forparse_defaultparse_inherit	parse_def)ra  r   contextr   r   s   &&&  r   rs  rs    sr   &)S!!ay&*$$q	ID::<DuBxu%??4  DOOD$9$9;;v&Dt|||FD1||D"-DLDt|#D - - c &*,,	&	&.) ) {F2J&&			&00
//'
"
"V^'$**,q/9% 	% 
&	&#d*% 	% 
.	.d"% 	% 
	 	 w//		$	$V733		$	$V733		 	 w//			3q	!-vbz99C1&r
22r   c                 D   V ^ ,          ^,          p. pVR,           p V '       g   \        RW1R7      h\        V ^ ,          \        4      '       d3   V ^ ,          ^ ,          R8X  d   RV3\        V4      ,           V R,          3# \        WV4      w  rPVP	                  V4       K  )rC   zMissing {{endif}}r   r  r   r   )r  )r   r	   r  parse_one_condr   )ra  r   r  r   piecesrf  s   &&&   r   r  r     s    1IaLEFG
#+ + vay%((1IaLG+E?U6]2F2J>>+F'B
j!r   c                    V ^ ,          V R,          uw  r4p . pVP                  R4      '       d   VRR pVP                  R4      '       d   RWCR,          P                  4       V3pMOVP                  R4      '       d   RWCR	,          P                  4       V3pMVR
8X  d   R
VRV3pMQ RT: RT: 24       h V '       g   \        RWAR7      h\	        V ^ ,          \
        4      '       dS   V ^ ,          ^ ,          R8X  g;   V ^ ,          ^ ,          P                  R4      '       g   V ^ ,          ^ ,          R
8X  d   W`3# \        WV4      w  rpVP                  V4       K  )rC   r   r  Nry  r  rv  rz  r  :   NNr   zUnexpected token z at zNo {{endif}}r   r  rH   )rU   r  r  r   r	   r  rs  r   )ra  r   r  firstr   rI   r   rf  s   &&&     r   r  r  0  s7   !!9fRjLU&G~~ccr
c9++-w7			'	"	"2Y--/9	&T7+<<<q
) ) vay%((1(1IaL++G441IaLF*<'g>
z"r   c                 ~   V ^ ,          w  r4V R,          p RV,           p. pVP                  R4      '       g   Q V4       hVP                  R4      '       d   VRR pVR,          P                  4       p\        P	                  V4      pV'       g   \        RV,          WAR7      hVRVP                  4        pR	V9   d   \        R
V,          WAR7      h\        VRVP                  4        P                  R4       Uu. uF+  pVP                  4       '       g   K  VP                  4       NK-  	  up4      pW6P                  4       R p	 V '       g   \        RWAR7      h\        V ^ ,          \        4      '       d$   V ^ ,          ^ ,          R8X  d   RWGW3V R,          3# \        WV4      w  rVP                  V
4       Kw  u upi )rC   r   r   r{  r  Nrv  zBad for (no "in") in %rr   r  z=You cannot have () in the variable section of a for loop (%r),zNo {{endfor}}r  )r   rH   )r  rU   r_  in_rer\  r   r   r  r   r   r	   rs  r   )ra  r   r  r  r   rI   rW  r   r   r   rf  s   &&&        r   r  r  K  s   JEBZF GGF##*U*#~~ccr
"IOOELLE%-% 	% %++- D
d{K - 	-  %++-066s;;a779 		; D D
) ) vay%((1IaLH,3d4fRj@@'g>
z"s   9F:F:c                    V ^ ,          w  r4VP                  R4      '       g   Q hVP                  R^4      ^,          pVP                  R^4      p\        V4      ^8X  d   \        RV,          WAR7      hV^ ,          P	                  4       pRV9   d   \        RWAR7      h\
        P                  V4      '       g   \        RV,          WAR7      hV^,          P	                  4       pR	WFV3V R
,          3# )rC   r|  Nr   z:Expression must be {{default var=value}}; no = found in %rr   r  z'{{default x, y = ...}} is not supportedz-Not a valid variable name for {{default}}: %rr   r   )r  r   rx   r   r_  var_rer\  )ra  r   r  r  r   r   r   r   s   &&&     r   r  r  n  s    JEJ''''KKa #EKKQE
5zQH5P% 	% (..
C
cz5% 	% ==;, 	, 8>>Ds&r
22r   c                     V ^ ,          w  r4VP                  R4      '       g   Q hVP                  R^4      ^,          pRWE3V R,          3# )rC   r}  Nr   r   )r  r   )ra  r   r  r  r   r   s   &&&   r   r  r    sM    JEJ'''';;tQ"Ds!6":--r   c                    V ^ ,          w  r4V R,          p VP                  R4      '       g   Q hVP                  R^4      ^,          pVP                  R4      '       d   VRR pRV9  d
   TpRRR/ 3pMPVP                  R4      '       g   \        RV,          WAR7      hVRR pVP                  R^4      w  rW\	        WqV4      pVR,           p. p V '       g   \        R
WAR7      h\        V ^ ,          \        4      '       d$   V ^ ,          ^ ,          R8X  d   R	WEWh3V R,          3# \        WV4      w  rVP                  V	4       Kw  )rC   r   r~  Nr  r  )z*Function definition doesn't end with ): %sr   r   zMissing {{enddef}}r  rH   r/   )r   )	r  r   rU   r   parse_signaturer	   r  rs  r   )
ra  r   r  r  r   r   sigsig_textrI   rf  s
   &&&       r   r  r    sF   !9LEBZFF####KKa #E~~ccr

%	4r"^^C  H5P%*7 	7 cr
#kk#q1	he4 GG
$+ + vay%((1IaLH,5S:F2JFF'g>
z"r   c                   a \         P                  ! \        V 4      P                  4      o. pR pR p/ pRV3R llp R pV! 4       w  rV	\         P                  8X  d   EMzV	\         P
                  8X  d   V
R8X  g   V
R8X  d   T
pV! 4       w  rV	\         P                  8w  d   \        RV ,          W!R7      hT
pV! 4       w  rV	\         P                  8X  g   V	\         P
                  8X  dF   V
R8X  d?   VR8X  d   TpMVR8X  d   TpMVP                  V4       V	\         P                  8X  d   EMK  Ve   \        RV ,          W!R7      hV	\         P
                  8X  g   EK$  V
R8X  g   EK.  R pR p^ pR ;pp. p V! R4      w  rppVf   TpTpV	\         P                  8X  d   V'       d   \        RV ,          W!R7      hV'       gV   V	\         P                  8X  g   V	\         P
                  8X  d,   V
R8X  d%   \        WV4      pVWk&   VP                  V4       EK  VP                  W34       V'       d'   V	\         P
                  8X  d   W8X  d   V^,          pK  V'       d6   V	\         P
                  8X  d!   W8X  d   V^,          pV'       g   R ;rEK  EK   V'       d   EK+  V	\         P
                  8X  g   EKC  V
R9   g   EKM  T
p^pR	RR
RRR/V,          pEKc  W4WV3# )Nc                    <  \        S4      w  rw  r4w  rVpT '       d   YY43YV33# Y3#   \         d    \        P                  R 3u # i ; ir8  )nextStopIterationtokenize	ENDMARKER)	r   tok_type
tok_stringsrowscolerowecollinera  s	   &       r   	get_token"parse_signature.<locals>.get_token  s_    	*EI&\BH,4d $|CC''  	*%%r))	*s   ) A	A	*z**zInvalid signature: (%s)r   r  r   Tr  [{r  ]}rE  )r  r  r  )
r  generate_tokensr   readliner  OPNAMEr   r   isolate_expression)r  r   r   r  var_argr  r  r  var_arg_typer  r  var_name	nest_typeunnest_type
nest_count	start_posend_posr   rP  r   default_exprra  s   &&&                  @r   r  r    s   %%hx&8&A&ABFHGFH( ({x)))x{{"
c(9Z4=O%L#,; Hx}}$ 9H D),9 9({x)))h(++.E*X[J[s""%!)8---# 9H D),9 9x{{"zS'8IKJ"&&IE-6t_*a$ !Ix111j'(AH(L14A A"!X%7%77H<SXbfiXi#5h7#SL)5H&OOH-h34(hkk"9j>U!OJH$;
@Y!OJ%266	K &#HKK(?JRaDa *I!"J#&S#sC"@"KKf..r   c                 :   Vw  r4V^,          pVw  rVV^,          pV P                  R4      pW58X  d   Ws,          WF # Ws,          VR .pVP                  Ws^,           V 4       V\        V4      8  d   VP                  Wu,          RV 4       RP	                  V4      # )r   TNr   )
splitlinesextendrx   r   r   )	rm  r  r  r  r  r  r  rp  r   s	   &&&      r   r  r    s    JDAIDJDAIDd#E|{4%%[ E	LLAvd#$c%jU[$'(775>r   zn%prog [OPTIONS] TEMPLATE arg=value

Use py:arg=value to set a Python value; otherwise all values are
strings.
c                    ^ RI p^ RIp^ RIp^ RIpV f   VP                  R,          p VP                  R4      pVP                  \        V4      \        R7      pVP                  RRRRR	R
7       VP                  RRRRR7       VP                  V 4      w  rp\        V 4      ^8  d   \        R4       VP                  ! ^4       V ^ ,          pV R,          p / p	VP                  '       d   V	P                  VP                   4       V  Fq  p
RV
9  d%   \        RV
,          4       VP                  ! ^4       V
P#                  R^4      w  rVP%                  R4      '       d   VR,          p\'        V
4      p
WV&   Ks  	  VR8X  d   VP(                  P+                  4       pRpM-\-        VR4      ;_uu_ 4       pVP+                  4       pRRR4       \/        XVR7      pVP1                  V	4      pVP2                  '       d;   \-        VP2                  R4      ;_uu_ 4       pVP5                  V4       RRR4       R# VP6                  P5                  V4       R#   + '       g   i     L; i  + '       g   i     R# ; i)rC   Nr   Paste)versionusagez-oz--outputoutputFILENAMEz(File to write output to (default stdout))destmetavarhelpz--envuse_env
store_truez-Put the environment in as top-level variables)r  actionr  z!You must give a template filenamer   zBad argument: %rru  :Nrw  N-z<stdin>r`   r   wb)rQ   optparsepkg_resourcesr7   argvget_distributionOptionParserr   _fill_command_usage
add_option
parse_argsrx   printexitr  ry   environr   r  r   stdinrb   ra   r   r   r  writestdout)r    rQ   r  r  r7   distparseroptionstemplate_namer   r   r   template_contentrg   r   r~   s   &               r   fill_commandr    s   |xx|))'2D""D!! # #F j7	  9
 <	  >
 %%d+MG
4y1}12GM8DDBJJe$u,-HHQKkk#q)??5!!8DKET
  99>>+!-&&! vvx '(}=H  &F~~~'..$''1GGFO (' 	

  '&
 (''s   4II'I$	'I8	__main__)r   r   r   r   r   )NTrC   N)r   r  r  r  r   r   )NrC   N)r/   )2r(   rI  rQ   r7   r  ior   _looperr   __all__rJ  r  Ir  r   r   r   r.   r3   r=   r   r   r   r   r   r   r   r#  r4  r-  rX  r[  r]  r^  r`  rO  rN  rW   rs  r  r  r  r  r  r  r  r  r  r  r$   r/   r   r   <module>r     st  @ 
 
 	   
7


;	)244	0I &		 		Y 	1b bJ	!
KD K<J JZB B	Q 	Q & 	
=~ zzKLN jj1 ZZ- 7t):z23j" #6 #F3,.#>I/X 3!j zN r   