o
    4cK                     @   st  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 ddlmZ G dd	 d	eZ	G d
d de	Z
G dd de	ZG dd de	ZG dd de	ZG dd de	ZG dd de	ZG dd deZG dd deee	ZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZdS ),z5defines the parse tree components for Mako templates.    N)ast)compat)
exceptions)filters)utilc                   @   s4   e Zd ZdZdd Zedd Zdd Zdd	 Zd
S )Nodez(base class for a Node in the parse tree.c                 C   s   || _ || _|| _|| _d S Nsourcelinenoposfilename)selfr
   r   r   r    r   D/var/www/html/gps/gps/lib/python3.10/site-packages/mako/parsetree.py__init__   s   
zNode.__init__c                 C   s   | j | j| j| jdS )Nr	   r	   r   r   r   r   exception_kwargs   s
   zNode.exception_kwargsc                 C      g S r   r   r   r   r   r   get_children%      zNode.get_childrenc                    s,    fdd}t  d| jj |}||  d S )Nc                    s   |   D ]}|  qd S r   )r   accept_visitor)nodenvisitorr   r   traverse)   s   z%Node.accept_visitor.<locals>.traversevisit)getattr	__class____name__)r   r   r   methodr   r   r   r   (   s   zNode.accept_visitorN)	r    
__module____qualname____doc__r   propertyr   r   r   r   r   r   r   r      s    
r   c                       0   e Zd ZdZ fddZdd Zdd Z  ZS )TemplateNodez?a 'container' node that stores the overall collection of nodes.c                    s&   t t| ddd| g | _i | _d S )N r   )superr'   r   nodespage_attributes)r   r   r   r   r   r   5   s   
zTemplateNode.__init__c                 C      | j S r   r*   r   r   r   r   r   :      zTemplateNode.get_childrenc                 C   s   dt | j| jf S )NzTemplateNode(%s, %r))r   sorted_dict_reprr+   r*   r   r   r   r   __repr__=   s   
zTemplateNode.__repr__)r    r"   r#   r$   r   r   r1   __classcell__r   r   r,   r   r'   1   s
    r'   c                       sL   e Zd ZdZdZ fddZdd Zdd Zd	d
 Zdd Z	dd Z
  ZS )ControlLinezdefines a control line, a line-oriented python line or end tag.

    e.g.::

        % if foo:
            (markup)
        % endif

    Fc                    sv   t t| jdi | || _|| _|| _|dv | _g | _| jr'g | _g | _	d S t
j|fi | j}|j| _|j| _	d S )N)forifwhiletrywithr   )r)   r3   r   textkeywordisend
is_primaryr*   _declared_identifiers_undeclared_identifiersr   PythonFragmentr   declared_identifiersundeclared_identifiers)r   r:   r;   r9   kwargscoder,   r   r   r   R   s   

zControlLine.__init__c                 C   r-   r   r.   r   r   r   r   r   a   r/   zControlLine.get_childrenc                 C   r-   r   )r=   r   r   r   r   r@   d   r/   z ControlLine.declared_identifiersc                 C   r-   r   )r>   r   r   r   r   rA   g   r/   z"ControlLine.undeclared_identifiersc                 C   s0   |t ddgt ddgt dgd| jg v S )zRreturn true if the given keyword is a ternary keyword
        for this ControlLineelseelifexceptfinally)r5   r7   r4   )setgetr:   )r   r:   r   r   r   
is_ternaryj   s   


zControlLine.is_ternaryc                 C   s   d| j | j| j| j| jff S )NzControlLine(%r, %r, %r, %r))r:   r9   r;   r   r   r   r   r   r   r1   t   s   
zControlLine.__repr__)r    r"   r#   r$   has_loop_contextr   r   r@   rA   rJ   r1   r2   r   r   r,   r   r3   D   s    

r3   c                       (   e Zd ZdZ fddZdd Z  ZS )Textz#defines plain text in the template.c                        t t| jdi | || _d S Nr   )r)   rM   r   content)r   rP   rB   r,   r   r   r         
zText.__init__c                 C      d| j | j| jff S )NzText(%r, %r))rP   r   r   r   r   r   r   r1         zText.__repr__r    r"   r#   r$   r   r1   r2   r   r   r,   r   rM   }   s    rM   c                       8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
Codezdefines a Python code block, either inline or module level.

    e.g.::

        inline:
        <%
            x = 12
        %>

        module level:
        <%!
            import logger
        %>

    c                    s<   t t| jdi | || _|| _tj|fi | j| _d S rO   )	r)   rV   r   r9   ismoduler   
