
 X                 @   s   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
 m Z d d l m Z d d l m Z d d	 l m Z Gd
 d   d e  Z d S)    )ImproperlyConfigured)	lru_cachesix)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  } n  | d  k r* g  } n  | d  k rX d g } | rm | d g 7} qm n | rm t  d   n  | d  k r i  } n  |	 d  k r g  }	 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.)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   D/home/ubuntu/projects/ifolica/build/django/django/template/engine.py__init__   s6    														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   )
isinstance).0engine)r!   r   r   
<listcomp>J   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_default4   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>[   s    z5Engine.template_context_processors.<locals>.<genexpr>)r
   tupler   )r   r   r   r   r   template_context_processorsW   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%   ^   s   	 z0Engine.get_template_builtins.<locals>.<listcomp>r   )r   r   r   r   r   r   ]   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   `   s    zEngine.get_template_librariesc             C   s   |  j  |  j  S)N)get_template_loadersr   )r   r   r   r   template_loadersf   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   r1   r   Ztemplate_loaderloaderr   r   r   r0   j   s    zEngine.get_template_loadersc             C   s}   t  | t t f  r8 t | d d    } | d } n g  } t  | t j  ri t |  } | |  |  St d |   d  S)Nr   r   z3Invalid value in template loaders configuration: %r)r"   r+   listr   string_typesr   r   )r   r4   argsloader_classr   r   r   r2   r   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)r1   Zsupports_recursionget_templateoriginr   extendr:   )r   r/   r   r9   r:   r4   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   sC   |  j  |  \ } } t | d  s? t | | | d |  } n  | S)z
        Returns a compiled Template object for the given template name,
        handling template inheritance recursively.
        renderr$   )r@   hasattrr	   )r   template_namer>   r<   r   r   r   r;      s    zEngine.get_templatec             C   si   t  | t t f  r' |  j |  } n |  j |  } t  | t  rR | j |  S| j t |   Sd S)z
        Render the template specified by template_name with the given context.
        For use in Django's test suite.
        N)r"   r5   r+   select_templater;   r   rB   )r   rD   contexttr   r   r   render_to_string   s    zEngine.render_to_stringc             C   s   | s t  d   n  g  } xt | D]l } y |  j |  SWq" t  k
 r } z2 | j d | k rx | j | j d  n  w" WYd d } ~ Xq" Xq" Wt  d j |    d S)zW
        Given a list of template names, returns the first that can be loaded.
        zNo template names providedr   Nz, )r   r;   r7   r3   join)r   Ztemplate_name_list	not_foundrD   excr   r   r   rE      s    zEngine.select_template)__name__
__module____qualname__r   r   staticmethodr   r(   r   r,   r   r   r1   r0   r2   r@   rA   r;   rH   rE   r   r   r   r   r      s&   			"r   N)Zdjango.core.exceptionsr   Zdjango.utilsr   r   Zdjango.utils.functionalr   Zdjango.utils.module_loadingr   baser   r	   rF   r
   
exceptionsr   Zlibraryr   objectr   r   r   r   r   <module>   s   