o
    ‹å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   úJ/var/www/html/flaskapp/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 )ÚControlLinez‰defines 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 )
ÚCodezÏdefines 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 )ÚTagzˆabstract 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 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¤Ž‚|| _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   ;%!{?<#	