

_V*                 @   s   d  d l  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 d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z e   Z e   Z e   Z Gd d   d e  Z d S)    N)ImproperlyConfigured)	lru_cachesix)RemovedInDjango110Warning)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 d d d d d d d 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 d  Z d d   Z e d d  Z d e e e d d  Z e d  d!  Z d S)"Enginezdjango.template.defaulttagszdjango.template.defaultfilterszdjango.template.loader_tagsNF zutf-8c             C   sY  | d  k r g  } n  | d  k r* g  } n  | d  k r? g  } n  | d  k rm d g } | r | d g 7} q n | r t  d   n  |	 d  k r i  }	 n  |
 d  k r g  }
 n  t | t j  r t  d   n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 | |  _ |	 |  _ |  j |	  |  _ |  j |
 |  _ |  j |  j  |  _ d  S)Nz)django.template.loaders.filesystem.Loaderz.django.template.loaders.app_directories.Loaderz1app_dirs must not be set when loaders is defined.z4allowed_include_roots must be a tuple, not a string.)r   
isinstancer   string_typesdirsapp_dirsallowed_include_roots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    8/tmp/pip-build-ghmbqnp_/Django/django/template/engine.py__init__   s@    															zEngine.__init__c                 s   d d l  m }  d d l m     f d d   |  j   D } t |  d k r\ | d j St |  d k r} t d   n t d   d	 S)
a  
        When only one DjangoTemplates backend is configured, returns it.

        Raises ImproperlyConfigured otherwise.

        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)DjangoTemplatesc                s%   g  |  ] } t  |    r |  q Sr    )r   ).0engine)r$   r    r!   
<listcomp>X   s   	 z&Engine.get_default.<locals>.<listcomp>r   z)No DjangoTemplates backend is configured.zPSeveral DjangoTemplates backends are configured. You must select one explicitly.N)Zdjango.templater#   Zdjango.template.backends.djangor$   alllenr&   r   )r#   Zdjango_enginesr    )r$   r!   get_defaultB   s    zEngine.get_defaultc             C   s0   t  } | t |  j  7} t d d   | D  S)Nc             s   s   |  ] } t  |  Vq d  S)N)r   )r%   pathr    r    r!   	<genexpr>i   s    z5Engine.template_context_processors.<locals>.<genexpr>)r   tupler   )r   r   r    r    r!   template_context_processorse   s    z"Engine.template_context_processorsc             C   s   d d   | D S)Nc             S   s   g  |  ] } t  |   q Sr    )r   )r%   xr    r    r!   r'   l   s   	 z0Engine.get_template_builtins.<locals>.<listcomp>r    )r   r   r    r    r!   r   k   s    zEngine.get_template_builtinsc             C   s7   i  } x* | j    D] \ } } t |  | | <q W| S)N)itemsr   )r   r   Zloadednamer+   r    r    r!   r   n   s    zEngine.get_template_librariesc             C   s   |  j  |  j  S)N)get_template_loadersr   )r   r    r    r!   template_loaderst   s    zEngine.template_loadersc             C   sF   g  } x9 | D]1 } |  j  |  } | d  k	 r | j |  q q W| S)N)find_template_loaderappend)r   r3   r   Ztemplate_loaderloaderr    r    r!   r2   x   s    zEngine.get_template_loadersc             C   s   t  | t t f  r8 t | d d    } | d } n g  } t  | t j  r t |  } t | d d  r | j d |   n t j	 d | t
 d d | |   St d |   d  S)	Nr   r   Z_accepts_engine_in_initFzc%s inherits from django.template.loader.BaseLoader instead of django.template.loaders.base.Loader. 
stacklevel   z3Invalid value in template loaders configuration: %r)r   r-   listr   r   r   getattrinsertwarningswarnr   r   )r   r6   argsloader_classr    r    r!   r4      s    
zEngine.find_template_loaderc             C   s   g  } x |  j  D] } | j r y, | j | d | d | } | | j f SWq t k
 r } z | j | j  WYd  d  } ~ Xq Xq y | | |  SWq t k
 r Yq Xq Wt | d |  d  S)NZtemplate_dirsskiptried)r3   Zsupports_recursionget_templateoriginr   extendrA   )r   r1   r   r@   rA   r6   templateer    r    r!   find_template   s    	&	zEngine.find_templatec             C   s   t  | d |  S)z
        Returns 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   sq   | t  k r d } n t j d t d d |  j | |  \ } } t | d  sm t | | | d |  } n  | S)z
        Returns a compiled Template object for the given template name,
        handling template inheritance recursively.
        Nz0The dirs argument of get_template is deprecated.r7   r8   renderr&   )_dirs_undefinedr<   r=   r   rG   hasattrr
   )r   template_namer   rE   rC   r    r    r!   rB      s    	zEngine.get_templatec          	   C   s/  | t  k r d  } n t j d t d d | t k r: n t j d t d d | t k re d  } n t j d t d d | } t | t t f  r |  j	 | |  } n |  j
 | |  } | s t | t  r | j |  S| j t |   Sn  | s| j |  S| j |   | j |  SWd  QXd  S)Nz@The context_instance argument of render_to_string is deprecated.r7      z4The dirs argument of render_to_string is deprecated.zCThe dictionary argument of render_to_string was renamed to context.)_context_instance_undefinedr<   r=   r   rJ   _dictionary_undefinedr   r9   r-   select_templaterB   r	   rI   push)r   rL   contextZcontext_instancer   
dictionarytr    r    r!   render_to_string   s6    		zEngine.render_to_stringc             C   s   | t  k r n t j d t d d | s: t d   n  g  } xw | D]o } y |  j | |  SWqG t k
 r } z2 | j d | k r | j | j d  n  wG WYd d } ~ XqG XqG Wt d j |    d S)zW
        Given a list of template names, returns the first that can be loaded.
        z3The dirs argument of select_template is deprecated.r7   rM   zNo template names providedr   Nz, )	rJ   r<   r=   r   r   rB   r>   r5   join)r   Ztemplate_name_listr   	not_foundrL   excr    r    r!   rP      s     zEngine.select_template)__name__
__module____qualname__r   r"   staticmethodr   r*   r   r.   r   r   r3   r2   r4   rG   rH   rJ   rB   rN   rO   rU   rP   r    r    r    r!   r      s.   		%")r   )r<   Zdjango.core.exceptionsr   Zdjango.utilsr   r   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   Zdjango.utils.module_loadingr   baser	   r
   rR   r   
exceptionsr   Zlibraryr   objectrN   rO   rJ   r   r    r    r    r!   <module>   s   			