o
    .dy                      @   s4  d 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 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 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 ddlmZ ed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d S )!zCommon parse tree nodes.    )ABC)abstractmethod)
Collection)Dict)List)
NamedTuple)Optional)TextIO)Literal)Context)DisabledTagError)Error)
Expression)TOKEN_ILLEGAL)	TOKEN_TAG)Token c                   @   s   e Zd ZdZdZdZdefddZdee	 ddfd	d
Z
dededee fddZdededee fddZedededee fddZdededee fddZded fddZdS )Nodez)Base class for all nodes in a parse tree. Freturnc                 C   s   t | dt}|S )z!The token that started this node.tok)getattrIllegalToken)selftokenr   r   B/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/ast.pyr   $   s   z
Node.tokendisabled_tagsNc                 C   s:   |   }|jtkr|j|v rt|j d|jddS dS )zBRaise a DisabledTagError if this node's type is in the given list.z% usage is not allowed in this context)linenumN)r   typer   valuer   r   )r   r   r   r   r   r   raise_for_disabled)   s   
zNode.raise_for_disabledcontextbufferc                 C   s   |j r	| |j  | ||S )z<Check disabled tags before delegating to `render_to_output`.)r   r!   render_to_outputr   r"   r#   r   r   r   render2   s   zNode.renderc                    s<   |j r
| |j  t| dr| ||I dH S | ||S )z-An async version of `liquid.ast.Node.render`.render_to_output_asyncN)r   r!   hasattrr'   r$   r%   r   r   r   render_async8   s   
zNode.render_asyncc                 C      dS )z&Render this node to the output buffer.Nr   r%   r   r   r   r$   @   s    zNode.render_to_outputc                    s   |  ||S )z7An async version of `liquid.ast.Node.render_to_output`.)r$   r%   r   r   r   r'   H   s   zNode.render_to_output_async	ChildNodec                 C   s   t | jj d)zJReturn a list of child nodes and/or expressions associated with this node.z	.children)NotImplementedError	__class____name__r   r   r   r   childrenP   s   zNode.children)r.   
__module____qualname____doc__	__slots__force_outputr   r   r   strr!   r   r	   r   boolr&   r)   r   r$   r'   r   r0   r   r   r   r   r      s0    	
r   c                   @   s   e Zd ZU dZeed< dZee ed< dZ	ee
 ed< dZeee  ed< dZeee  ed< dZeed  ed	< dZeeeef  ed
< dS )r+   a  An AST node and expression pair with optional scope and load data.

    Args:
        linenum: The line number of the child's first token in the template source text.
        expression: An `liquid.expression.Expression`. If not `None`, this expression is
            expected to be related to the given `liquid.ast.Node`.
        node: A `liquid.ast.Node`. Typically a `BlockNode` or `ConditionalBlockNode`.
        template_scope: A list of names the parent node adds to the template "local"
            scope. For example, the built-in `assign`, `capture`, `increment` and
            `decrement` tags all add names to the template scope. This helps us
            identify, through static analysis, names that are assumed to be "global".
        block_scope: A list of names available to the given child node. For example,
            the `for` tag adds the name "forloop" for the duration of its block.
        load_mode: If not `None`, indicates that the given expression should be used to
            load a partial template. In "render" mode, the partial will be analyzed in
            an isolated namespace, without access to the parent's template local scope.
            In "include" mode, the partial will have access to the parents template
            local scope and the parent's scope can be updated by the partial template
            too.
        load_context: Meta data a template `Loader` might need to find the source
            of a partial template.
    r   N
expressionnodetemplate_scopeblock_scope)r&   includeextends	load_modeload_context)r.   r1   r2   r3   int__annotations__r8   r   r   r9   r   r:   r   r6   r;   r>   r
   r?   r   r   r   r   r   r+   U   s   
 r+   c                   @   sT   e Zd ZdZdZdddZdefddZdefd	d
