o
    {,h]                     @   sr   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
mZ ddlmZ dd	lmZ G d
d dZdS )    N)ImproperlyConfigured)cached_propertyimport_string   Template)Context_builtin_context_processors)TemplateDoesNotExistimport_libraryc                   @   s   e Zd Zg dZ										d#ddZd	d
 Zeejdd Z	e
dd Zdd Zdd Ze
dd Zdd Zdd Zd$ddZdd Zdd Zd%dd Zd!d" ZdS )&Engine)zdjango.template.defaulttagszdjango.template.defaultfilterszdjango.template.loader_tagsNF utf-8Tc                 C   s   |d u rg }|d u rg }|d u r dg}|r|dg7 }d|fg}n|r&t d|d u r,i }|	d u r2g }	|| _|| _|
| _|| _|| _|| _|| _|| _|| _	| 
|| _| j|	 | _| | j| _d S )Nz)django.template.loaders.filesystem.Loaderz.django.template.loaders.app_directories.Loaderz%django.template.loaders.cached.Loaderz1app_dirs must not be set when loaders is defined.)r   dirsapp_dirs
autoescapecontext_processorsdebugloadersstring_if_invalidfile_charset	librariesget_template_librariestemplate_librariesdefault_builtinsbuiltinsget_template_builtinstemplate_builtins)selfr   r   r   r   r   r   r   r   r   r    r!   L/var/www/html/rh/venv/lib/python3.10/site-packages/django/template/engine.py__init__   s:   
zEngine.__init__c                 C   s   d| j j| js	dndt| j | j| jsdndt| j | jt| jt| jt| j	| j
s/dndt| j
 | js:dndt| j t| jf S )Nz`<%s:%s app_dirs=%s%s debug=%s loaders=%s string_if_invalid=%s file_charset=%s%s%s autoescape=%s>r   z dirs=%sz context_processors=%sz libraries=%sz builtins=%s)	__class____qualname__r   reprr   r   r   r   r   r   r   r   r   r    r!   r!   r"   __repr__A   s    zEngine.__repr__c                  C   sB   ddl m}  ddlm} |  D ]}t||r|j  S qtd)a  
        Return the first DjangoTemplates backend that's configured, or raise
        ImproperlyConfigured if none are configured.

        This is required for preserving historical APIs that rely on a
        globally available, implicitly configured engine such as:

        >>> from django.template import Context, Template
        >>> template = Template("Hello {{ name }}!")
        >>> context = Context({'name': "world"})
        >>> template.render(context)
        'Hello world!'
        r   )engines)DjangoTemplatesz)No DjangoTemplates backend is configured.)django.templater)   django.template.backends.djangor*   all
isinstanceenginer   )r)   r*   r/   r!   r!   r"   get_defaultW   s   

zEngine.get_defaultc                 C   s$   t }|t| j7 }tdd |D S )Nc                 s   s    | ]}t |V  qd S Nr   ).0pathr!   r!   r"   	<genexpr>v   s    z5Engine.template_context_processors.<locals>.<genexpr>)r
   tupler   )r    r   r!   r!   r"   template_context_processorsr   s   z"Engine.template_context_processorsc                 C   s   dd |D S )Nc                 S   s   g | ]}t |qS r!   r   )r2   xr!   r!   r"   
<listcomp>y   s    z0Engine.get_template_builtins.<locals>.<listcomp>r!   )r    r   r!   r!   r"   r   x   s   zEngine.get_template_builtinsc                 C   s&   i }|  D ]
\}}t|||< q|S r1   )itemsr   )r    r   loadednamer3   r!   r!   r"   r   {   s   zEngine.get_template_librariesc                 C   s   |  | jS r1   )get_template_loadersr   r'   r!   r!   r"   template_loaders   s   zEngine.template_loadersc                 C   s.   g }|D ]}|  |}|d ur|| q|S r1   )find_template_loaderappend)r    r=   r   template_loaderloaderr!   r!   r"   r<      s   

zEngine.get_template_loadersc                 C   sJ   t |ttfr|^}}ng }t |trt|}|| g|R  S td| )Nz3Invalid value in template loaders configuration: %r)r.   r5   liststrr   r   )r    rA   argsloader_classr!   r!   r"   r>      s   

zEngine.find_template_loaderc                 C   sj   g }| j D ])}z|j||d}||jfW   S  ty. } z||j W Y d }~qd }~ww t||d)N)skip)tried)r=   get_templateoriginr   extendrG   )r    r;   r   rF   rG   rA   templateer!   r!   r"   find_template   s   
zEngine.find_templatec                 C   s   t || dS )z
        Return a compiled Template object for the given template code,
        handling template inheritance recursively.
        r/   r   )r    template_coder!   r!   r"   from_string   s   zEngine.from_stringc                 C   s,   |  |\}}t|dst|||| d}|S )z
        Return a compiled Template object for the given template name,
        handling template inheritance recursively.
        renderrN   )rM   hasattrr   )r    template_namerK   rI   r!   r!   r"   rH      s   
zEngine.get_templatec                 C   sL   t |ttfr| |}n| |}t |tr||S |t|| jdS )z
        Render the template specified by template_name with the given context.
        For use in Django's test suite.
        )r   )r.   rB   r5   select_templaterH   r	   rQ   r   )r    rS   contexttr!   r!   r"   render_to_string   s   


zEngine.render_to_stringc                 C   sz   |st dg }|D ]+}z| |W   S  t y5 } z|jd |vr+||jd  W Y d}~q
d}~ww t d|)zV
        Given a list of template names, return the first that can be loaded.
        zNo template names providedr   Nz, )r   rH   rD   r?   join)r    template_name_list	not_foundrS   excr!   r!   r"   rT      s   zEngine.select_template)
NFNFNr   r   NNT)NNr1   )__name__
__module__r%   r   r#   r(   staticmethod	functools	lru_cacher0   r   r6   r   r   r=   r<   r>   rM   rP   rH   rW   rT   r!   r!   r!   r"   r      s<    
-




r   )r_   django.core.exceptionsr   django.utils.functionalr   django.utils.module_loadingr   baser   rU   r	   r
   
exceptionsr   libraryr   r   r!   r!   r!   r"   <module>   s    