o
    .dB                     @  s  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 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rdd l(m)Z) dd!l*m+Z+ dd"l,m-Z- d#Z.G d$d% d%Z/G d&d' d'e/Z0G d(d) d)e/Z1G d*d+ d+e0Z2G d,d- d-ee3ee3 f Z4d.S )/zLiquid template definition.    )annotations)Counter)abc)StringIO)Path)TYPE_CHECKING)Any)	Awaitable)Dict)Iterator)Mapping)Optional)TextIO)Union)Context)FutureContext)FutureVariableCaptureContext)ReadOnlyChainMap)VariableCaptureContext)Error)LiquidInterrupt)LiquidSyntaxError)
StopRender)LimitedStringIO)ContextualTemplateAnalysis)NameRefsReferencedVariable)Refs)TemplateAnalysis)_TemplateCounter)Environment)	ParseTree)UpToDate)
AwareBoundTemplateBoundTemplater   FutureAwareBoundTemplateFutureBoundTemplater   r   r   r   TemplateDropc                   @  s   e Zd ZdZeZeZ					dFdGddZdHddZ	dHddZ
dIddZddd dJd)d*Zddd dJd+d,ZedKd-d.ZdKd/d0ZdLd3d4ZdMd5d6ZdNd7d8Z	9dOdPd=d>Z	9dOdPd?d@ZdQdBdCZdQdDdEZdS )Rr%   a  A liquid template that has been parsed and is bound to a `liquid.Environment`.

    You probably don't want to instantiate `BoundTemplate` directly. Use
    `liquid.Environment.from_string` or `liquid.Environment.get_template` instead.

    Args:
        env: The environment this template is bound to.
        parse_tree: The parse tree representing this template.
        name: Optional name of the template. Defaults to an empty string.
        path: Optional origin path or identifier for the template.
        globals: An optional mapping of context variables made available every
            time the resulting template is rendered. Defaults to `None`.
        matter: Optional mapping containing variables associated with the template.
            Could be "front matter" or other meta data.
        uptodate: Optional callable that will return `True` if the template is up
            to date, or `False` if it needs to be reloaded. Defaults to `None`.
     Nenvr!   
parse_treer"   namestrpathOptional[Union[str, Path]]globalsOptional[Dict[str, object]]matterOptional[Mapping[str, object]]uptodater#   c                 C  s6   || _ || _|p	i | _|pi | _|| _|| _|| _d S N)r*   treer0   r2   r,   r.   r4   )selfr*   r+   r,   r.   r0   r2   r4    r8   G/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/template.py__init__O   s   



zBoundTemplate.__init__argsr   kwargsreturnc                 O  s>   | j | j| t|i || d}|  }| || | S )zRender the template with `args` and `kwargs` included in the render context.

        Accepts the same arguments as the `dict` constructor.
        r0   template)context_classr*   make_globalsdict_get_bufferrender_with_contextgetvaluer7   r;   r<   contextbufr8   r8   r9   rendera   s   zBoundTemplate.renderc                   sF   | j | j| t|i || d}|  }| ||I dH  | S )z;An async version of `liquid.template.BoundTemplate.render`.r>   N)r@   r*   rA   rB   rC   render_with_context_asyncrE   rF   r8   r8   r9   render_asynco   s   zBoundTemplate.render_asyncr   c                 C  s    | j jd u r	t S t| j jdS )N)limit)r*   output_stream_limitr   r   r7   r8   r8   r9   rC   z   s   zBoundTemplate._get_bufferF)partialblock_scoperG   r   bufferr   rO   boolrP   Nonec          
      O  s  |  |t|i |}|j|dn | jjD ]X}z||| W q tyI }	 z|r,|r>| jt	d|	 d|
 jd n W Y d}	~	qd}	~	w tyR   Y  n% tyn }	 z| jj|	|
 jd W Y d}	~	qd}	~	ww W d   dS W d   dS 1 sw   Y  dS )a(  Render the template using an existing context and output buffer.

        Args:
            context: A render context.
            buffer: File-like object to which rendered text is written.
            partial: If `True`, indicates that the current template has been
                included using either a "render" or "include" tag. Defaults to `False`.
            block_scope: If `True`, indicates that assigns, breaks and continues
                from this template will not leak into the parent context. Defaults to
                `False`.
            args: Passed to the `dict` constructor. The resulting dictionary is added to
                the render context.
            kwargs: Passed to the `dict` constructor. The resulting dictionary is added
                to the render context.
        	namespaceunexpected ''linenumN)make_partial_namespacerB   extendr6   
