
    gMJ                        d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ  G d d      Z G d	 d
e      Z G d de      Z	 G d de      Z
 G d de      Z G d de      Z G d de      Z G d de      Z G d dee      Z G d de      Z G d de      Z G d de      Z G d  d!e      Z G d" d#e      Z G d$ d%e      Z G d& d'e      Z G d( d)e      Z G d* d+e      Zy),z5defines the parse tree components for Mako templates.    N)ast)
exceptions)filters)utilc                   2    e Zd ZdZd Zed        Zd Zd Zy)Nodez(base class for a Node in the parse tree.c                 <    || _         || _        || _        || _        y Nsourcelinenoposfilename)selfr   r   r   r   s        M/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/mako/parsetree.py__init__zNode.__init__   s         c                 `    | j                   | j                  | j                  | j                  dS )Nr   r   r   s    r   exception_kwargszNode.exception_kwargs   s*     kkkk88	
 	
r   c                     g S r
    r   s    r   get_childrenzNode.get_children$       	r   c                 h    fd}t        d| j                  j                  z   |      } ||        y )Nc                 R    | j                         D ]  }|j                          y r
   )r   accept_visitor)nodenvisitors     r   traversez%Node.accept_visitor.<locals>.traverse(   s)    &&( *  )*r   visit)getattr	__class____name__)r   r    r!   methods    `  r   r   zNode.accept_visitor'   s.    	* 'DNN,C,C"CXNtr   N)	r%   
__module____qualname____doc__r   propertyr   r   r   r   r   r   r   r      s(    2! 
 
r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )TemplateNodez?a 'container' node that stores the overall collection of nodes.c                 F    t         |   ddd|       g | _        i | _        y )N r   )superr   nodespage_attributes)r   r   r$   s     r   r   zTemplateNode.__init__4   s%    Q8,
!r   c                     | j                   S r
   r0   r   s    r   r   zTemplateNode.get_children9       zzr   c                 b    dt        j                  | j                        d| j                  dS )NzTemplateNode(, ))r   sorted_dict_reprr1   r0   r   s    r   __repr__zTemplateNode.__repr__<   s'    !!$"6"67JJ
 	
r   )r%   r'   r(   r)   r   r   r9   __classcell__r$   s   @r   r,   r,   0   s    I"

r   r,   c                   D     e Zd ZdZdZ fdZd Zd Zd Zd Z	d Z
 xZS )	ControlLinezdefines a control line, a line-oriented python line or end tag.

    e.g.::

        % if foo:
            (markup)
        % endif

    Fc                 (   t        |   di | || _        || _        || _        |dv | _        g | _        | j                  rg | _        g | _        y t        j                  |fi | j                  }|j                  | _        |j                  | _        y )N)forifwhiletrywithr   )r/   r   textkeywordisend
is_primaryr0   _declared_identifiers_undeclared_identifiersr   PythonFragmentr   declared_identifiersundeclared_identifiers)r   rE   rF   rD   kwargscoder$   s         r   r   zControlLine.__init__Q   s    "6"	
!%JJ
::)+D&+-D(%%dDd.C.CDD)-)B)BD&+/+F+FD(r   c                     | j                   S r
   r3   r   s    r   r   zControlLine.get_children`   r4   r   c                     | j                   S r
   )rH   r   s    r   rK   z ControlLine.declared_identifiersc   s    )))r   c                     | j                   S r
   )rI   r   s    r   rL   z"ControlLine.undeclared_identifiersf   s    +++r   c                 d    ddhddhdhd}||j                  | j                  t                     v S )zRreturn true if the given keyword is a ternary keyword
        for this ControlLineelseelifexceptfinally)r@   rB   r?   )getrE   set)r   rE   casess      r   
is_ternaryzControlLine.is_ternaryi   s>    
 6"i(8
 %))DLL#%888r   c           	          d| j                   d| j                  d| j                  d| j                  | j                  fd	S )NzControlLine(r6   r7   )rE   rD   rF   r   r   r   s    r   r9   zControlLine.__repr__u   s1    LLIIJJ[[$((#	
 	
r   )r%   r'   r(   r)   has_loop_contextr   r   rK   rL   rZ   r9   r:   r;   s   @r   r=   r=   C   s/     G*,
9
r   r=   c                   (     e Zd ZdZ fdZd Z xZS )Textz#defines plain text in the template.c                 2    t        |   di | || _        y Nr   )r/   r   content)r   ra   rM   r$   s      r   r   zText.__init__   s    "6"r   c                 T    d| j                   d| j                  | j                  fdS )NzText(r6   r7   )ra   r   r   r   s    r   r9   zText.__repr__   s    !%TXX/FGGr   r%   r'   r(   r)   r   r9   r:   r;   s   @r   r^   r^   ~   s    -Hr   r^   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )Codezdefines a Python code block, either inline or module level.

    e.g.::

        inline:
        <%
            x = 12
        %>

        module level:
        <%!
            import logger
        %>

    c                     t        |   di | || _        || _        t	        j
                  |fi | j                  | _        y r`   )r/   r   rD   ismoduler   
