

_V                 @   s   d  d l  Z  d  d l Z d  d l m Z 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 Gd d   d e
  Z Gd d   d e  Z e j   d d    Z d S)    N)CounterOrderedDict)apps)settings)ImproperlyConfigured)	lru_cache)upath)RemovedInDjango110Warning)cached_property)import_stringc               @   s   e  Z d  Z d S)InvalidTemplateEngineErrorN)__name__
__module____qualname__ r   r   7/tmp/pip-build-ghmbqnp_/Django/django/template/utils.pyr      s   r   c               @   sU   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 |  _  n  |  j  s t j d t  i d d 6t j d 6i t j d 6t j d 6t j	 d 6t j
 d 6t j d	 6d
 6g |  _  n  t   } g  } x |  j  D] } | j   } y | d j d d  d } Wn9 t k
 r| j d d  } t d j |    Yn X| j d |  | j d g   | j d d  | j d
 i   | | | d <| j | d  q Wt |  } d d   | j   D } | rt d j d j |     n  | S)NzYou haven't defined a TEMPLATES setting. You must do so before upgrading to Django 1.10. Otherwise Django will be unable to load templates.z/django.template.backends.django.DjangoTemplatesBACKENDZDIRSZallowed_include_rootsZcontext_processorsdebugloadersZstring_if_invalidOPTIONS.   z<not defined>zHInvalid BACKEND for a template engine: {}. Check your TEMPLATES setting.NAMEZAPP_DIRSFc             S   s(   g  |  ] \ } } | d  k r |  q S)   r   ).0aliascountr   r   r   
<listcomp>K   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warningswarnr	   ZTEMPLATE_DIRSZALLOWED_INCLUDE_ROOTSZTEMPLATE_CONTEXT_PROCESSORSZTEMPLATE_DEBUGZTEMPLATE_LOADERSZTEMPLATE_STRING_IF_INVALIDr   copyrsplit	Exceptiongetr   format
setdefaultappendr   most_commonjoin)r   r   Zbackend_namestpldefault_nameZinvalid_backendcounts
duplicatesr   r   r   r      sN    	




	zEngineHandler.templatesc             C   s   y |  j  | SWn t k
 r y |  j | } Wn' t k
 rY t d j |    Yn X| j   } | j d  } t |  } | |  } | |  j  | <| SYn Xd  S)Nz4Could not find config for '{}' in settings.TEMPLATESr   )r   KeyErrorr   r   r+   r'   popr   )r   r!   paramsbackendZ
engine_clsZenginer   r   r   __getitem__T   s    zEngineHandler.__getitem__c             C   s   t  |  j  S)N)iterr   )r   r   r   r   __iter__j   s    zEngineHandler.__iter__c                s     f d d     D S)Nc                s   g  |  ] }   |  q Sr   r   )r    r!   )r   r   r   r#   n   s   	 z%EngineHandler.all.<locals>.<listcomp>r   )r   r   )r   r   allm   s    zEngineHandler.all)	r   r   r   r   r
   r   r8   r:   r;   r   r   r   r   r      s
   8r   c             C   sv   g  } xc t  j   D]U } | j s( q n  t j j | j |   } t j j |  r | j t |   q q Wt |  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.
    )	r   Zget_app_configspathosr/   isdirr-   r   tuple)dirnameZtemplate_dirsZ
app_configZtemplate_dirr   r   r   get_app_template_dirsq   s    	rA   )r=   r%   collectionsr   r   Zdjango.appsr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.utilsr   Zdjango.utils._osr   Zdjango.utils.deprecationr	   Zdjango.utils.functionalr
   Zdjango.utils.module_loadingr   r   objectr   rA   r   r   r   r   <module>   s   ^