statementsrI   r   r*   errorr   tokenrY   r   r   
r7   rG   rQ   rO   rP   r;   r<   rU   nodeerrr8   r8   r9   rD      s2   ""z!BoundTemplate.render_with_contextc          
        s  |  |t|i |}|j|dq | jjD ][}z|||I dH  W q tyM }	 z|r0|rB| jt	d|	 d|
 jd n W Y d}	~	qd}	~	w tyV   Y  n% tyr }	 z| jj|	|
 jd W Y d}	~	qd}	~	ww W d   dS W d   dS 1 sw   Y  dS )z*An async version of `render_with_context`.rT   NrV   rW   rX   )rZ   rB   r[   r6   r\   rK   r   r*   r]   r   r^   rY   r   r   r_   r8   r8   r9   rJ      s4   ""z'BoundTemplate.render_with_context_asyncc                 C  s4   | j sdS |   }t|tstdt|j |S )z;`False` if the template has bee modified, `True` otherwise.Tz(expected a boolean from uptodate, found )r4   
isinstancerR   r   type__name__r7   r4   r8   r8   r9   is_up_to_date   s   
zBoundTemplate.is_up_to_datec                   s,   | j sdS |   }t|tr|I dH S |S )zAn async version of the `is_up_to_date` property.

        If `template.uptodate` is a coroutine, it wil be awaited. Otherwise it will be
        called just like `is_up_to_date`
        TN)r4   rb   r	   re   r8   r8   r9   is_up_to_date_async   s   

z!BoundTemplate.is_up_to_date_asyncrender_argsMapping[str, object]c                 C  s   t || j| jS )zAReturn a mapping including render arguments and template globals.)r   r2   r0   )r7   rh   r8   r8   r9   rA      s
   zBoundTemplate.make_globalsc                 C  s   i |d|iS )zuReturn a namespace dictionary.

        This is used by `render_with_context` to extend an existing context.
        rO   r8   r7   rO   rh   r8   r8   r9   rZ      s   	z$BoundTemplate.make_partial_namespacec                 C  s   d| j  d| j dS )NzTemplate(name='z	', path=''))r,   r.   rN   r8   r8   r9   __repr__  s   zBoundTemplate.__repr__Tfollow_partialsraise_for_failuresr   c              	   C  sp   t | ||d }tdd |j D dd |j D dd |j D t|jt|j	t|j
t|jdS )a  Statically analyze this template and any included/rendered templates.

        Args:
            follow_partials: If `True`, we will try to load partial templates and
                analyze those templates too.
            raise_for_failures: If `True`, will raise an exception if an
                `ast.Node` or `expression.Expression` does not define a `children()`
                method, or if a partial template can not be loaded. When `False`, no
                exception is raised and a mapping of failed nodes and expressions is
                available as the `failed_visits` property. A mapping of unloadable
                partial templates is stored in the `unloadable_partials` property.
        rm   rn   c                 S     i | ]	\}}t ||qS r8   r   .0kvr8   r8   r9   
<dictcomp>      z)BoundTemplate.analyze.<locals>.<dictcomp>c                 S  rp   r8   r   rq   r8   r8   r9   ru         c                 S  rp   r8   r   rq   r8   r8   r9   ru   "  rw   	variableslocal_variablesglobal_variablesfailed_visitsunloadable_partialsfilterstags)r    analyzer   ry   itemstemplate_localstemplate_globalsrB   r|   r}   r~   r   r7   rm   rn   refsr8   r8   r9   r     s(   zBoundTemplate.analyzec              	     sx   t | ||d I dH }tdd |j D dd |j D dd |j D t|jt|j	t|j
t|jdS )zAn async version of `analyze`.ro   Nc                 S  rp   r8   r   rq   r8   r8   r9   ru   6  rv   z/BoundTemplate.analyze_async.<locals>.<dictcomp>c                 S  rp   r8   r   rq   r8   r8   r9   ru   7  rw   c                 S  rp   r8   r   rq   r8   r8   r9   ru   :  rw   rx   )r    analyze_asyncr   ry   r   r   r   rB   r|   r}   r~   r   r   r8   r8   r9   r   +  s*   zBoundTemplate.analyze_asyncr   c                 O  sl   | j | j| t|i |d}|  }| || ttt|jtt|j	tt|j
tt|jdS )a  Analyze a path through this template's syntax tree given some context data.

        Unlike `analyze`, this form of template analysis does perform a render,
        capturing template variables as we go.

        Python Liquid does not currently support template introspection from within a
        render context or `Expression` object. Meaning line numbers and template names
        are not available. Only variable names are reported along with the number of
        times they were referenced.

        It's also, using this method, not currently possible to detect names added to a
        block's scope. For example, `forloop.index` will be included in the results
        object if referenced within a `for` loop block.

        Accepts the same arguments as `render`.
        r0   all_variablesrz   undefined_variablesr~   )capture_context_classr*   rA   rB   rC   rD   r   r   all_referenceslocal_referencesundefined_referencesr~   rF   r8   r8   r9   analyze_with_contextC  s   z"BoundTemplate.analyze_with_contextc                   st   | j | j| t|i |d}|  }| ||I dH  ttt|jtt|j	tt|j