Zde	de
dee fddZdS )	ParseTreez"The root node of all syntax trees.)
statementsversionr   Nc                 C   s
   g | _ d S NrC   r/   r   r   r   __init__{      
zParseTree.__init__c                 C      d dd | jD S )Nr   c                 s       | ]}t |V  qd S rE   r6   .0sr   r   r   	<genexpr>       z$ParseTree.__str__.<locals>.<genexpr>joinrC   r/   r   r   r   __str__~      zParseTree.__str__c                 C      d| j  dS )Nz
ParseTree()rF   r/   r   r   r   __repr__      zParseTree.__repr__r"   r#   c                 C   s   | j D ]}||| qd S rE   )rC   r&   )r   r"   r#   stmtr   r   r   r$      s   
zParseTree.render_to_output)r   N)r.   r1   r2   r3   r4   rG   r6   rS   rW   r   r	   r   r7   r$   r   r   r   r   rB   v   s    
rB   c                   @   sX   e Zd ZdZdZdefddZdefddZdefd	d
Z	de
dedee fddZdS )IllegalNodezParse tree node representing an illegal or unregistered tag.

    Illegal nodes are necessary when running in "warn" or "lax" mode. In
    strict mode, an exception should be raised as soon as an illegal token
    is found.
    r   r   c                 C   s
   || _ d S rE   r[   )r   r   r   r   r   rG      rH   zIllegalNode.__init__r   c                 C   r*   )Nr   r   r/   r   r   r   rS         zIllegalNode.__str__c                 C   rU   )NzIllegalNode(tok=rV   r[   r/   r   r   r   rW      rX   zIllegalNode.__repr__r"   r#   c                 C   s   d S rE   r   r%   r   r   r   r$      r\   zIllegalNode.render_to_outputN)r.   r1   r2   r3   r4   r   rG   r6   rS   rW   r   r	   r   r7   r$   r   r   r   r   rZ      s    rZ   c                   @   s   e Zd ZdZdZddedeee  fddZ	de
fd	d
Zdededee fddZdededee fddZded fddZdS )	BlockNodez8A parse tree node representing a sequence of statements.r   rC   forced_outputNr   rC   c                 C   s   || _ |pg | _d| _d S )NFr^   )r   r   rC   r   r   r   rG      s   

zBlockNode.__init__r   c                 C   rI   )Nr   c                 s   rJ   rE   rK   rL   r   r   r   rO      rP   z$BlockNode.__str__.<locals>.<genexpr>rQ   r/   r   r   r   rS      rT   zBlockNode.__str__r"   r#   c                 C   sN   | j D ]!}z||| W q ty$ } z|| W Y d }~qd }~ww dS NT)rC   r&   r   errorr   r"   r#   rY   errr   r   r   r$      s   
zBlockNode.render_to_outputc                    sV   | j D ]$}z|||I d H  W q ty( } z|| W Y d }~qd }~ww dS r`   )rC   r)   r   ra   rb   r   r   r   r'      s   
z BlockNode.render_to_output_asyncr+   c                    s    fdd j D S )Nc                    s   g | ]
}t  jj|d qS ))r   r9   )r+   r   r   )rM   rY   r/   r   r   
<listcomp>   s    z&BlockNode.children.<locals>.<listcomp>rF   r/   r   r/   r   r0      s   
zBlockNode.childrenrE   )r.   r1   r2   r3   r4   r   r   r   r   rG   r6   rS   r   r	   r7   r$   r'   r0   r   r   r   r   r]      s    	
r]   c                   @   s~   e Zd ZdZdZdededefddZde	fd	d
Z
dededee fddZdededee fddZded fddZdS )ConditionalBlockNodezHA node containing a sequence of statements and a conditional expression.r   	conditionblockr_   r   rg   rh   c                 C   s   || _ || _|| _|j| _d S rE   rf   )r   r   rg   rh   r   r   r   rG      s   zConditionalBlockNode.__init__r   c                 C   s   | j  d| j dS )Nz { z })rg   rh   r/   r   r   r   rS      s   zConditionalBlockNode.__str__r"   r#   c                 C   s"   | j |r| j|| dS dS NTF)rg   evaluaterh   r&   r%   r   r   r   r$      s   z%ConditionalBlockNode.render_to_outputc                    s0   | j |I d H r| j||I d H  dS dS ri   )rg   evaluate_asyncrh   r)   r%   r   r   r   r'      s
   z+ConditionalBlockNode.render_to_output_asyncr+   c                 C   s   t | jj| j| jdgS )N)r   r9   r8   )r+   r   r   rh   rg   r/   r   r   r   r0      s   zConditionalBlockNode.childrenN)r.   r1   r2   r3   r4   r   r   r]   rG   r6   rS   r   r	   r   r7   r$   r'   r   r0   r   r   r   r   re      s    
re   N)r3   abcr   r   typingr   r   r   r   r   r	   typing_extensionsr
   liquid.contextr   liquid.exceptionsr   r   liquid.expressionr   liquid.tokenr   r   r   r   r   r+   rB   rZ   r]   re   r   r   r   r   <module>   s0    :!+