PythonCoder   rN   )r   rD   rg   rM   r$   s       r   r   zCode.__init__   s<    "6"	 NN4A4+@+@A	r   c                 .    | j                   j                  S r
   )rN   rK   r   s    r   rK   zCode.declared_identifiers   s    yy---r   c                 .    | j                   j                  S r
   )rN   rL   r   s    r   rL   zCode.undeclared_identifiers   s    yy///r   c                 n    d| j                   d| j                  d| j                  | j                  fdS )NzCode(r6   r7   )rD   rg   r   r   r   s    r   r9   zCode.__repr__   s*    IIMM[[$((#
 	
r   	r%   r'   r(   r)   r   rK   rL   r9   r:   r;   s   @r   re   re      s     B.0
r   re   c                   (     e Zd ZdZ fdZd Z xZS )Commentz6defines a comment line.

    # this is a comment

    c                 2    t        |   di | || _        y r`   )r/   r   rD   )r   rD   rM   r$   s      r   r   zComment.__init__   s    "6"	r   c                 T    d| j                   d| j                  | j                  fdS )NzComment(r6   r7   )rD   r   r   r   s    r   r9   zComment.__repr__   s    $(IITXX/FGGr   rc   r;   s   @r   rn   rn      s    Hr   rn   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )
Expressionz/defines an inline expression.

    ${x+y}

    c                     t        |   di | || _        || _        t	        j
                  |fi | j                  | _        t	        j                  |fi | j                  | _	        y r`   )
r/   r   rD   escapesr   ArgumentListr   escapes_coderh   rN   )r   rD   rt   rM   r$   s       r   r   zExpression.__init__   sZ    "6"	,,WN8M8MNNN4A4+@+@A	r   c                     g S r
   r   r   s    r   rK   zExpression.declared_identifiers   r   r   c                     | j                   j                  j                  | j                  j                  j	                  t
        j                              j	                  | j                   j                        S r
   )rN   rL   unionrv   
differencer   DEFAULT_ESCAPESrK   r   s    r   rL   z!Expression.undeclared_identifiers   sX    yy//5544??''
 *TYY33
4		5r   c                     d| j                   d| j                  j                  d| j                  | j                  fdS )NzExpression(r6   r7   )rD   rv   argsr   r   r   s    r   r9   zExpression.__repr__   s2    II""[[$((#
 	
r   rl   r;   s   @r   rr   rr      s    B5
r   rr   c                   ,     e Zd ZdZi Z fdZd Z xZS )_TagMetazImetaclass to allow Tag to produce a subclass according to
    its keywordc                 t    t        | dd       | | j                  | j                  <   t        |   |||       y )N__keyword__)r#   	_classmapr   r/   r   )clsclsnamebasesdict_r$   s       r   r   z_TagMeta.__init__   s5    3t,8-0CMM#//*%/r   c           	      0   d|v r1|j                  d      \  }}t        j                  t        |||fi |S 	 t        j
                  |   } t        j                  | ||fi |S # t        $ r* t        j                  d|z  |d   |d   |d   |d         w xY w)N:zNo such tag: '%s'r   r   r   r   r   )	splittype__call__CallNamespaceTagr   r   KeyErrorr   CompileException)r   rE   
attributesrM   nsdefnames         r   r   z_TagMeta.__call__   s    '>!--,KB== "gz=C 		$$W-C }}S':@@@  	--#g-h'h'5M
+ 	s   A" "3B)r%   r'   r(   r)   r   r   r   r:   r;   s   @r   r   r      s     I0
Ar   r   c                   J     e Zd ZdZdZ fdZd Zd Zd Zd Z	d Z
d	 Z xZS )
Tagzabstract base class for tags.

    e.g.::

        <%sometag/>

        <%someothertag>
            stuff
        </%someothertag>

    Nc                 N   t        	|   di | || _        || _        | j	                  ||       |D cg c]  }|| j
                  vs| }}t        |      r9t        j                  ddj                  d |D              z  fi | j                  d| _        g | _        yc c}w )aV  construct a new Tag instance.

        this constructor not called directly, and is only called
        by subclasses.

        :param keyword: the tag keyword

        :param attributes: raw dictionary of attribute key/value pairs

        :param expressions: a set of identifiers that are legal attributes,
         which can also contain embedded expressions

        :param nonexpressions: a set of identifiers that are legal
         attributes, which cannot contain embedded expressions

        :param \**kwargs:
         other arguments passed to the Node superclass (lineno, pos)

        zMissing attribute(s): %s,c              3   2   K   | ]  }t        |        y wr
   )repr).0ms     r   	<genexpr>zTag.__init__.<locals>.<genexpr>1  s     81tAw8s   Nr   )r/   r   rE   r   _parse_attributesparsed_attributeslenr   r   joinr   parentr0   )