tt|jdS )z+An async version of `analyze_with_context`.r   Nr   )r   r*   rA   rB   rC   rJ   r   r   r   r   r   r~   rF   r8   r8   r9   analyze_with_context_asyncb  s   z(BoundTemplate.analyze_with_context_async)r)   NNNN)r*   r!   r+   r"   r,   r-   r.   r/   r0   r1   r2   r3   r4   r#   )r;   r   r<   r   r=   r-   )r=   r   )rG   r   rQ   r   r;   r   rO   rR   rP   rR   r<   r   r=   rS   )r=   rR   )rh   ri   r=   ri   )rO   rR   rh   ri   r=   ri   r=   r-   )TT)rm   rR   rn   rR   r=   r   )r;   r   r<   r   r=   r   )rd   
__module____qualname____doc__r   r@   r   r   r:   rI   rK   rC   rD   rJ   propertyrf   rg   rA   rZ   rl   r   r   r   r   r8   r8   r8   r9   r%   7   s>    



8%



$
r%   c                      s0   e Zd ZdZd fddZd fddZ  ZS )r$   zIA `BoundTemplate` subclass with a `TemplateDrop` in the global namespace.r;   r   r<   r=   rS   c                   s&   t  j|i | t| j| j| _d S r5   )superr:   r(   r,   r.   drop)r7   r;   r<   	__class__r8   r9   r:   v  s   zAwareBoundTemplate.__init__rO   rR   rh   ri   abc.Mapping[str, object]c                   s   d| j it ||S )Nr?   )r   r   rZ   rj   r   r8   r9   rZ   z  s   z)AwareBoundTemplate.make_partial_namespace)r;   r   r<   r   r=   rS   )rO   rR   rh   ri   r=   r   )rd   r   r   r   r:   rZ   __classcell__r8   r8   r   r9   r$   s  s    r$   c                   @     e Zd ZdZeZeZdS )r'   zrA `BoundTemplate` configured to use the `FutureContext` render context.

    See `liquid.future.Environment`.
    Nrd   r   r   r   r   r@   r   r   r8   r8   r8   r9   r'     s    r'   c                   @  r   )r&   zA `BoundTemplate` configured to use the `FutureContext` render context.

    Inserts a `TemplateDrop` into the global namespace automatically.

    See `liquid.future.Environment`.
    Nr   r8   r8   r8   r9   r&     s    r&   c                   @  sV   e Zd ZdZdddZdd	d
ZdddZdddZd ddZd!ddZ	d"ddZ
dS )#r(   zTemplate meta data mapping.r,   r-   r.   r/   c                 C  s~   || _ || _| jrt| jtrt| j | _| jj| _d | _d| jv r+| jdd | _| jjj | jj dd | jd| _	d S )N.r   )	directoryr,   suffix)
r,   r.   rb   r-   r   stemr   splitparent_items)r7   r,   r.   r8   r8   r9   r:     s   

zTemplateDrop.__init__r=   c                 C  s   | j S r5   )r   rN   r8   r8   r9   __str__  s   zTemplateDrop.__str__c                 C  s$   d| d  d| d  d| d  dS )NzTemplateDrop(directory='r   z	', name='r,   z', suffix='r   rk   r8   rN   r8   r8   r9   rl     s   zTemplateDrop.__repr__itemobjectrR   c                 C  s
   || j v S r5   )r   )r7   r   r8   r8   r9   __contains__     
zTemplateDrop.__contains__keyOptional[str]c                 C  s   | j t| S r5   )r   r-   )r7   r   r8   r8   r9   __getitem__  s   zTemplateDrop.__getitem__intc                 C  
   t | jS r5   )lenr   rN   r8   r8   r9   __len__  r   zTemplateDrop.__len__Iterator[str]c                 C  r   r5   )iterr   rN   r8   r8   r9   __iter__  r   zTemplateDrop.__iter__N)r,   r-   r.   r/   r   )r   r   r=   rR   )r   r   r=   r   )r=   r   )r=   r   )rd   r   r   r   r:   r   rl   r   r   r   r   r8   r8   r8   r9   r(     s    





r(   N)5r   
__future__r   collectionsr   r   ior   pathlibr   typingr   r   r	   r
   r   r   r   r   r   liquid.contextr   r   r   r   r   liquid.exceptionsr   r   r   r   liquid.outputr   liquid.static_analysisr   r   r   r   r   r    liquidr!   
liquid.astr"   liquid.loadersr#   __all__r%   r$   r'   r&   r-   r(   r8   r8   r8   r9   <module>   sV      >
 