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 erdd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 G dd deZdS )z<A file system loader that caches parsed templates in memory.    )annotations)partial)TYPE_CHECKING)	Awaitable)Callable)Iterable)Mapping)Union)LRUCache   )FileExtensionLoader)Path)BoundTemplate)Context)Environment)TemplateNamespace)TemplateSourcec                      s   e Zd ZdZdZ		d@dddddA fddZ	dBdC fddZ	dBdC fddZ	dBdD fd"d#Z	dBdD fd$d%Z	dE fd(d)Z
dE fd*d+ZdFd/d0ZdGd2d3ZdHd6d7ZdId8d9ZdJd<d=ZdJd>d?Z  ZS )KCachingFileSystemLoadera  A file system loader that caches parsed templates in memory.

    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.
        auto_reload: If `True`, automatically reload a cached template if it has been
            updated.
        namespace_key: The name of a global render context variable or loader keyword
            argument that resolves to the current loader "namespace" or "scope".

            If you're developing a multi-user application, a good namespace might be
            `uid`, where `uid` is a unique identifier for a user and templates are
            arranged in folders named for each `uid` inside the search path.
        cache_size: The maximum number of templates to hold in the cache before removing
            the least recently used template.
    Tutf-8.liquid i,  )auto_reloadnamespace_key
cache_sizesearch_path,Union[str, Path, Iterable[Union[str, Path]]]encodingstrextr   boolr   r   intc                  s.   t  j|||d || _t|d| _|| _d S )N)r   r   r   )capacity)super__init__r   r
   cacher   )selfr   r   r   r   r   r   	__class__ i/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/builtin/loaders/caching_file_system_loader.pyr#   2   s   

z CachingFileSystemLoader.__init__Nenvr   nameglobalsr   returnr   c              
     s   |  |||tt j|||S N)check_cacher   r"   loadr%   r*   r+   r,   r&   r(   r)   r0   E   s   zCachingFileSystemLoader.loadc              
     s&   |  |||tt j|||I d H S r.   )check_cache_asyncr   r"   
load_asyncr1   r&   r(   r)   r3   R   s   
z"CachingFileSystemLoader.load_asynckwargsobjectc              
     s2   |  ||}| |||tt j|||fi |S r.   )	cache_keyr/   r   r"   load_with_argsr%   r*   r+   r,   r4   r6   r&   r(   r)   r7   _   s   z&CachingFileSystemLoader.load_with_argsc              
     s:   |  ||}| |||tt j|||fi |I d H S r.   )r6   r2   r   r"   load_with_args_asyncr8   r&   r(   r)   r9   n   s   
z,CachingFileSystemLoader.load_with_args_asynccontextr   c              
     s>   | j ||fi |}| |j||jtt jf||d|S )N)r:   r+   )cache_key_with_contextr/   r*   r,   r   r"   load_with_contextr%   r:   r+   r4   r6   r&   r(   r)   r<   }   s   z)CachingFileSystemLoader.load_with_contextc              	     sD   | j ||fi |}| |j||jtt j||fi |I d H S r.   )r;   r2   r*   r,   r   r"   load_with_context_asyncr=   r&   r(   r)   r>      s   
z/CachingFileSystemLoader.load_with_context_asyncr6   	load_funcCallable[[], BoundTemplate]c                 C  sj   z| j | }W n ty   | }|| j |< | Y S w | jr+|js+| }|| j |< |S |r3|j| |S r.   )r$   KeyErrorr   is_up_to_dater,   updater%   r*   r6   r,   r?   cached_templatetemplater(   r(   r)   r/      s   

z#CachingFileSystemLoader.check_cache&Callable[[], Awaitable[BoundTemplate]]c                   s   z| j | }W n ty   | I d H }|| j |< | Y S w | jr6| I d H s6| I d H }|| j |< |S |r>|j| |S r.   )r$   rA   r   is_up_to_date_asyncr,   rC   rD   r(   r(   r)   r2      s   

z)CachingFileSystemLoader.check_cache_asyncargsMapping[str, object]c                 C  s8   | j s|S z|| j   d| W S  ty   | Y S w N/)r   rA   )r%   r+   rI   r(   r(   r)   r6      s   z!CachingFileSystemLoader.cache_keyc                 K  s:   | j s|S z|j| j   d| W S  ty   | Y S w rK   )r   r,   rA   )r%   r+   r:   r4   r(   r(   r)   r;      s   z.CachingFileSystemLoader.cache_key_with_contexttemplate_namer   c                 K  s"   | j ||fi |}| |j|S r.   )r;   
get_sourcer*   r%   r:   rM   r4   r+   r(   r(   r)   get_source_with_context   s   z/CachingFileSystemLoader.get_source_with_contextc                   s*   | j ||fi |}| |j|I d H S r.   )r;   get_source_asyncr*   rO   r(   r(   r)   get_source_with_context_async   s   z5CachingFileSystemLoader.get_source_with_context_async)r   r   )r   r   r   r   r   r   r   r   r   r   r   r    r.   )r*   r   r+   r   r,   r   r-   r   )
r*   r   r+   r   r,   r   r4   r5   r-   r   )r:   r   r+   r   r4   r   r-   r   )
r*   r   r6   r   r,   r   r?   r@   r-   r   )
r*   r   r6   r   r,   r   r?   rG   r-   r   )r+   r   rI   rJ   r-   r   )r+   r   r:   r   r4   r   r-   r   )r:   r   rM   r   r4   r   r-   r   )__name__
__module____qualname____doc__caching_loaderr#   r0   r3   r7   r9   r<   r>   r/   r2   r6   r;   rP   rR   __classcell__r(   r(   r&   r)   r      s4    



	
r   N)rV   
__future__r   	functoolsr   typingr   r   r   r   r   r	   liquid.utilsr
   file_system_loaderr   pathlibr   liquidr   r   r   base_loaderr   r   r   r(   r(   r(   r)   <module>   s&    