3
(hn                 @   sp   d Z ddlZddlZ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 G d	d
 d
eZdS )z4
Wrapper for loading templates from the filesystem.
    N)SuspiciousFileOperation)OriginTemplateDoesNotExist)	safe_join)RemovedInDjango20Warning   )Loaderc               @   s0   e Zd Zdd Zdd Zd
ddZddd	ZdS )r   c             C   s   | j jS )N)enginedirs)self r   F/tmp/pip-install-q3hcpn_q/Django/django/template/loaders/filesystem.pyget_dirs   s    zLoader.get_dirsc             C   sf   y(t j|j| jjd
}|j S Q R X W n8 tk
r` } z|jtjkrNt	| W Y d d }~X nX d S )N)encoding)
ioopennamer	   Zfile_charsetreadIOErrorerrnoENOENTr   )r   originfper   r   r   get_contents   s    zLoader.get_contentsNc             c   sT   |s| j  }xB|D ]:}yt||}W n tk
r:   wY nX t||| dV  qW dS )z
        Return an Origin object pointing to an absolute path in each directory
        in template_dirs. For security reasons, if a path doesn't lie inside
        one of the template_dirs it is excluded from the result set.
        )r   template_nameloaderN)r   r   r   r   )r   r   template_dirsZtemplate_dirr   r   r   r   get_template_sources   s    
zLoader.get_template_sourcesc             C   sT   t jdt x:| j||D ]*}y| j||jfS  tk
rB   Y qX qW t|d S )Nz_The load_template_sources() method is deprecated. Use get_template() or get_contents() instead.)warningswarnr   r   r   r   r   )r   r   r   r   r   r   r   load_template_source5   s    
zLoader.load_template_source)N)N)__name__
__module____qualname__r   r   r   r!   r   r   r   r   r      s   	
r   )__doc__r   r   r   Zdjango.core.exceptionsr   Zdjango.templater   r   Zdjango.utils._osr   Zdjango.utils.deprecationr   baser   Z
BaseLoaderr   r   r   r   <module>   s   