
vÅÏ^â  ã               @   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 m	 Z	 d d l
 m Z d d l m Z d d	 l m Z Gd
 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 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 d d „  Z d d d  „ Z d! d" „  Z d S)#ÚEnginezdjango.template.defaulttagszdjango.template.defaultfilterszdjango.template.loader_tagsNFÚ zutf-8Tc             C   s&  | d  k r g  } | d  k r$ g  } | d  k rd d g } | rL | d g 7} | sv d | f g } n | rv t  d ƒ ‚ | d  k rˆ i  } |	 d  k rš g  }	 | |  _ | |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 |  j
 | ƒ |  _ |  j |	 |  _ |  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   ú8/tmp/pip-build-8lau8j11/django/django/template/engine.pyÚ__init__   s:    											zEngine.__init__c              C   s]   d d l  m }  d d l m } x* |  j ƒ  D] } t | | ƒ r- | j Sq- Wt 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   s0   t  } | t |  j ƒ 7} t d d „  | Dƒ ƒ S)Nc             s   s   |  ] } t  | ƒ Vq d  S)N)r   )Ú.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 Sr   )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   s7   i  } x* | j  ƒ  D] \ } } t | ƒ | | <q W| S)N)Úitemsr
   )r   r   ZloadedÚnamer%   r   r   r   r   Z   s    zEngine.get_template_librariesc             C   s   |  j  |  j ƒ S)N)Úget_template_loadersr   )r   r   r   r   Útemplate_loaders`   s    zEngine.template_loadersc             C   sC   g  } x6 | D]. } |  j  | ƒ } | d  k	 r | j | ƒ q W| S)N)Úfind_template_loaderÚappend)r   r.   r   Ztemplate_loaderÚloaderr   r   r   r-   d   s    zEngine.get_template_loadersc             C   sf   t  | t t f ƒ r$ | ^ } } n g  } t  | t ƒ rR t | ƒ } | |  | Œ St d | ƒ ‚ d  S)Nz3Invalid value in template loaders configuration: %r)r!   r'   ÚlistÚstrr   r   )r   r1   ÚargsÚloader_classr   r   r   r/   l   s    zEngine.find_template_loaderc             C   sŽ   g  } xo |  j  D]d } y& | j | d | ƒ} | | j f SWq t k
 rs } z | j | j ƒ WYd  d  } ~ Xq Xq Wt | d | ƒ‚ d  S)NÚskipÚtried)r.   Úget_templateÚoriginr	   Úextendr7   )r   r,   r   r6   r7   r1   Ú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@   |  j  | ƒ \ } } t | d ƒ s< t | | | d |  ƒ} | S)zƒ
        Return a compiled Template object for the given template name,
        handling template inheritance recursively.
        Úrenderr"   )r=   Úhasattrr   )r   Útemplate_namer;   r9   r   r   r   r8   Š   s    zEngine.get_templatec             C   sr   t  | t t f ƒ r' |  j | ƒ } n |  j | ƒ } t  | t ƒ rR | j | ƒ S| j t | d |  j ƒƒ Sd S)z€
        Render the template specified by template_name with the given context.
        For use in Django's test suite.
        r   N)r!   r2   r'   Úselect_templater8   r   r?   r   )r   rA   ÚcontextÚtr   r   r   Úrender_to_string•   s    zEngine.render_to_stringc             C   s¥   | s t  d ƒ ‚ g  } xq | D]i } y |  j | ƒ SWq t  k
 r‡ } z/ | j d | k rr | j | j d ƒ w WYd d } ~ Xq Xq Wt  d j | ƒ ƒ ‚ d S)zV
        Given a list of template names, return the first that can be loaded.
        zNo template names providedr   Nz, )r	   r8   r4   r0   Újoin)r   Ztemplate_name_listÚ	not_foundrA   Úexcr   r   r   rB   ¥   s    zEngine.select_template)Ú__name__Ú
__module__Ú__qualname__r   r   ÚstaticmethodÚ	functoolsÚ	lru_cacher#   r   r(   r   r   r.   r-   r/   r=   r>   r8   rE   rB   r   r   r   r   r      s&   			!
r   )rM   Zdjango.core.exceptionsr   Zdjango.utils.functionalr   Zdjango.utils.module_loadingr   Úbaser   r   rC   r   Ú
exceptionsr	   Zlibraryr
   r   r   r   r   r   Ú<module>   s   