r   rE   r   expressionsnonexpressionsrequiredrM   rmissingr$   s
            r   r   zTag.__init__  s    8 	"6"${N;&J!43I3I*I1JJw<--.hh8889
 ''  
 Ks   B"	B"c                     | j                   d u S r
   )r   r   s    r   is_rootzTag.is_root9  s    {{d""r   c                     | j                   S r
   r3   r   s    r   r   zTag.get_children<  r4   r   c                 D   t               }i | _        | j                  D ]  }||v rBg }t        j                  dt        j
                        j                  | j                  |         D ]  }t        j                  dt        j
                        j                  |      }|r|t        j                  |j                  d      j                         fi | j                  }|j                  |j                        }|j                  d|j                  d      z         |s|j                  t!        |              dj#                  |      xs t!        d      | j                  |<   K||v r{t        j$                  d| j                  |         r1t'        j(                  d|d	| j*                  d
fi | j                  t!        | j                  |         | j                  |<   t'        j(                  d| j*                  d|dfi | j                   || _        y )Nz(\${(?:[^$]*?{.+|.+?)})z^\${(.+?)}$   z(%s)z + r.   z\${.+?}zAttribute 'z
' in tag 'z%' does not allow embedded expressionszInvalid attribute for tag 'z': '')rX   r   r   recompileSr   matchr   rh   grouprstripr   ry   rL   appendr   r   searchr   r   rE   !expression_undeclared_identifiers)	r   r   r   rL   keyexprxr   rN   s	            r   r   zTag._parse_attributes?  s   !$!#?? #	Ck!$>EKKOOC( -A 

>2448>>qAA"~~GGAJ--/ 373H3H  2H1M1M 772. FQWWQZ$78DG,#-$ /4jj.>.J$r(&&s+&99Z)=>$55),dll< // 
 /34??33G.H&&s+ 11||S* ++ ?#	H 2H.r   c                     g S r
   r   r   s    r   rK   zTag.declared_identifiersh  r   r   c                     | j                   S r
   )r   r   s    r   rL   zTag.undeclared_identifiersk  s    555r   c           
          | j                   j                  d| j                  dt        j                  | j
                        d| j                  | j                  fd| j                  d
S )N(r6   r7   )	r$   r%   rE   r   r8   r   r   r   r0   r   s    r   r9   zTag.__repr__n  sI    NN##LL!!$//2[[$((#JJ
 	
r   )r%   r'   r(   r)   r   r   r   r   r   rK   rL   r9   r:   r;   s   @r   r   r      s5    
 K+Z#'HR6
r   r   )	metaclassc                   2     e Zd ZdZ fdZd Z fdZ xZS )
IncludeTagincludec                     t        |   ||dddfi | t        j                  d|j	                  dd      z  fi | j
                  | _        y )N)fileimportr}   r   r   z__DUMMY(%s)r}   r.   )r/   r   r   rh   rW   r   	page_argsr   rE   r   rM   r$   s       r   r   zIncludeTag.__init__{  s\    &	
 	
 JNN6266
:>:O:O
r   c                     g S r
   r   r   s    r   rK   zIncludeTag.declared_identifiers  r   r   c                     | j                   j                  j                  dh      j                  | j                   j                        }|j	                  t
        |                S )N__DUMMY)r   rL   rz   rK   ry   r/   )r   identifiersr$   s     r   rL   z!IncludeTag.undeclared_identifiers  sT    nn;;FFK

*T^^88
9 	   !?!ABBr   r%   r'   r(   r   r   rK   rL   r:   r;   s   @r   r   r   x  s    K
C Cr   r   c                   (     e Zd ZdZ fdZd Z xZS )NamespaceTag	namespacec                 :   t        |   ||dddfi | |j                  ddt        t	        t        |                   z        | _        d|vr$d|vr t        j                  	 d	i | j                  d|v r%d|v r t        j                  	 d
i | j                  y y )Nr   )nameinheritabler   moduler   r   z	__anon_%sr   r   r   )z?'name' and/or 'import' attributes are required for <%namespace>)z4<%namespace> may only have one of 'file' or 'module')
r/   r   rW   hexabsidr   r   r   r   r   s       r   r   zNamespaceTag.__init__  s    7	
 	
 NN6;SD]9K+KL	#
