

_V                 @   s>  d  d l  m Z d  d l Z 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 m Z 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 Gd d   d e  Z Gd d   d e  Z d d   Z  d d   Z! d d   Z" d S)    )absolute_importN)import_module)walk_packages)apps)settings)TemplateDoesNotExist)ContextRequestContextmake_context)Engine_dirs_undefined)InvalidTemplateLibrary)six)RemovedInDjango110Warning   )
BaseEnginec                   sO   e  Z d  Z d Z   f d d   Z d d   Z e d d  Z d d	   Z   S)
DjangoTemplatesZ	templatesc                s   | j    } | j d  j    } | j d t j  | j d t j  | j d i   } |  j |  | d <t t	 |   j
 |  t |  j |  j |  |  _ d  S)NOPTIONSdebugZfile_charset	libraries)copypop
setdefaultr   DEBUGZFILE_CHARSETgetget_templatetag_librariessuperr   __init__r   dirsZapp_dirsengine)selfparamsoptionsr   )	__class__ A/tmp/pip-build-ghmbqnp_/Django/django/template/backends/django.pyr      s    zDjangoTemplates.__init__c             C   s   t  |  j j |  |   S)N)Templater   from_string)r    Ztemplate_coder$   r$   r%   r'   #   s    zDjangoTemplates.from_stringc             C   sY   y  t  |  j j | |  |   SWn2 t k
 rT } z t | |   WYd  d  } ~ Xn Xd  S)N)r&   r   get_templater   reraise)r    Ztemplate_namer   excr$   r$   r%   r(   &   s     zDjangoTemplates.get_templatec             C   s   t    } | j |  | S)z
        Return a collation of template tag libraries from installed
        applications and the supplied custom_libraries argument.
        )get_installed_librariesupdate)r    Zcustom_librariesr   r$   r$   r%   r   ,   s    	z)DjangoTemplates.get_templatetag_libraries)	__name__
__module____qualname__Zapp_dirnamer   r'   r   r(   r   r$   r$   )r#   r%   r      s
   
r   c               @   s@   e  Z d  Z d d   Z e d d    Z d d d d  Z d S)r&   c             C   s   | |  _  | |  _ d  S)N)templatebackend)r    r0   r1   r$   r$   r%   r   8   s    	zTemplate.__init__c             C   s
   |  j  j S)N)r0   origin)r    r$   r$   r%   r2   <   s    zTemplate.originNc             C   s   t  | t  rR | d  k	 r9 | | j k	 r9 t d   n  t j d t d d n7 t  | t  rz t j d t d d n t | |  } y |  j	 j
 |  SWn5 t k
 r } z t | |  j  WYd  d  } ~ Xn Xd  S)Nzrender() was called with a RequestContext and a request argument which refer to different requests. Make sure that the context argument is a dict or at least that the two arguments refer to the same request.z:render() must be called with a dict, not a RequestContext.
stacklevel   z3render() must be called with a dict, not a Context.)
isinstancer	   request
ValueErrorwarningswarnr   r   r
   r0   renderr   r)   r1   )r    contextr6   r*   r$   r$   r%   r:   @   s     zTemplate.render)r-   r.   r/   r   propertyr2   r:   r$   r$   r$   r%   r&   6   s   r&   c             C   sc   |  j  d |  j d | |  j  } t |  d  r? |  j | _ n  t j |  j  | t j   d  d S)zT
    Reraise TemplateDoesNotExist while maintaining template debug information.
    triedr1   template_debugr4   N)	r#   r=   argshasattrr>   r   r)   sysexc_info)r*   r1   newr$   r$   r%   r)   d   s    !r)   c              C   s   i  }  d g } | j  d d   t j   D  x} | D]u } y t |  } Wn t k
 rc w6 Yn Xt | d  r6 x5 t |  D]$ } | |  | t |  d d  <q Wq6 q6 W|  S)a  
    Return the built-in template tag libraries and those from installed
    applications. Libraries are stored in a dictionary where keys are the
    individual module names, not the full module paths. Example:
    django.templatetags.i18n is stored as i18n.
    zdjango.templatetagsc             s   s   |  ] } d  | j  Vq d S)z%s.templatetagsN)name).0Z
app_configr$   r$   r%   	<genexpr>x   s   z*get_installed_libraries.<locals>.<genexpr>__path__r   N)extendr   Zget_app_configsr   ImportErrorr@   get_package_librarieslen)r   
candidates	candidatepkgrD   r$   r$   r%   r+   n   s    		)r+   c             c   s   x t  |  j |  j d  D]w } y t | d  } Wn? t k
 ru } z t d | d | f   WYd d } ~ Xn Xt | d  r | d Vq q Wd S)zZ
    Recursively yield template tag libraries defined in submodules of a
    package.
    .r   zSInvalid template library specified. ImportError raised when trying to load '%s': %sNregister)r   rG   r-   r   rI   r   r@   )rN   entrymoduleer$   r$   r%   rJ      s     'rJ   )#
__future__r   rA   r8   	importlibr   pkgutilr   Zdjango.appsr   Zdjango.confr   Zdjango.templater   Zdjango.template.contextr   r	   r
   Zdjango.template.enginer   r   Zdjango.template.libraryr   Zdjango.utilsr   Zdjango.utils.deprecationr   baser   r   objectr&   r)   r+   rJ   r$   r$   r$   r%   <module>   s$   !.