PythonCoder   rC   )r   r9   rW   rB   r,   r   r   r      s   zCode.__init__c                 C      | j jS r   )rC   r@   r   r   r   r   r@         zCode.declared_identifiersc                 C   rY   r   )rC   rA   r   r   r   r   rA      rZ   zCode.undeclared_identifiersc                 C   s   d| j | j| j| jff S )NzCode(%r, %r, %r))r9   rW   r   r   r   r   r   r   r1      s
   
zCode.__repr__	r    r"   r#   r$   r   r@   rA   r1   r2   r   r   r,   r   rV      s    rV   c                       rL   )Commentz6defines a comment line.

    # this is a comment

    c                    rN   rO   )r)   r\   r   r9   )r   r9   rB   r,   r   r   r      rQ   zComment.__init__c                 C   rR   )NzComment(%r, %r))r9   r   r   r   r   r   r   r1      rS   zComment.__repr__rT   r   r   r,   r   r\      s    r\   c                       rU   )

Expressionz/defines an inline expression.

    ${x+y}

    c                    sR   t t| jdi | || _|| _tj|fi | j| _tj	|fi | j| _
d S rO   )r)   r]   r   r9   escapesr   ArgumentListr   escapes_coderX   rC   )r   r9   r^   rB   r,   r   r   r      s
   zExpression.__init__c                 C   r   r   r   r   r   r   r   r@      r   zExpression.declared_identifiersc                 C   s,   | j j| jjttj | j j	S r   )
rC   rA   unionr`   
differencerH   r   DEFAULT_ESCAPESkeysr@   r   r   r   r   rA      s   
z!Expression.undeclared_identifiersc                 C   s   d| j | jj| j| jff S )NzExpression(%r, %r, %r))r9   r`   argsr   r   r   r   r   r   r1      s
   
zExpression.__repr__r[   r   r   r,   r   r]      s    r]   c                       s,   e Zd ZdZi Z fddZdd Z  ZS )_TagMetazImetaclass to allow Tag to produce a subclass according to
    its keywordc                    s4   t | dd d ur| | j| j< tt| ||| d S )N__keyword__)r   	_classmaprg   r)   rf   r   )clsclsnamebasesdict_r,   r   r   r      s   z_TagMeta.__init__c              
   K   s   d|v r| d\}}tjt|||fi |S ztj| } W n ty9   tjd| |d |d |d |d dw tj| ||fi |S )N:zNo such tag: '%s'r
   r   r   r   r	   )	splittype__call__CallNamespaceTagrf   rh   KeyErrorr   CompileException)ri   r:   
attributesrB   nsdefnamer   r   r   rp      s&   z_TagMeta.__call__)r    r"   r#   r$   rh   r   rp   r2   r   r   r,   r   rf      s
    rf   c                       sT   e Zd ZdZdZ fddZdd Zdd Zd	d
 Zdd Z	dd Z
dd Z  ZS )Tagzabstract base class for tags.

    e.g.::

        <%sometag/>

        <%someothertag>
            stuff
        </%someothertag>

    Nc                    s   t t jdi | | _| _ ||  fdd|D }t|r8tjdd	dd |D  fi  j
d _g  _dS )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)

        c                    s   g | ]	}| j vr|qS r   )parsed_attributes).0rr   r   r   
<listcomp>0      z Tag.__init__.<locals>.<listcomp>zMissing attribute(s): %s,c                 S   s   g | ]}t |qS r   )repr)ry   mr   r   r   r{   4  s    Nr   )r)   rw   r   r:   rt   _parse_attributeslenr   rs   joinr   parentr*   )r   r:   rt   expressionsnonexpressionsrequiredrB   missingr,   r   r   r     s   
zTag.__init__c                 C   
   | j d u S r   )r   r   r   r   r   is_root:  s   
zTag.is_rootc                 C   r-   r   r.   r   r   r   r   r   =  r/   zTag.get_childrenc           	      C   s<  t  }i | _| jD ]}||v rcg }tdtj| j| D ]7}tdtj|}|rLtj	|
d fi | j}||j}|d|
d  q|rU|t| qd|p^td| j|< q	||v rtd| j| rtjd|| jf fi | jt| j| | j|< q	tjd	| j|f fi | j|| _d S )
Nz	(\${.+?})z^\${(.+?)}$   z(%s)z + r(   z\${.+?}z=Attibute '%s' in tag '%s' does not allow embedded expressionsz$Invalid attribute for tag '%s': '%s')rH   rx   rt   recompileSrn   matchr   rX   grouprstripr   ra   rA   appendr~   r   searchr   rs   r:   !expression_undeclared_identifiers)	r   r   r   rA   keyexprxr   rC   r   r   r   r   @  sR   