(B--# '' 
 ZH
$:--F''  %;r   c                     g S r
   r   r   s    r   rK   z!NamespaceTag.declared_identifiers  r   r   r%   r'   r(   r   r   rK   r:   r;   s   @r   r   r     s    K.r   r   c                   (     e Zd ZdZ fdZd Z xZS )TextTagrD   c                     t        |   ||dddfi | t        j                  |j	                  dd      fi | j
                  | _        y )Nr   filterr.   )r/   r   r   ru   rW   r   filter_argsr   s       r   r   zTextTag.__init__  sL    *b8bKFK++NN8R(
,0,A,A
r   c                     | j                   j                  j                  t        j                  j                               j                  | j                        S r
   r   rL   rz   r   r{   keysry   r   r   s    r   rL   zTextTag.undeclared_identifiers  sC    66AA##((*

%66
7	8r   )r%   r'   r(   r   r   rL   r:   r;   s   @r   r   r     s    K
8r   r   c                   L     e Zd ZdZ fdZdZdZed        Zd Z	d Z
d Z xZS )DefTagdefc                     ddg|D cg c]  }|j                  d      s| c}z   }t        |   |||ddfi | |d   }t        j                  d|      r t        j                  	 di | j                  t        j                  d|z   d	z   fi | j                  | _
        | j                  j                  | _        |j                  d
d      | _        t        j                  |j                  dd      fi | j                  | _        y c c}w )Nbufferedcachedcache_r   r   	decoratorr   r   ^[\w_]+$zdef z:passr   r.   r   )zMissing parenthesis in %def)
startswithr/   r   r   r   r   r   r   r   FunctionDeclfunction_declfuncnamer   rW   r   ru   r   r   rE   r   rM   cr   r   r$   s          r   r   zDefTag.__init__  s    !8,!0
Q\\(%;A0
 
 	+	
 	
 &!88K&---151F1F  !--TMG#
'+'<'<
 &&//	#R8++NN8R(
,0,A,A
-0
s
   DDFc                 .    | j                   j                  S r
   )r   r   r   s    r   r   zDefTag.funcname  s    !!***r   c                 :     | j                   j                  di |S r`   )r   get_argument_expressionsr   kws     r   r   zDefTag.get_argument_expressions  s    :t!!::@R@@r   c                 .    | j                   j                  S r
   )r   allargnamesr   s    r   rK   zDefTag.declared_identifiers  s    !!---r   c           	         g }| j                   j                  D ]8  }|t        t        j                  |fi | j
                  j                        z  }: t        |      j                  | j                  j                  j                  t        j                  j                                     j                  | j                        j                  | j                   j                        S r
   )r   defaultslistr   rh   r   rL   rX   ry   r   rz   r   r{   r   r   r   )r   resr   s      r   rL   zDefTag.undeclared_identifiers  s    ##,, 	A4..(( C	 HU  77BB++002
 U499:Z**667		
r   )r%   r'   r(   r   r   is_anonymousis_blockr*   r   r   rK   rL   r:   r;   s   @r   r   r     s;    K
6 LH+ +A.
r   r   c                   X     e Zd ZdZ fdZdZed        Zed        Zd Z	d Z
d Z xZS )	BlockTagblockc                    g d|D cg c]  }|j                  d      s| c}z   }t        |   |||ddfi | |j                  d      }|r6t	        j
                  d|      s t        j                  	 di | j                  |s2|j                  dd       r t        j                  	 di | j                  t        j                  |j                  dd      fi | j                  | _        || _        |j                  d	d      | _        t        j                  |j                  d
d      fi | j                  | _        y c c}w )N)r   r   r}   r   r   r   r   r   r}   r.   r   r   )z,%block may not specify an argument signature)z#Only named %blocks may specify args)r   r/   r   rW   r   r   r   r   r   r   FunctionArgs	body_declr   r   ru   r   r   s          r   r   zBlockTag.__init__  sL   4!8
Q\\(%;A8
 
 	+	
 	
 ~~f%d3-->''  
vt4--59=9N9N  ))NN62&
*.*?*?
 	#R8++NN8R(
,0,A,A
98
s
   EETc                     | j                   d u S r
   r   r   s    r   r   zBlockTag.is_anonymous$  s    yyD  r   c                 >    | j                   xs d| j                  fz  S )Nz__M_anon_%d)r   r   r   s    r   r   zBlockTag.funcname(  s    yy:MT[[N::r   c                 :     | j                   j                  di |S r`   )r  r   r   s     r   r   z!BlockTag.get_argument_expressions,  s    6t~~66<<<r   c                 .    | j                   j                  S r
   r  r   r   s    r   rK   zBlockTag.declared_identifiers/      ~~)))r   c                     | j                   j                  j                  t        j                  j                               j                  | j                        S r
   r   r   s    r   rL   zBlockTag.undeclared_identifiers2  sE    33>>'',,. %66
