o
    .dw                     @  sj  d Z ddlm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	 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%l0m1Z1 dd&l2m3Z3 erdd'l4m5Z5 dd(lm6Z6 dd)l7m8Z8 dd*l7m9Z9 dd+l7m:Z: dd,l;m<Z< dd-l=m>Z> G d.d/ d/Z?ed0d1dZdKdLZ@dMdNdOdPdQe+jAedRdQdRdSddQdTdUdfd[dXdYZBdS )\zCShared configuration from which templates can be loaded and parsed.    )annotationsN)	lru_cache)TYPE_CHECKING)Any)Callable)ClassVar)Dict)Iterator)Mapping)MutableMapping)Optional)Tuple)Type)Union)ast)builtin)loaders)InnerTagMap)TagAnalysis)	Undefined)Error)LiquidSyntaxError)TemplateInheritanceError)lookup_warning)parse_boolean_expression)$parse_boolean_expression_with_parens)parse_conditional_expression)(parse_conditional_expression_with_parens)parse_filtered_expression)parse_loop_expression)	get_lexer)Mode)
get_parser)TokenStream)BoundTemplate)LRUCache)Path)Context)BooleanExpression)FilteredExpression)LoopExpression)Tag)Tokenc                   @  s  e Zd ZU dZdZded< dZded< dZded< dZded	< e	Z
d
ddddejdedddddddddfdyd,d-Zdzd/d0Zd{d2d3Zd|d7d8Zd}d<d=Zd~d>d?ZddBdCZ	D			dddIdJZ	dddKdLZ	dddMdNZ	dddQdRZ	dddSdTZddWdXZddYdZZ	[ddd\dd`daZdddbddddeZdddbddfdgZ	dddidjZ		dddqdrZ dddtduZ!	dddwdxZ"dS )Environmenta  Shared configuration from which templates can be loaded and parsed.

    An `Environment` is where you might register custom tags and filters, or store
    global context variables that should be included with every template.

    Args:
        tag_start_string: The sequence of characters indicating the start of a
            liquid tag.
        tag_end_string: The sequence of characters indicating the end of a liquid
            tag.
        statement_start_string: The sequence of characters indicating the start of
            an output statement.
        statement_end_string: The sequence of characters indicating the end of an
            output statement.
        template_comments: If `True`, enable template comments. Where, by default,
            anything between `{#` and `#}` is considered a comment.
            `False`.
        comment_start_string: The sequence of characters indicating the start of a
            comment.
            `comment_start_string` to have any effect.
        comment_end_string: The sequence of characters indicating the end of a
            comment.
            `comment_end_string` to have any effect.
        tolerance: Indicates how tolerant to be of errors. Must be one of
            `Mode.LAX`, `Mode.WARN` or `Mode.STRICT`.
        loader: A template loader. If you want to use the builtin "render" or
            "include" tags, a loader must be configured.
            `liquid.loaders.DictLoader`.
        undefined: A subclass of `Undefined` that represents undefined values. Could be
            one of the built-in undefined types, `Undefined`, `DebugUndefined` or
            `StrictUndefined`. undefined type that silently ignores undefined values.
        strict_filters: If `True`, will raise an exception upon finding an
            undefined filter. Otherwise undefined filters are silently ignored. Defaults
            to `True`.
        autoescape: If `True`, all context values will be HTML-escaped before output
            unless they've been explicitly marked as "safe". Requires the package
            Markupsafe.
        auto_reload: If `True`, loaders that have an `uptodate` callable will
            reload template source data automatically. For deployments where template
            sources don't change between service reloads, setting auto_reload to `False`
            can yield an increase in performance by avoiding calls to `uptodate`.
            `.
        cache_size: The capacity of the template cache in number of templates.
            . If `cache_size` is `None` or less than `1`, it has the
            effect of setting `auto_reload` to `False`.
        expression_cache_size: The capacity of each of the common expression caches.
            `, disabling expression caching.
        globals: An optional mapping that will be added to the context of any
            template loaded from this environment.

    Attributes:
        context_depth_limit: Class attribute.The maximum number of times a render
            context can be extended or wrapped before a `ContextDepthError` is raised.
        local_namespace_limit: Class attribute. The maximum number of bytes (according
            to sys.getsizeof) allowed in a template's local namespace, per render,
            before a `LocalNamespaceLimitError` exception is raised. Note that we only
            count the size of the local namespace values, not its keys.
        loop_iteration_limit: Class attribute. The maximum number of loop iterations
            allowed before a  `liquid.exceptions.LoopIterationLimitError` is raised.
        output_stream_limit: Class attribute. The maximum number of bytes that can be
            written to a template's output stream, per render, before an
            `OutputStreamLimitError` exception is raised.
        undefined: The undefined type. When an identifier can not be resolved, an
            instance of `undefined` is returned.
        strict_filters: Indicates if an undefined filter should raise an exception or be
            ignored.
        autoescape: Indicates if auto-escape is enabled.
        tags: A dictionary mapping tag names to `liquid.tag.Tag` instances.
        filters: A dictionary mapping filter names to callable objects implementing a
            filter's behavior.
        mode: The current tolerance mode.
        cache: The template cache.
        auto_reload: Indicates if automatic reloading of templates is enabled.
        template_class: `Environment.get_template` and `Environment.from_string`
            return an instance of :attr:`Environment.template_class`.
            `liquid.template.BoundTemplate`.
        globals: A dictionary of variables that will be added to the context of every
            template rendered from the environment.
       zClassVar[int]context_depth_limitNzClassVar[Optional[int]]loop_iteration_limitlocal_namespace_limitoutput_stream_limit{%%}{{}}FT,  {##}r   tag_start_stringstrtag_end_stringstatement_start_stringstatement_end_string
strip_tagsbool	tolerancer!   loaderOptional[loaders.BaseLoader]	undefinedType[Undefined]strict_filters
autoescapeauto_reload
cache_sizeintglobalsOptional[Mapping[str, object]]template_commentscomment_start_stringcomment_end_stringexpression_cache_sizec                 C  s   || _ || _|| _|| _|| _|pti | _|pi | _|| _	|| _
|| _| j	s.d| _
d| _|| _|	| _|
| _i | _i | _|| _|rS|dkrS| jjsSt|| _|| _nd | _d| _|| _| | j\| _| _| _| _| _| _|   d S )N r   F)r:   r<   r=   r>   r?   r   
DictLoaderrB   rK   rM   rN   rO   rD   rF   rG   tagsfiltersmodecaching_loaderr%   cacherH   rP   _get_expression_parsersparse_boolean_expression_value*parse_boolean_expression_value_with_parens"parse_conditional_expression_value.parse_conditional_expression_value_with_parensparse_filtered_expression_valueparse_loop_expression_valuesetup_tags_and_filters)selfr:   r<   r=   r>   r?   rA   rB   rD   rF   rG   rH   rI   rK   rM   rN   rO   rP    ra   J/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/environment.py__init__   sD   


zEnvironment.__init__returnc                 C  s2   t | j| j| j| j| j| j| j| j| j	
df	S )N	statement)hashr=   r>   r:   r<   rN   rO   rU   r?   rS   getr`   ra   ra   rb   __hash__   s   
zEnvironment.__hash__ Callable[[str], Iterator[Token]]c                 C  s   t | j| j| j| j| j| jS )z(Return a tokenizer for this environment.)r    r:   r<   r=   r>   rN   rO   rh   ra   ra   rb   	tokenizer  s   zEnvironment.tokenizertag	Type[Tag]Nonec                 C  s   || | j |j< dS )zRegister a liquid tag with the environment.

        Built-in tags are registered for you automatically with every new `Environment`.

        Args:
            tag: The tag to register.
        N)rS   name)r`   rl   ra   ra   rb   add_tag  s   zEnvironment.add_tagro   funcCallable[..., Any]c                 C  s   || j |< dS )aP  Register a filter function with the environment.

        Args:
            name: The filter's name. Does not need to match the function name. This is
                what you'll use to apply the filter to an expression in a liquid
                template.
            func: Any callable that accepts at least one argument, the result of the
                expression the filter is applied to. If the filter needs access to the
                active environment or render context, use `liquid.filer.with_context`
                and/or `liquid.filter.with_environment` decorators.
        N)rT   )r`   ro   rq   ra   ra   rb   
add_filter  s   zEnvironment.add_filterc                 C  s   t |  dS )z1Add default tags and filters to this environment.N)r   registerrh   ra   ra   rb   r_   $  s   z"Environment.setup_tags_and_filterssourceast.ParseTreec                 C  s"   t | }|  |}|t|S )zParse `source` as a liquid template.

        More often than not you'll want to use `Environment.from_string` instead.
        )r"   rk   parser#   )r`   ru   parser
