o
    ‚.Údç$  ã                   @  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 er^ddlmZ ddlmZ ddlmZ eeeef  Zee
g ef e
g e	e f df ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )zBase template loader.é    )Úannotations)ÚABC)ÚPath)ÚTYPE_CHECKING)Ú	Awaitable)ÚCallable)ÚDict)ÚMapping)Ú
NamedTuple)ÚOptional)ÚUnion)ÚTemplateNotFound)ÚContext)ÚEnvironment)ÚBoundTemplateNc                   @  s6   e Zd ZU dZded< ded< ded< dZded	< dS )
ÚTemplateSourcea  A Liquid template source as returned by the `get_source` method of a `loader`.

    Attributes:
        source: The liquid template source code.
        filename: The liquid template file name or other string identifying its origin.
        uptodate: Optional callable that will return `True` if the template is up to
            date, or `False` if it needs to be reloaded.
        matter: Optional mapping containing variables associated with the template.
            Could be "front matter" or other meta data.
    ÚstrÚsourceÚfilenameÚUpToDateÚuptodateNÚTemplateNamespaceÚmatter)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   © r   r   úZ/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/builtin/loaders/base_loader.pyr      s   
 r   c                   @  sœ   e Zd 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d„Z	d-d.d d!„Z	d-d/d"d#„Z	d-d/d$d%„Zd0d&d'„Zd0d(d)„ZdS )1Ú
BaseLoadera3  Base template loader from which all template loaders are derived.

    Attributes:
        caching_loader (bool): Indicates if this loader implements its own cache.
            Setting this sto `True` will cause the `Environment` to disable its cache
            when initialized with a caching loader.
    FÚenvr   Útemplate_namer   Úreturnr   c                 C  s   t dƒ‚)zùGet the template source, filename and reload helper for a template.

        Args:
            env: The `Environment` attempting to load the template source text.
            template_name: A name or identifier for a template's source text.
        z3template loaders must implement a get_source method)ÚNotImplementedError©Úselfr!   r"   r   r   r   Ú
get_source9   s   zBaseLoader.get_sourcec                 Ã  s   |   ||¡S )zkAn async version of `get_source`.

        The default implementation delegates to `get_source()`.
        ©r'   r%   r   r   r   Úget_source_asyncF   s   €	zBaseLoader.get_source_asyncÚkwargsÚobjectc                 K  s   |   ||¡S )at  Get template source text, optionally referencing arbitrary keyword arguments.

        Keyword arguments can be useful for multi-user environments where you need to
        modify a template loader's search space for a given user.

        By default, this method delegates to `get_source`, ignoring any keyword
        arguments.

        _New in version 1.9.0._
        r(   ©r&   r!   r"   r*   r   r   r   Úget_source_with_argsQ   s   zBaseLoader.get_source_with_argsc                 Ë  s   | j ||fi |¤ŽS )zUAn async version of `get_source_with_args`.

        _New in version 1.9.0._
        )r-   r,   r   r   r   Úget_source_with_args_asyncc   ó   €z%BaseLoader.get_source_with_args_asyncÚcontextr   c                 K  s   |   |j|¡S )zAGet a template's source, optionally referencing a render context.)r'   r!   ©r&   r0   r"   r*   r   r   r   Úget_source_with_contextl   s   z"BaseLoader.get_source_with_contextc                 Ë  s   |   |j|¡I dH S )z.An async version of `get_source_with_context`.N)r)   r!   r1   r   r   r   Úget_source_with_context_asyncu   r/   z(BaseLoader.get_source_with_context_asyncNÚnameÚglobalsr   r   c           
   
   C  s^   z|   ||¡\}}}}W n ty } zt|ƒ|‚d}~ww |j|||t|ƒ|d}	||	_|	S )zêLoad and parse a template.

        Used internally by `Environment` to load a template source. Delegates to
        `get_source`. A custom loaders would typically implement `get_source` rather
        than overriding `load`.
        N©r5   r4   Úpathr   )r'   Ú	Exceptionr   Úfrom_stringr   r   )
r&   r!   r4   r5   r   r   r   r   ÚerrÚtemplater   r   r   Úload~   s   
€ÿûzBaseLoader.loadc              
   Ã  sj   z|   ||¡I dH }|\}}}}W n ty# }	 zt|ƒ|	‚d}	~	ww |j|||t|ƒ|d}
