a
    e	gMJ                     @   sb  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 d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d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)
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   Q/var/www/html/llm_bihealth/app/venv/lib/python3.9/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   s   g S r   r   r   r   r   r   get_children$   s    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                       s0   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  ddd| g | _i | _d S )N r   )superr   nodespage_attributes)r   r   r   r   r   r   4   s    zTemplateNode.__init__c                 C   s   | j S r   r&   r   r   r   r   r   9   s    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   r+   __classcell__r   r   r(   r   r#   0   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                    sp   t  jf i | || _|| _|| _|dv | _g | _| jrHg | _g | _n$t	j
|fi | j}|j| _|j| _d S )N)forifwhiletrywith)r%   r   textkeywordisendZ
is_primaryr&   _declared_identifiers_undeclared_identifiersr   ZPythonFragmentr   declared_identifiersundeclared_identifiers)r   r4   r5   r3   kwargscoder(   r   r   r   Q   s    
zControlLine.__init__c                 C   s   | j S r   r)   r   r   r   r   r   `   s    zControlLine.get_childrenc                 C   s   | j S r   )r6   r   r   r   r   r8   c   s    z ControlLine.declared_identifiersc                 C   s   | j S r   )r7   r   r   r   r   r9   f   s    z"ControlLine.undeclared_identifiersc                 C   s*   ddhddhdhd}|| | jt v S )zRreturn true if the given keyword is a ternary keyword
        for this ControlLineelseelifexceptfinally)r/   r1   r.   )getr4   set)r   r4   Zcasesr   r   r   
is_ternaryi   s
    zControlLine.is_ternaryc                 C   s   d| j | j| j| j| jff S )NzControlLine(%r, %r, %r, %r))r4   r3   r5   r
   r   r   r   r   r   r+   u   s    
zControlLine.__repr__)r   r   r    r!   Zhas_loop_contextr   r   r8   r9   rB   r+   r,   r   r   r(   r   r-   C   s   
r-   c                       s(   e Zd ZdZ fddZdd Z  ZS )Textz#defines plain text in the template.c                    s   t  jf i | || _d S r   )r%   r   content)r   rD   r:   r(   r   r   r      s    zText.__init__c                 C   s   d| j | j| jff S )NzText(%r, %r))rD   r
   r   r   r   r   r   r+      s    zText.__repr__r   r   r    r!   r   r+   r,   r   r   r(   r   rC   ~   s   rC   c                       s8   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                    s8   t  jf i | || _|| _tj|fi | j| _d S r   )r%   r   r3   ismoduler   
PythonCoder   r;   )r   r3   rG   r:   r(   r   r   r      s    zCode.__init__c                 C   s   | j jS r   )r;   r8   r   r   r   r   r8      s    zCode.declared_identifiersc                 C   s   | j jS r   )r;   r9   r   r   r   r   r9      s    zCode.undeclared_identifiersc                 C   s   d| j | j| j| jff S )NzCode(%r, %r, %r))r3   rG   r
   r   r   r   r   r   r+      s
    
zCode.__repr__	r   r   r    r!   r   r8   r9   r+   r,   r   r   r(   r   rF      s
   rF   c                       s(   e Zd ZdZ fddZdd Z  ZS )Commentz6defines a comment line.

    # this is a comment

    c                    s   t  jf i | || _d S r   )r%   r   r3   )r   r3   r:   r(   r   r   r      s    zComment.__init__c                 C   s   d| j | j| jff S )NzComment(%r, %r))r3   r
   r   r   r   r   r   r+      s    zComment.__repr__rE   r   r   r(   r   rJ      s   rJ   c                       s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )

Expressionz/defines an inline expression.

    ${x+y}

    c                    sN   t  jf i | || _|| _tj|fi | j| _tj|fi | j| _	d S r   )
r%   r   r3   escapesr   ArgumentListr   escapes_coderH   r;   )r   r3   rL   r:   r(   r   r   r      s
    zExpression.__init__c                 C   s   g S r   r   r   r   r   r   r8      s    zExpression.declared_identifiersc                 C   s$   | j j| jjtj| j jS r   )r;   r9   unionrN   
differencer   DEFAULT_ESCAPESr8   r   r   r   r   r9      s    z!Expression.undeclared_identifiersc                 C   s   d| j | jj| j| jff S )NzExpression(%r, %r, %r))r3   rN   argsr
   r   r   r   r   r   r+      s
    
zExpression.__repr__rI   r   r   r(   r   rK      s
   rK   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                    s0   t | dd d ur| | j| j< t ||| d S )N__keyword__)r   	_classmaprT   r%   r   )clsZclsnamebasesZ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yv   tjd| |d |d |d |d dY n0 tj| ||fi |S )N:zNo such tag: '%s'r	   r
   r   r   r   )	splittype__call__CallNamespaceTagrS   rU   KeyErrorr   CompileException)rV   r4   
attributesr:   nsdefnamer   r   r   r[      s$    z_TagMeta.__call__)r   r   r    r!   rU   r   r[   r,   r   r   r(   r   rS      s   rS   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  jf i | | _| _ ||  fdd|D }t|rlt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>,      z Tag.__init__.<locals>.<listcomp>zMissing attribute(s): %s,c                 s   s   | ]}t |V  qd S r   )repr)rd   mr   r   r   	<genexpr>1  rg   zTag.__init__.<locals>.<genexpr>N)r%   r   r4   r_   _parse_attributeslenr   r^   joinr   parentr&   )r   r4   r_   expressionsnonexpressionsrequiredr:   missingr(   r   r   r     s    zTag.__init__c                 C   s
   | j d u S r   )ro   r   r   r   r   is_root9  s    zTag.is_rootc                 C   s   | j S r   r)   r   r   r   r   r   <  s    zTag.get_childrenc           	      C   sD  t  }i | _| jD ]$}||v rg }tdtj| j| D ]n}tdtj|}|rtj	|
d fi | j}||j}|d|
d  q>|r>|t| q>d|ptd| j|< q||v rtd| j| rtjd|| jf fi | jt| j| | j|< qtjd	| j|f fi | jq|| _d S )
Nz(\${(?:[^$]*?{.+|.+?)})z^\${(.+?)}$   z(%s)z + r$   z\${.+?}z>Attribute '%s' in tag '%s' does not allow embedded expressionsz$Invalid attribute for tag '%s': '%s')rA   rc   r_   recompileSrY   matchr   rH   grouprstripr   rO   r9   appendri   rn   searchr   r^   r4   !expression_undeclared_identifiers)	r   rp   rq   r9   keyexprxrj   r;   r   r   r   rl   ?  sP    
zTag._parse_attributesc                 C   s   g S r   r   r   r   r   r   r8   h  s    zTag.declared_identifiersc                 C   s   | j S r   )r~   r   r   r   r   r9   k  s    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   r4   r   r*   r_   r
   r   r&   r   r   r   r   r+   n  s    

zTag.__repr__)r   r   r    r!   rT   r   rt   r   rl   r8   r9   r+   r,   r   r   r(   r   rb      s   -)rb   )	metaclassc                       s4   e Zd ZdZ fddZdd Z fddZ  ZS )
IncludeTagincludec                    sB   t  j||dddfi | tjd|dd fi | j| _d S )N)fileimportrR   r   r   z__DUMMY(%s)rR   r$   )r%   r   r   rH   r@   r   	page_argsr   r4   r_   r:   r(   r   r   r   {  s    zIncludeTag.__init__c                 C   s   g S r   r   r   r   r   r   r8     s    zIncludeTag.declared_identifiersc                    s*   | j jdh| j j}|t  S )NZ__DUMMY)r   r9   rP   r8   rO   r%   )r   Zidentifiersr(   r   r   r9     s    z!IncludeTag.undeclared_identifiersr   r   r    rT   r   r8   r9   r,   r   r   r(   r   r   x  s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )NamespaceTag	namespacec                    s   t  j||dddfi | |ddttt|  | _d|vr\d|vr\tjdi | j	d|v r~d	|v r~tjdi | j	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@   hexabsidr   r   r^   r   r   r(   r   r   r     s,    	  zNamespaceTag.__init__c                 C   s   g S r   r   r   r   r   r   r8     s    z!NamespaceTag.declared_identifiersr   r   r    rT   r   r8   r,   r   r   r(   r   r     s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )TextTagr3   c                    s>   t  j||dddfi | tj|ddfi | j| _d S )Nr   filterr$   )r%   r   r   rM   r@   r   filter_argsr   r(   r   r   r     s    
zTextTag.__init__c                 C   s   | j jtj | jS r   r   r9   rP   r   rQ   keysrO   r~   r   r   r   r   r9     s
    zTextTag.undeclared_identifiers)r   r   r    rT   r   r9   r,   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  j|||ddfi | |d }td|rXt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   s   g | ]}| d r|qS Zcache_
startswithrd   cr   r   r   rf     s   z#DefTag.__init__.<locals>.<listcomp>r   r   	decoratorr   r   ^[\w_]+$Missing parenthesis in %defzdef z:passr   r$   r   )r   )r%   r   rv   ry   r   r^   r   r   ZFunctionDeclfunction_declfuncnamer   r@   r   rM   r   r   r4   r_   r:   rp   r   r(   r   r   r     s>     


zDefTag.__init__Fc                 C   s   | j jS r   )r   r   r   r   r   r   r     s    zDefTag.funcnamec                 K   s   | j jf i |S r   )r   get_argument_expressionsr   kwr   r   r   r     s    zDefTag.get_argument_expressionsc                 C   s   | j jS r   )r   allargnamesr   r   r   r   r8     s    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   rH   r   r9   rA   rO   r   rP   r   rQ   r   r~   r   )r   resr   r   r   r   r9     s&    zDefTag.undeclared_identifiers)r   r   r    rT   r   is_anonymousis_blockr"   r   r   r8   r9   r,   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  j|||ddfi | |d}|r^td|s^tjdi | j|s|d	d rt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   rR   c                 S   s   g | ]}| d r|qS r   r   r   r   r   r   rf     s   z%BlockTag.__init__.<locals>.<listcomp>r   r   r   r   ,%block may not specify an argument signaturerR   #Only named %blocks may specify argsr$   r   r   )r   )r   )r%   r   r@   rv   ry   r   r^   r   r   FunctionArgs	body_declr   r   rM   r   r   r(   r   r   r     sJ    
  

zBlockTag.__init__Tc                 C   s
   | j d u S 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   s   | j jf i |S r   )r   r   r   r   r   r   r   ,  s    z!BlockTag.get_argument_expressionsc                 C   s   | j jS r   r   r   r   r   r   r   r8   /  s    zBlockTag.declared_identifiersc                 C   s   | j jtj | jS r   r   r   r   r   r   r9   2  s    zBlockTag.undeclared_identifiers)r   r   r    rT   r   r   r"   r   r   r   r8   r9   r,   r   r   r(   r   r     s   !

r   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )CallTagcallc                    s`   t  j||dddfi | |d | _tj| jfi | j| _tj|ddfi | j| _	d S )NrR   )r   r   r$   )
r%   r   
expressionr   rH   r   r;   r   r@   r   r   r(   r   r   r   =  s    


zCallTag.__init__c                 C   s   | j j| jjS r   r;   r8   rO   r   r   r   r   r   r   r8   G  s    zCallTag.declared_identifiersc                 C   s   | j j| j jS r   r;   r9   rP   r8   r   r   r   r   r9   J  s    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 )r\   c                    s   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 )
NrX   )rR   r   z	%s.%s(%s)rh   c                 s   s&   | ]\}}|d krd||f V  qdS )rR   z%s=%sNr   )rd   kvr   r   r   rk   ^  s   z,CallNamespaceTag.__init__.<locals>.<genexpr>rR   r$   )r%   r   tupler   rn   rc   itemsr   r   rH   r   r;   r   r@   r   )r   r   ra   r_   r:   r(   r   r   r   Q  s,    
	


zCallNamespaceTag.__init__c                 C   s   | j j| jjS r   r   r   r   r   r   r8   j  s    z%CallNamespaceTag.declared_identifiersc                 C   s   | j j| j jS r   r   r   r   r   r   r9   m  s    z'CallNamespaceTag.undeclared_identifiers)r   r   r    r   r8   r9   r,   r   r   r(   r   r\   P  s   r\   c                       s    e Zd ZdZ fddZ  ZS )
InheritTagZinheritc                    s    t  j||dddfi | d S )Nr   r   )r%   r   r   r(   r   r   r   v  s
    
zInheritTag.__init__)r   r   r    rT   r   r,   r   r   r(   r   r   s  s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )PageTagpagec                    sr   g ddd |D  }t  j|||ddfi | tj|ddfi | j| _tj|ddfi | j| _d S )N)r   rR   expression_filterZenable_loopc                 S   s   g | ]}| d r|qS r   r   r   r   r   r   rf     rg   z$PageTag.__init__.<locals>.<listcomp>r   rR   r$   r   )	r%   r   r   r   r@   r   r   rM   r   )r   r4   r_   r:   rp   r(   r   r   r     s    

zPageTag.__init__c                 C   s   | j jS r   r   r   r   r   r   r8     s    zPageTag.declared_identifiersr   r   r   r(   r   r   |  s   r   )r!   rv   Zmakor   r   r   r   r   r#   r-   rC   rF   rJ   rK   rZ   rS   rb   r   r   r   r   r   r   r\   r   r   r   r   r   r   <module>   s.   ;%!{?<#	