token_iterra   ra   rb   rw   (  s   zEnvironment.parserQ   pathOptional[Union[str, Path]]matterr$   c              
   C  sx   z|  |}W n& ttfy } z||_||_|d}~w ty- } ztd|d}~ww | j| |||| ||dS )a5  Parse the given string as a liquid template.

        Args:
            source: The liquid template source code.
            name: Optional name of the template. Available as `Template.name`.
            path: Optional path or identifier to the origin of the template.
            globals: An optional mapping of context variables made available every
                time the resulting template is rendered.
            matter: Optional mapping containing variables associated with the
                template. Could be "front matter" or other meta data.
        Nzunexpected liquid parsing error)envro   rz   
parse_treerK   r|   )	rw   r   r   filenameru   	Exceptionr   template_classmake_globals)r`   ru   ro   rz   rK   r|   r~   errra   ra   rb   from_string1  s&   
zEnvironment.from_stringc                 C  sr   | j dur!| j |}t|tr!| jr|jr!|j| | |S | j	j
| || |d}| j dur7|| j |< |S )a  Load and parse a template using the configured loader.

        Args:
            name: The template's name. The loader is responsible for interpreting
                the name. It could be the name of a file or some other identifier.
            globals: A mapping of context variables made available every time the
                resulting template is rendered.

        Raises:
            TemplateNotFound: if a template with the given name can not be found.
        NrK   )rW   rg   
isinstancer$   rH   is_up_to_daterK   updater   rB   loadr`   ro   rK   cachedtemplatera   ra   rb   get_templateU  s   



