U
    7h*                     @   s   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 G d	d
 d
e
ZG dd dZe jdd ZdS )    N)Counter)Path)apps)settings)ImproperlyConfigured)cached_property)import_stringc                   @   s   e Zd ZdS )InvalidTemplateEngineErrorN)__name__
__module____qualname__ r   r   O/var/www/formularioweb/env/lib/python3.8/site-packages/django/template/utils.pyr	      s   r	   c                   @   s:   e Zd ZdddZedd Zdd Zdd	 Zd
d ZdS )EngineHandlerNc                 C   s   || _ i | _dS )z|
        templates is an optional list of template engine definitions
        (structured like settings.TEMPLATES).
        N)
_templates_engines)self	templatesr   r   r   __init__   s    zEngineHandler.__init__c              	   C   s   | j d krtj| _ i }g }| j D ]x}z|d ddd }W n. tk
rj   |dd}td|Y nX |g di d|}|||d	 < ||d	  q t	|}d
d |
 D }|rtdd||S )NBACKEND.   z<not defined>zHInvalid BACKEND for a template engine: {}. Check your TEMPLATES setting.F)NAMEZDIRSZAPP_DIRSOPTIONSr   c                 S   s   g | ]\}}|d kr|qS )   r   ).0aliascountr   r   r   
<listcomp>8   s      z+EngineHandler.templates.<locals>.<listcomp>zoTemplate engine aliases aren't unique, duplicates: {}. Set a unique NAME for each engine in settings.TEMPLATES.z, )r   r   Z	TEMPLATESrsplit	Exceptiongetr   formatappendr   most_commonjoin)r   r   Zbackend_namesZtpldefault_nameZinvalid_backendcounts
duplicatesr   r   r   r      s@    


zEngineHandler.templatesc                 C   s   z| j | W S  tk
r   z| j| }W n" tk
rL   td|Y nX | }|d}t|}||}|| j |< | Y S X d S )Nz4Could not find config for '{}' in settings.TEMPLATESr   )r   KeyErrorr   r	   r#   copypopr   )r   r   paramsbackendZ
engine_clsZenginer   r   r   __getitem__C   s"    


zEngineHandler.__getitem__c                 C   s
   t | jS )N)iterr   r   r   r   r   __iter__Z   s    zEngineHandler.__iter__c                    s    fdd D S )Nc                    s   g | ]} | qS r   r   )r   r   r1   r   r   r   ^   s     z%EngineHandler.all.<locals>.<listcomp>r   r1   r   r1   r   all]   s    zEngineHandler.all)N)	r
   r   r   r   r   r   r/   r2   r3   r   r   r   r   r      s   

)r   c                    s    fddt  D }t|S )z
    Return an iterable of paths of directories to load app templates from.

    dirname is the name of the subdirectory containing templates inside
    installed applications.
    c                    s2   g | ]*}|j rt|j    rt|j   qS r   )pathr   is_dir)r   Z
app_configdirnamer   r   r   i   s    z)get_app_template_dirs.<locals>.<listcomp>)r   Zget_app_configstuple)r7   Ztemplate_dirsr   r6   r   get_app_template_dirsa   s    
r9   )	functoolscollectionsr   pathlibr   Zdjango.appsr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.utils.functionalr   Zdjango.utils.module_loadingr   r	   r   	lru_cacher9   r   r   r   r   <module>   s   Q