o
    .d,                     @  s   d Z ddlmZ ddl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 e
rNddlmZ G dd deZG dd deZdS )zBuilt-in file system loader.    )annotationsN)partialPath)TYPE_CHECKING)Iterable)Tuple)Union)TemplateNotFound   )
BaseLoader)TemplateSource)Environmentc                      sj   e Zd ZdZ	d d! fddZd"ddZd#ddZd$ddZed%ddZ	ed%ddZ
d$ddZ  ZS )&FileSystemLoaderzA loader that loads templates from one or more directories on the file system.

    Args:
        search_path: One or more paths to search.
        encoding: Open template files with the given encoding.
    utf-8search_path,Union[str, Path, Iterable[Union[str, Path]]]encodingstrc                   s>   t    t|trt|tr|g}dd |D | _|| _d S )Nc                 S  s   g | ]}t |qS  r   ).0pathr   r   a/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/builtin/loaders/file_system_loader.py
<listcomp>'   s    z-FileSystemLoader.__init__.<locals>.<listcomp>)super__init__
isinstancer   r   r   r   )selfr   r   	__class__r   r   r      s
   

zFileSystemLoader.__init__template_namereturnr   c                 C  sL   t |}tjj|jv rt|| jD ]}||}| sq|  S t|)a  Return a path to the template `template_name`.

        If the search path is a list of paths, returns the first path where
        `template_name` exists. If none of the search paths contain `template_name`, a
        `TemplateNotFound` exception is raised.
        )	r   osr   pardirpartsr
   r   joinpathexistsr   r    template_pathr   source_pathr   r   r   resolve_path*   s   

zFileSystemLoader.resolve_pathr)   Tuple[str, float]c                 C  sD   |j | jd}| }W d    n1 sw   Y  || jfS )N)r   )openr   readstatst_mtime)r   r)   fdsourcer   r   r   _read=   s   
zFileSystemLoader._read_r   r   c                 C  s2   |  |}| |\}}t|t|t| j||S N)r*   r2   r   r   r   	_uptodate)r   r3   r    r)   r1   mtimer   r   r   
get_sourceB   s   
zFileSystemLoader.get_sourcer6   floatboolc                 C  s   ||   jkS r4   r.   r/   r)   r6   r   r   r   r5   M   s   zFileSystemLoader._uptodatec                   s"   t  d  fddI d H S )Nc                     s      jkS r4   r:   r   r6   r)   r   r   <lambda>T   s    z2FileSystemLoader._uptodate_async.<locals>.<lambda>)asyncioget_running_looprun_in_executorr;   r   r<   r   _uptodate_asyncQ   s   
z FileSystemLoader._uptodate_asyncc                   sT   t  }|d | j|I d H }|d | j|I d H \}}t|t|t| j||S r4   )	r>   r?   r@   r*   r2   r   r   r   rA   )r   r3   r    loopr)   r1   r6   r   r   r   get_source_asyncW   s   z!FileSystemLoader.get_source_async)r   )r   r   r   r   r    r   r!   r   )r)   r   r!   r+   )r3   r   r    r   r!   r   )r)   r   r6   r8   r!   r9   )__name__
__module____qualname____doc__r   r*   r2   r7   staticmethodr5   rA   rC   __classcell__r   r   r   r   r      s    



r   c                      s2   e Zd ZdZ		dd fd	d
ZdddZ  ZS )FileExtensionLoadera  A file system loader that adds a file name extension if one is missing.

    Args:
        search_path: One or more paths to search.
        encoding: Open template files with the given encoding.
        ext: A default file extension. Should include a leading period.
    r   .liquidr   r   r   r   extc                   s   t  j||d || _d S )N)r   r   )r   r   rM   )r   r   r   rM   r   r   r   r   k   s   
zFileExtensionLoader.__init__r    r!   r   c                 C  s^   t |}|js|| j}tjj|jv rt|| j	D ]}|
|}| s'q|  S t|r4   )r   suffixwith_suffixrM   r"   r   r#   r$   r
   r   r%   r&   r'   r   r   r   r*   t   s   

z FileExtensionLoader.resolve_path)r   rL   )r   r   r   r   rM   r   rD   )rE   rF   rG   rH   r   r*   rJ   r   r   r   r   rK   b   s    	rK   )rH   
__future__r   r>   r"   	functoolsr   pathlibr   typingr   r   r   r	   liquid.exceptionsr
   base_loaderr   r   liquidr   r   rK   r   r   r   r   <module>   s"    L