zEnvironment.get_templatec                   s   | j dur&| j |}t|tr&| jr| I dH r&|j| | |S | j	j
| || |dI dH }| j dur?|| j |< |S )z#An async version of `get_template`.Nr   )rW   rg   r   r$   rH   is_up_to_date_asyncrK   r   r   rB   
load_asyncr   ra   ra   rb   get_template_asyncr  s    



zEnvironment.get_template_asynckwargsobjectc                 K  s   | j j| ||fi |S )a  Load and parse a template with arbitrary loader arguments.

        This method bypasses the environment's template cache. You should use a caching
        loader instead when the loader requires extra keyword arguments.

        _New in version 1.9.0._
        )rB   load_with_argsr`   ro   rK   r   ra   ra   rb   get_template_with_args  s   z"Environment.get_template_with_argsc                   s    | j j| ||fi |I dH S )zWAn async version of `get_template_with_args`.

        _New in version 1.9.0._
        N)rB   load_with_args_asyncr   ra   ra   rb   get_template_with_args_async  s   
z(Environment.get_template_with_args_asynccontext	'Context'c                 K  s   | j j||fi |S )zLoad and parse a template with reference to a render context.

        This method bypasses the environment's template cache. You should consider using
        a caching loader.
        )rB   load_with_contextr`   r   ro   r   ra   ra   rb   get_template_with_context  s   z%Environment.get_template_with_contextc                   s   | j j||fi |I dH S )z0An async version of `get_template_with_context`.N)rB   load_with_context_asyncr   ra   ra   rb   get_template_with_context_async  s   z+Environment.get_template_with_context_async<string>)
