o
    hMJ                     @   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   b/var/www/html/construction_image-detection-poc/venv/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  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      | j S r   r)   r   r   r   r   r   9      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   r0   __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                    sr   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(   r   textkeywordisend
is_primaryr)   _declared_identifiers_undeclared_identifiersr   PythonFragmentr   declared_identifiersundeclared_identifiers)r   r9   r:   r8   kwargscoder+   r   r   r   Q   s   

zControlLine.__init__c                 C   r,   r   r-   r   r   r   r   r   `   r.   zControlLine.get_childrenc                 C   r,   r   )r<   r   r   r   r   r?   c   r.   z ControlLine.declared_identifiersc                 C   r,   r   )r=   r   r   r   r   r@   f   r.   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)r4   r6   r3   )getr9   set)r   r9   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))r9   r8   r:   r
   r   r   r   r   r   r0   u   s   
zControlLine.__repr__)r   r!   r"   r#   has_loop_contextr   r   r?   r@   rJ   r0   r1   r   r   r+   r   r2   C   s    
r2   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  jdi | || _d S Nr   )r(   r   content)r   rP   rA   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   r0         zText.__repr__r   r!   r"   r#   r   r0   r1   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                    s8   t  jdi | || _|| _tj|fi | j| _d S rO   )r(   r   r8   ismoduler   
PythonCoder   rB   )r   r8   rW   rA   r+   r   r   r      s   zCode.__init__c                 C      | j jS r   )rB   r?   r   r   r   r   r?         zCode.declared_identifiersc                 C   rY   r   )rB   r@   r   r   r   r   r@      rZ   zCode.undeclared_identifiersc                 C   s   d| j | j| j| jff S )NzCode(%r, %r, %r))r8   rW   r
   r   r   r   r   r   r0      s
   
zCode.__repr__	r   r!   r"   r#   r   r?   r@   r0   r1   r   r   r+   r   rV      s    rV   c                       rL   )Commentz6defines a comment line.

    # this is a comment

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

Expressionz/defines an inline expression.

    ${x+y}

    c                    sN   t  jdi | || _|| _tj|fi | j| _tj|fi | j| _	d S rO   )
r(   r   r8   escapesr   ArgumentListr   escapes_coderX   rB   )r   r8   r^   rA   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j| j jS r   )rB   r@   unionr`   
differencer   DEFAULT_ESCAPESr?   r   r   r   r   r@      s   
z!Expression.undeclared_identifiersc                 C   s   d| j | jj| j| jff S )NzExpression(%r, %r, %r))r8   r`   argsr
   r   r   r   r   r   r0      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                    s0   t | dd d ur| | j| j< t ||| d S )N__keyword__)r   	_classmaprf   r(   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__CallNamespaceTagre   rg   KeyErrorr   CompileException)rh   r9   
attributesrA   nsdefnamer   r   r   ro      s&   z_TagMeta.__call__)r   r!   r"   r#   rg   r   ro   r1   r   r   r+   r   re      s
    re   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di | | _| _ ||  fdd|D }t|r6t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)rx   mr   r   r   	<genexpr>1  s    zTag.__init__.<locals>.<genexpr>Nr   )r(   r   r9   rs   _parse_attributeslenr   rr   joinr   parentr)   )r   r9   rs   expressionsnonexpressionsrequiredrA   missingr+   r   r   r     s   
zTag.__init__c                 C   
   | j d u S r   )r   r   r   r   r   is_root9  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>Attribute '%s' in tag '%s' does not allow embedded expressionsz$Invalid attribute for tag '%s': '%s')rH   rw   rs   recompileSrm   matchr   rX   grouprstripr   ra   r@   appendr}   r   searchr   rr   r9   !expression_undeclared_identifiers)	r   r   r   r@   keyexprxr~   rB   r   r   r   r   ?  sR   

zTag._parse_attributesc                 C   r   r   r   r   r   r   r   r?   h  r   zTag.declared_identifiersc                 C   r,   r   )r   r   r   r   r   r@   k  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   r9   r   r/   rs   r
   r   r)   r   r   r   r   r0   n  s   

zTag.__repr__)r   r!   r"   r#   rf   r   r   r   r   r?   r@   r0   r1   r   r   r+   r   rv      s    -)rv   )	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importrd   r   r   z__DUMMY(%s)rd   r'   )r(   r   r   rX   rG   r   	page_argsr   r9   rs   rA   r+   r   r   r   {  s   zIncludeTag.__init__c                 C   r   r   r   r   r   r   r   r?     r   zIncludeTag.declared_identifiersc                    s*   | j jdh| j j}|t  S )N__DUMMY)r   r@   rb   r?   ra   r(   )r   identifiersr+   r   r   r@     s   
z!IncludeTag.undeclared_identifiersr   r!   r"   rf   r   r?   r@   r1   r   r   r+   r   r   x  s
    r   c                       rL   )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 rAd	|v rCt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   rG   hexabsidr   r   rr   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"   rf   r   r?   r1   r   r   r+   r   r     s    r   c                       rL   )TextTagr8   c                    s>   t  j||dddfi | tj|ddfi | j| _d S )Nr   filterr'   )r(   r   r   r_   rG   r   filter_argsr   r+   r   r   r     s   
zTextTag.__init__c                 C      | j jtj | jS r   r   r@   rb   r   rc   keysra   r   r   r   r   r   r@     s
   zTextTag.undeclared_identifiers)r   r!   r"   rf   r   r@   r1   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|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rx   cr   r   r   rz     
    
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   rr   r   r   FunctionDeclfunction_declfuncnamer   rG   r   r_   r   r   r9   rs   rA   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   r@   rH   ra   r   rb   r   rc   r   r   r   )r   resr   r   r   r   r@     s&   
zDefTag.undeclared_identifiers)r   r!   r"   rf   r   is_anonymousis_blockr$   r   r   r?   r@   r1   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}|r0td|s0tj	di | j|sB|d	d rBt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   rd   c                 S   r   r   r   r   r   r   r   rz     r   z%BlockTag.__init__.<locals>.<listcomp>r   r   r   r   ,%block may not specify an argument signaturerd   #Only named %blocks may specify argsr'   r   r   )r   )r   )r(   r   rG   r   r   r   rr   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   ,  r   z!BlockTag.get_argument_expressionsc                 C   rY   r   r   r   r   r   r   r   r?   /  rZ   zBlockTag.declared_identifiersc                 C   r   r   r   r   r   r   r   r@   2  s
   zBlockTag.undeclared_identifiers)r   r!   r"   rf   r   r   r$   r   r   r   r?   r@   r1   r   r   r+   r   r     s    !

r   c                       r%   )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 )Nrd   )r   r   r'   )
r(   r   
expressionr   rX   r   rB   r   rG   r   r   r+   r   r   r   =  s   


zCallTag.__init__c                 C      | j j| jjS r   rB   r?   ra   r   r   r   r   r   r   r?   G  r   zCallTag.declared_identifiersc                 C      | j j| j jS r   rB   r@   rb   r?   r   r   r   r   r@   J     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 )rp   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 )
Nrl   )rd   r   z	%s.%s(%s)r|   c                 s   s(    | ]\}}|d krd||f V  qdS )rd   z%s=%sNr   )rx   kvr   r   r   r   ^  s    
z,CallNamespaceTag.__init__.<locals>.<genexpr>rd   r'   )r(   r   tupler   r   rw   itemsr   r   rX   r   rB   r   rG   r   )r   r   ru   rs   rA   r+   r   r   r   Q  s,   
	


zCallNamespaceTag.__init__c                 C   r   r   r   r   r   r   r   r?   j  r   z%CallNamespaceTag.declared_identifiersc                 C   r   r   r   r   r   r   r   r@   m  r   z'CallNamespaceTag.undeclared_identifiers)r   r!   r"   r   r?   r@   r1   r   r   r+   r   rp   P  s    rp   c                       s    e Zd ZdZ fddZ  ZS )
InheritTag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"   rf   r   r1   r   r   r+   r   r   s  s    r   c                       rL   )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   rd   expression_filterenable_loopc                 S   r   r   r   r   r   r   r   rz     r{   z$PageTag.__init__.<locals>.<listcomp>r   rd   r'   r   )	r(   r   r   r   rG   r   r   r_   r   )r   r9   rs   rA   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   r&   r2   rM   rV   r\   r]   rn   re   rv   r   r   r   r   r   r   rp   r   r   r   r   r   r   <module>   s0   ;%!{?<#	