||
_|
S )zAn async version of `load`.Nr6   )r)   r8   r   r9   r   r   )r&   r!   r4   r5   Útemplate_sourcer   r   r   r   r:   r;   r   r   r   Ú
load_async™   s"   €
€ÿûzBaseLoader.load_asyncc              
   K  sf   z| j ||fi |¤Ž\}}}}W n ty! }	 zt|ƒ|	‚d}	~	ww |j|||t|ƒ|d}
||
_|
S )a…  Load template source text, optionally referencing extra keyword arguments.

        Most custom loaders will want to override `get_source_with_args()` rather than
        this method. For example, you might want to override `load_with_args()` and
        `get_source_with_args()` when implementing a custom caching loader. Where cache
        handling happens in `load_*` methods.
        Nr6   )r-   r8   r   r9   r   r   )r&   r!   r4   r5   r*   r   r   r   r   r:   r;   r   r   r   Úload_with_args°   s&   ÿÿ
€ÿûzBaseLoader.load_with_argsc              
   Ë  sr   z| j ||fi |¤ŽI dH }|\}}}}	W n ty' }
 zt|ƒ|
‚d}
~
ww |j|||t|ƒ|	d}||_|S )z'An async version of `load_with_args()`.Nr6   )r.   r8   r   r9   r   r   )r&   r!   r4   r5   r*   r=   r   r   r   r   r:   r;   r   r   r   Úload_with_args_asyncÏ   s"   €
€ÿûzBaseLoader.load_with_args_asyncc           
   
   K  sj   z| j ||fi |¤Ž\}}}}W n ty! } zt|ƒ|‚d}~ww |jj||j|t|ƒ|d}	||	_|	S )zCLoad and parse a template, optionally referencing a render context.Nr6   )r2   r8   r   r!   r9   r5   r   r   ©
r&   r0   r4   r*   r   r   r   r   r:   r;   r   r   r   Úload_with_contextç   s&   ÿÿ
€ÿûzBaseLoader.load_with_contextc           
   
   Ë  sr   z| j ||fi |¤ŽI dH \}}}}W n ty% } zt|ƒ|‚d}~ww |jj||j|t|ƒ|d}	||	_|	S )z(An async version of `load_with_context`.Nr6   )r3   r8   r   r!   r9   r5   r   r   rA   r   r   r   Úload_with_context_asyncÿ   s*   €û
€ÿûz"BaseLoader.load_with_context_async)r!   r   r"   r   r#   r   )r!   r   r"   r   r*   r+   r#   r   )r0   r   r"   r   r*   r   r#   r   ©N)r!   r   r4   r   r5   r   r#   r   )
r!   r   r4   r   r5   r   r*   r+   r#   r   )r0   r   r4   r   r*   r   r#   r   )r   r   r   r   Úcaching_loaderr'   r)   r-   r.   r2   r3   r<   r>   r?   r@   rB   rC   r   r   r   r   r    .   s&    




	
	üüü#ü
r    c                      s,   e Zd ZdZd‡ fdd„Zddd„Z‡  ZS )Ú
DictLoaderz“A loader that loads templates from a dictionary.

    Args:
        templates: A dictionary mapping template names to template source strings.
    Ú	templatesúDict[str, str]c                   s   t ƒ  ¡  || _d S rD   )ÚsuperÚ__init__rG   )r&   rG   ©Ú	__class__r   r   rJ   "  s   

zDictLoader.__init__Ú_r   r"   r   r#   r   c              
   C  s>   z| j | }W n ty } zt|ƒ|‚d }~ww t||d ƒS rD   )rG   ÚKeyErrorr   r   )r&   rM   r"   r   r:   r   r   r   r'   &  s   
€ÿzDictLoader.get_source)rG   rH   )rM   r   r"   r   r#   r   )r   r   r   r   rJ   r'   Ú__classcell__r   r   rK   r   rF     s    rF   )r   Ú
__future__r   Úabcr   Úpathlibr   Útypingr   r   r   r   r	   r
   r   r   Úliquid.exceptionsr   Úliquidr   r   Úliquid.templater   r   r+   r   Úboolr   r   r    rF   r   r   r   r   Ú<module>   s.    " n