zTag._parse_attributesc                 C   r   r   r   r   r   r   r   r@   j  r   zTag.declared_identifiersc                 C   r-   r   )r   r   r   r   r   rA   m  r/   zTag.undeclared_identifiersc                 C   s*   d| j j| jt| j| j| jf| jf S )Nz%s(%r, %s, %r, %r))	r   r    r:   r   r0   rt   r   r   r*   r   r   r   r   r1   p  s   

zTag.__repr__)r    r"   r#   r$   rg   r   r   r   r   r@   rA   r1   r2   r   r   r,   r   rw     s    **rw   c                       s4   e Zd ZdZ fddZdd Z fddZ  ZS )
IncludeTagincludec                    sF   t t| j||dddfi | tjd|dd fi | j| _d S )N)fileimportre   r   r   z__DUMMY(%s)re   r(   )r)   r   r   r   rX   rI   r   	page_argsr   r:   rt   rB   r,   r   r   r   }  s   
zIncludeTag.__init__c                 C   r   r   r   r   r   r   r   r@     r   zIncludeTag.declared_identifiersc                    s2   | j jtdg| j j}|tt|  S )N__DUMMY)r   rA   rb   rH   r@   ra   r)   r   )r   identifiersr,   r   r   rA     s   
z!IncludeTag.undeclared_identifiersr    r"   r#   rg   r   r@   rA   r2   r   r   r,   r   r   z  s
    r   c                       rL   )NamespaceTag	namespacec                    s   t t| j||dddfi | |ddttt|  | _d|vr1d|vr1tj		di | j
d|v rCd	|v rEtj		
di | j
d S d S )Nr   )nameinheritabler   moduler   r   z	__anon_%sr   ?'name' and/or 'import' attributes are required for <%namespace>r   r   4<%namespace> may only have one of 'file' or 'module')r   )r   )r)   r   r   rI   hexabsidr   r   rs   r   r   r,   r   r   r     s.   
	zNamespaceTag.__init__c                 C   r   r   r   r   r   r   r   r@     r   z!NamespaceTag.declared_identifiersr    r"   r#   rg   r   r@   r2   r   r   r,   r   r     s    r   c                       rL   )TextTagr9   c                    sB   t t| j||dddfi | tj|ddfi | j| _d S )Nr   filterr(   )r)   r   r   r   r_   rI   r   filter_argsr   r,   r   r   r     s   


zTextTag.__init__c                 C      | j jtj | jS r   r   rA   rb   r   rc   rd   ra   r   r   r   r   r   rA     s
   zTextTag.undeclared_identifiers)r    r"   r#   rg   r   rA   r2   r   r   r,   r   r     s    r   c                       sL   e Zd ZdZ fddZdZdZedd Zdd Z	d	d
 Z
