U
    a                     @   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m	Z	 ddl
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   )ContextTemplate)_builtin_context_processors)TemplateDoesNotExistimport_libraryc                
   @   s   e Zd ZdddgZd#d	d
Zee 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 )&Enginezdjango.template.defaulttagszdjango.template.defaultfilterszdjango.template.loader_tagsNF utf-8Tc                 C   s   |d krg }|d krg }|d krDdg}|r4|dg7 }|sPd|fg}n|rPt d|d kr\i }|	d krhg }	|| _|| _|
| _|| _|| _|| _|| _|| _|| _	| 
|| _| 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_librariesZtemplate_librariesdefault_builtinsbuiltinsget_template_builtinsZtemplate_builtins)selfr   r   r   r   r   r   r   r   r   r    r   /home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/site-packages/django/template/engine.py__init__   s<    
zEngine.__init__c                  C   sF   ddl m}  ddlm} |  D ]}t||r |j  S q tddS )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.N)Zdjango.templater!   Zdjango.template.backends.djangor"   all
isinstanceenginer   )r!   r"   r%   r   r   r   get_default7   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>U   s     z5Engine.template_context_processors.<locals>.<genexpr>)r	   tupler   )r   r   r   r   r   template_context_processorsQ   s    z"Engine.template_context_processorsc                 C   s   dd |D S )Nc                 S   s   g | ]}t |qS r   r   )r(   xr   r   r   
<listcomp>X   s     z0Engine.get_template_builtins.<locals>.<listcomp>r   )r   r   r   r   r   r   W   s    zEngine.get_template_builtinsc                 C   s&   i }|  D ]\}}t|||< q|S r'   )itemsr   )r   r   Zloadednamer)   r   r   r   r   Z   s    zEngine.get_template_librariesc                 C   s   |  | jS r'   )get_template_loadersr   )r   r   r   r   template_loaders`   s    zEngine.template_loadersc                 C   s.   g }|D ] }|  |}|d k	r|| q|S r'   )find_template_loaderappend)r   r2   r   Ztemplate_loaderloaderr   r   r   r1   d   s    
zEngine.get_template_loadersc                 C   sL   t |ttfr|^}}ng }t |tr<t|}|| f| S td| d S )Nz3Invalid value in template loaders configuration: %r)r$   r+   liststrr   r   )r   r5   argsloader_classr   r   r   r3   l   s    

zEngine.find_template_loaderc                 C   sn   g }| j D ]R}z|j||d}||jfW   S  tk
rZ } z||j W 5 d }~X Y q
X q
t||dd S )N)skip)tried)r2   get_templateoriginr
   extendr;   )r   r0   r   r:   r;   r5   templateer   r   r   find_templatey   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   Z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.
        renderrB   )rA   hasattrr   )r   template_namer?   r=   r   r   r   r<      s    
zEngine.get_templatec                 C   sP   t |ttfr| |}n
| |}t |tr8||S |t|| jdS dS )z
        Render the template specified by template_name with the given context.
        For use in Django's test suite.
        )r   N)r$   r6   r+   select_templater<   r   rD   r   )r   rF   contexttr   r   r   render_to_string   s    


zEngine.render_to_stringc                 C   s   |st dg }|D ]^}z| |W   S  t k
rp } z*|jd |krX||jd  W Y qW 5 d}~X Y qX qt d|dS )zV
        Given a list of template names, return the first that can be loaded.
        zNo template names providedr   Nz, )r
   r<   r8   r4   join)r   Ztemplate_name_list	not_foundrF   excr   r   r   rG      s    zEngine.select_template)
NFNFNr   r   NNT)NN)N)__name__
__module____qualname__r   r    staticmethod	functools	lru_cacher&   r   r,   r   r   r2   r1   r3   rA   rC   r<   rJ   rG   r   r   r   r   r      s:                
#




r   )rR   Zdjango.core.exceptionsr   Zdjango.utils.functionalr   Zdjango.utils.module_loadingr   baser   r   rH   r	   
exceptionsr
   Zlibraryr   r   r   r   r   r   <module>   s   