7		8r   )r%   r'   r(   r   r   r   r*   r   r   r   rK   rL   r:   r;   s   @r   r   r     sJ    K
B H! ! ; ;=*8r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )CallTagcallc                 
   t        |   ||dddfi | |d   | _        t        j                  | j                  fi | j
                  | _        t        j                  |j                  dd      fi | j
                  | _	        y )Nr}   )r   r   r.   )
r/   r   
expressionr   rh   r   rN   r   rW   r  r   s       r   r   zCallTag.__init__=  s~    Z&9i	
CI	
 %V,NN4??Ld6K6KL	))NN62&
*.*?*?
r   c                 t    | j                   j                  j                  | j                  j                        S r
   rN   rK   ry   r  r   r   s    r   rK   zCallTag.declared_identifiersG  '    yy--33DNN4N4NOOr   c                 t    | j                   j                  j                  | j                   j                        S r
   rN   rL   rz   rK   r   s    r   rL   zCallTag.undeclared_identifiersJ  ,    yy//::II**
 	
r   r   r;   s   @r   r
  r
  :  s    K
P
r   r
  c                   *     e Zd Z fdZd Zd Z xZS )r   c           	         t        |   |dz   |z   |t        |j                               dz   ddfi | |d|ddj	                  d | j
                  j                         D              d| _        t        j                  | j                  fi | j                  | _        t        j                  |j                  d	d
      fi | j                  | _        y )Nr   )r}   r   .r   r   c              3   :   K   | ]  \  }}|d k7  r	|d|  yw)r}   =Nr   )r   kvs      r   r   z,CallNamespaceTag.__init__.<locals>.<genexpr>^  s(      Aq; a s   r7   r}   r.   )r/   r   tupler   r   r   itemsr  r   rh   r   rN   r   rW   r  )r   r   r   r   rM   r$   s        r   r   zCallNamespaceTag.__init__Q  s    Og%*//#$y0	
 	
 HH  2288: 
 NN4??Ld6K6KL	))NN62&
*.*?*?
r   c                 t    | j                   j                  j                  | j                  j                        S r
   r  r   s    r   rK   z%CallNamespaceTag.declared_identifiersj  r  r   c                 t    | j                   j                  j                  | j                   j                        S r
   r  r   s    r   rL   z'CallNamespaceTag.undeclared_identifiersm  r  r   )r%   r'   r(   r   rK   rL   r:   r;   s   @r   r   r   P  s    
2P
r   r   c                   "     e Zd ZdZ fdZ xZS )
InheritTaginheritc                 .    t        |   ||dddfi | y )Nr   r   )r/   r   r   s       r   r   zInheritTag.__init__v  s#    ZB		
=C	
r   )r%   r'   r(   r   r   r:   r;   s   @r   r   r   s  s    K
 
r   r   c                   (     e Zd ZdZ fdZd Z xZS )PageTagpagec                 Z   g d|D cg c]  }|j                  d      s| c}z   }t        |   |||ddfi | t        j                  |j                  dd      fi | j                  | _        t        j                  |j                  dd      fi | j                  | _	        y c c}w )N)r   r}   expression_filterenable_loopr   r   r}   r.   r'  )
r   r/   r   r   r   rW   r   r  ru   r   )r   rE   r   rM   r   r   r$   s         r   r   zPageTag.__init__  s    

 #=1all8&<Q=> 	*k2rLVL))NN62&
*.*?*?
 ++NN.3
7;7L7L
 >s
   B(B(c                 .    | j                   j                  S r
   r  r   s    r   rK   zPageTag.declared_identifiers  r  r   r   r;   s   @r   r$  r$  |  s    K
 *r   r$  )r)   r   makor   r   r   r   r   r,   r=   r^   re   rn   rr   r   r   r   r   r   r   r   r   r
  r   r   r$  r   r   r   <module>r+     s   < 	     >
4 
&8
$ 8
vH4 H"
4 "
JHd H
 
BAt A>x
$( x
vC C43 <8c 8<
S <
~98s 98x
c 
, 
s  
F
 
*c *r   