dd Z  ZS )DefTagdefc                    s   ddgdd |D  }t t| j|||ddfi | |d }td|r/tj		di | jtj	d
| d fi | j| _
| j
j| _|dd| _tj|ddfi | j| _d S )Nbufferedcachedc                 S      g | ]	}| d r|qS cache_
startswithry   cr   r   r   r{     
    
z#DefTag.__init__.<locals>.<listcomp>r   r   	decoratorr   r   ^[\w_]+$Missing parenthesis in %defzdef z:passr   r(   r   )r   )r)   r   r   r   r   r   rs   r   r   FunctionDeclfunction_declfuncnamer   rI   r   r_   r   r   r:   rt   rB   r   r   r,   r   r   r     s>   



zDefTag.__init__Fc                 C   rY   r   )r   r   r   r   r   r   r     s   zDefTag.funcnamec                 K      | j jdi |S rO   )r   get_argument_expressionsr   kwr   r   r   r        zDefTag.get_argument_expressionsc                 C   rY   r   )r   allargnamesr   r   r   r   r@     rZ   zDefTag.declared_identifiersc                 C   s`   g }| j jD ]}|ttj|fi | jj7 }qt|| j	j
tj | j
| j jS r   )r   defaultslistr   rX   r   rA   rH   ra   r   rb   r   rc   rd   r   r   )r   resr   r   r   r   rA     s&   
zDefTag.undeclared_identifiers)r    r"   r#   rg   r   is_anonymousis_blockr%   r   r   r@   rA   r2   r   r   r,   r   r     s    
r   c                       sT   e Zd ZdZ fddZdZedd Zedd Zd	d
 Z	dd Z
dd Z  ZS )BlockTagblockc                    s   g ddd |D  }t t| j|||ddfi | |d}|r2td|s2tj	di | j|sD|d	d rDtj	
di | jt	j
|d	dfi | j| _|| _|dd| _t	j|ddfi | j| _d S )N)r   r   re   c                 S   r   r   r   r   r   r   r   r{     r   z%BlockTag.__init__.<locals>.<listcomp>r   r   r   r   ,%block may not specify an argument signaturere   #Only named %blocks may specify argsr(   r   r   )r   )r   )r)   r   r   rI   r   r   r   rs   r   r   FunctionArgs	body_declr   r   r_   r   r   r,   r   r   r     sJ   



zBlockTag.__init__Tc                 C   r   r   r   r   r   r   r   r   *  s   
zBlockTag.is_anonymousc                 C   s   | j pd| jf S )Nz__M_anon_%d)r   r   r   r   r   r   r   .  s   zBlockTag.funcnamec                 K   r   rO   )r   r   r   r   r   r   r   2  r   z!BlockTag.get_argument_expressionsc                 C   rY   r   r   r   r   r   r   r   r@   5  rZ   zBlockTag.declared_identifiersc                 C   r   r   r   r   r   r   r   rA   8  s
   zBlockTag.undeclared_identifiers)r    r"   r#   rg   r   r   r%   r   r   r   r@   rA   r2   r   r   r,   r   r     s    !

r   c                       r&   )CallTagcallc                    sd   t t| j||dddfi | |d | _tj| jfi | j| _tj|	ddfi | j| _
d S )Nre   )r   r   r(   )r)   r   r   
expressionr   rX   r   rC   r   rI   r   r   r,   r   r   r   C  s   



zCallTag.__init__c                 C      | j j| jjS r   rC   r@   ra   r   r   r   r   r   r   r@   M  r   zCallTag.declared_identifiersc                 C      | j j| j jS r   rC   rA   rb   r@   r   r   r   r   rA   P     zCallTag.undeclared_identifiersr   r   r   r,   r   r   @  s
    
r   c                       s,   e Zd Z fddZdd Zdd Z  ZS )rq   c                    s   t t| j|d | |t| d ddfi | d||ddd | j D f | _t	j
| jfi | j| _t	j|dd	fi | j| _d S )
Nrm   )re   r   z	%s.%s(%s)r}   c                 S   s$   g | ]\}}|d krd||f qS )re   z%s=%sr   )ry   kvr   r   r   r{   e  s    
z-CallNamespaceTag.__init__.<locals>.<listcomp>re   r(   )r)   rq   r   tuplerd   r   rx   itemsr   r   rX   r   rC   r   rI   r   )r   r   rv   rt   rB   r,   r   r   r   W  s0   

	
zCallNamespaceTag.__init__c                 C   r   r   r   r   r   r   r   r@   q  r   z%CallNamespaceTag.declared_identifiersc                 C   r   r   r   r   r   r   r   rA   t  r   z'CallNamespaceTag.undeclared_identifiers)r    r"   r#   r   r@   rA   r2   r   r   r,   r   rq   V  s    rq   c                       s    e Zd ZdZ fddZ  ZS )
InheritTaginheritc                    s$   t t| j||dddfi | d S )Nr   r   )r)   r   r   r   r,   r   r   r   }  s
   


zInheritTag.__init__)r    r"   r#   rg   r   r2   r   r   r,   r   r   z  s    r   c                       rL   )PageTagpagec                    sv   g ddd |D  }t t| j|||ddfi | tj|ddfi | j| _tj|ddfi | j| _	d S )N)r   re   expression_filterenable_loopc                 S   r   r   r   r   r   r   r   r{     r|   z$PageTag.__init__.<locals>.<listcomp>r   re   r(   r   )
r)   r   r   r   r   rI   r   r   r_   r   )r   r:   rt   rB   r   r,   r   r   r     s$   



zPageTag.__init__c                 C   rY   r   r   r   r   r   r   r@     rZ   zPageTag.declared_identifiersr   r   r   r,   r   r     s    r   )r$   r   makor   r   r   r   r   objectr   r'   r3   rM   rV   r\   r]   ro   rf   with_metaclassrw   r   r   r   r   r   r   rq   r   r   r   r   r   r   <module>   s2   9&" y?<$	