inner_tagsr   Optional[InnerTagMap]r   c                C  s   t | |t|  ||dS )ak  Analyze tags in template source text.

        Unlike template static or contextual analysis, a tag audit does not parse the
        template source text into an AST, nor does it attempt to load partial templates
        from `{% include %}` or `{% render %}` tags.

        Args:
            source: The source text of the template.
            name: A name or identifier for the template.
            inner_tags: A mapping of block tags to a list of allowed "inner" tags for
                the block. For example, `{% if %}` blocks are allowed to contain
                `{% elsif %}` and `{% else %}` tags.
        )r}   ro   tokensr   )r   listrk   )r`   ru   ro   r   ra   ra   rb   analyze_tags_from_string  s   z$Environment.analyze_tags_from_string)r   r   Optional['Context']c                K  sB   |r| j jd||d|}n| j j| |d}| j|j|j|dS )a  Audit template tags without parsing source text into an abstract syntax tree.

        This is useful for identifying unknown, misplaced and unbalanced tags in a
        template's source text. See also `liquid.template.BoundTemplate.analyze`.

        Args:
            name: The template's name or identifier, as you would use with
                `Environment.get_template`. Use `Environment.analyze_tags_from_string`
                to audit tags in template text without using a template loader.
            context: An optional render context the loader might use to modify the
                template search space. If given, uses
                `liquid.loaders.BaseLoader.get_source_with_context` from the current
                loader.
            inner_tags: A mapping of block tags to a list of allowed "inner" tags for
                the block. For example, `{% if %}` blocks are allowed to contain
                `{% elsif %}` and `{% else %}` tags.
            kwargs: Loader context.
        r   template_name)r   ro   r   Nra   )rB   get_source_with_context
get_sourcer   ru   r   r`   ro   r   r   r   template_sourcera   ra   rb   analyze_tags  s   zEnvironment.analyze_tagsc                  sP   |r| j jd||d|I dH }n| j j| |dI dH }| j|j|j|dS )z/An async version of `Environment.analyze_tags`.r   N)r}   r   r   ra   )rB   get_source_with_context_asyncget_source_asyncr   ru   r   r   ra   ra   rb   analyze_tags_async  s   	zEnvironment.analyze_tags_asyncDict[str, object]c                 C  s   |r	i | j |S t| j S )z2Combine environment globals with template globals.)rK   dict)r`   rK   ra   ra   rb   r     s   
zEnvironment.make_globalsexcUnion[Type[Error], Error]msgOptional[str]linenumOptional[int]c                 C  sb   t |ts|||d}n|js||_| jtjkr|| jtjkr/tjt	|t
|jdd dS dS )zHRaise, warn or ignore the given exception according to the current mode.)r      )category
stacklevelN)r   r   r   rU   r!   STRICTWARNwarningswarnr;   r   	__class__)r`   r   r   r   ra   ra   rb   error  s   

zEnvironment.errormaxsizec                 C  s.   || _ | | j \| _| _| _| _| _| _dS )zCreate or replace cached versions of the common expression parsers.

        If `maxsize` is less than `1`, no expression caching will happen.

        Args:
            maxsize: The maximum size of each expression cache.
        N)rP   rX   rY   rZ   r[   r\   r]   r^   )r`   r   ra   ra   rb   set_expression_cache_size.  s   
z%Environment.set_expression_cache_sizeTuple[Callable[[str], 'BooleanExpression'], Callable[[str], 'BooleanExpression'], Callable[[str], 'FilteredExpression'], Callable[[str], 'FilteredExpression'], Callable[[str], 'FilteredExpression'], Callable[[str], 'LoopExpression']]c                 C  sd   |dkr*t |dtt |dtt |dtt |dtt |dtt |dtfS ttttttfS )N   r   )r   r   r   r   r   r   r   )r`   rI   ra   ra   rb   rX   @  s   
	z#Environment._get_expression_parsers)"r:   r;   r<   r;   r=   r;   r>   r;   r?   r@   rA   r!   rB   rC   rD   rE   rF   r@   rG   r@   rH   r@   rI   rJ   rK   rL   rM   r@   rN   r;   rO   r;   rP   rJ   )rd   rJ   )rd   rj   )rl   rm   rd   rn   )ro   r;   rq   rr   rd   rn   )rd   rn   )ru   r;   rd   rv   )rQ   NNN)ru   r;   ro   r;   rz   r{   rK   rL   r|   rL   rd   r$   )N)ro   r;   rK   rL   rd   r$   )ro   r;   rK   rL   r   r   rd   r$   )r   r   ro   r;   r   r;   rd   r$   )r   )ru   r;   ro   r;   r   r   rd   r   )
ro   r;   r   r   r   r   r   r;   rd   r   )rK   rL   rd   r   )NN)r   r   r   r   r   r   rd   rn   )r   )r   rJ   rd   rn   )rI   rJ   rd   r   )#__name__
__module____qualname____doc__r/   __annotations__r0   r1   r2   r$   r   r!   r   r   rc   ri   rk   rp   rs   r_   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   rX   ra   ra   ra   rb   r-   5   s   
 R
U





' 

+r-   
   r   r:   r;   r<   r=   r>   r?   r@   rA   r!   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rd   c                 C  sp   t di d| d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|S )z=Return an `Environment` initialized with the given arguments.r:   r<   r=   r>   r?   rA   rB   rD   rF   rG   rH   rI   rK   rM   rN   rO   rP   Nra   )r-   )r:   r<   r=   r>   r?   rA   rB   rD   rF   rG   rH   rI   rK   rM   rN   rO   rP   ra   ra   rb   get_implicit_environment]  sF   	
r   r3   r4   r5   r6   FTr7   r8   r9   ru   r$   c                 C  s~   t di d|d|d|d|d|d|ddd	|d
|d|	d|
d|ddd|d|d|d|}|j| |dS )a
  Parse a template, automatically creating an `Environment` to bind it to.

    Other than `source`, all arguments are passed to the implicit `Environment`,
    which might have been cached from previous calls to `Template`.

    Args:
        source: A Liquid template source string.
        tag_start_string: The sequence of characters indicating the start of a liquid
            tag.
        tag_end_string: The sequence of characters indicating the end of a liquid tag.

        statement_start_string: The sequence of characters indicating the start of an
            output statement.
        statement_end_string: The sequence of characters indicating the end of an output
            statement.
        template_comments: If `True`, enable template comments. Where, by default,
            anything between `{#` and `#}` is considered a comment.
        comment_start_string: The sequence of characters indicating the start of a
            comment.
            `comment_start_string` to have any effect.
        comment_end_string: The sequence of characters indicating the end of a comment.
            `template_comments` must be `True` for
            `comment_end_string` to have any effect.
        tolerance: Indicates how tolerant to be of errors. Must be one of
            `Mode.LAX`, `Mode.WARN` or `Mode.STRICT`.
        undefined: A subclass of `Undefined` that represents undefined values. Could be
            one of the built-in undefined types, `Undefined`, `DebugUndefined` or
            `StrictUndefined`.
            ignores undefined values.
        strict_filters: If `True`, will raise an exception upon finding an undefined
            filter. Otherwise undefined filters are silently ignored.
            `True`.
        autoescape: If `True`, all context values will be HTML-escaped before output
            unless they've been explicitly marked as "safe". Requires the package
            Markupsafe.
        auto_reload: If `True`, loaders that have an `uptodate` callable will reload
            template source data automatically. For deployments where template sources
            don't change between service reloads, setting auto_reload to `False` can
            yield an increase in performance by avoiding calls to `uptodate`. Defaults
            to `True`.
        cache_size: The capacity of the template cache in number of templates. Defaults
            to 300. If `cache_size` is `None` or less than `1`, it has the effect of
            setting `auto_reload` to `False`.
        expression_cache_size: The capacity of each of the common expression caches.
            `, disabling expression caching.
        globals: An optional mapping that will be added to the context of any template
            loaded from this environment.
    r:   r<   r=   r>   r?   rA   rB   NrD   rF   rG   rH   rI   rK   rM   rN   rO   rP   r   ra   )r   r   )ru   r:   r<   r=   r>   r?   rA   rD   rF   rG   rH   rI   rK   rM   rN   rO   rP   r}   ra   ra   rb   Template  sH   E	
r   )$r:   r;   r<   r;   r=   r;   r>   r;   r?   r@   rA   r!   rB   rC   rD   rE   rF   r@   rG   r@   rH   r@   rI   rJ   rK   rL   rM   r@   rN   r;   rO   r;   rP   rJ   rd   r-   )$ru   r;   r:   r;   r<   r;   r=   r;   r>   r;   r?   r@   rA   r!   rD   rE   rF   r@   rG   r@   rH   r@   rI   rJ   rK   rL   rM   r@   rN   r;   rO   r;   rP   rJ   rd   r$   )Cr   
__future__r   r   	functoolsr   typingr   r   r   r   r   r	   r
   r   r   r   r   r   liquidr   r   r   liquid.analyze_tagsr   r   liquid.contextr   liquid.exceptionsr   r   r   r   liquid.expressionsr   r   r   r   r   r   
liquid.lexr    liquid.moder!   liquid.parser"   liquid.streamr#   liquid.templater$   liquid.utilsr%   pathlibr&   r'   liquid.expressionr(   r)   r*   
liquid.tagr+   liquid.tokenr,   r-   r   r   r   ra   ra   ra   rb   <module>   s        ,0