U
    N|e*                     @   s   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 d dlmZ d dlmZ d	d
lmZ G dd deZG dd dZdddZdd Zdd Zdd Zdd ZdS )    )import_module)walk_packages)apps)settings)TemplateDoesNotExist)make_context)Engine)InvalidTemplateLibrary   )
BaseEnginec                       s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
DjangoTemplates	templatesc                    sz   |  }|d  }|dd |dtj |dd |di }| ||d< t | t	| j
| jf|| _d S )NOPTIONS
autoescapeTdebugfile_charsetzutf-8	libraries)copypop
setdefaultr   DEBUGgetget_templatetag_librariessuper__init__r   dirsapp_dirsengine)selfparamsoptionsr   	__class__ \/var/www/website-v5/atlas_env/lib/python3.8/site-packages/django/template/backends/django.pyr      s    zDjangoTemplates.__init__c                 C   s   t | j|| S N)Templater   from_string)r   template_coder#   r#   r$   r'      s    zDjangoTemplates.from_stringc              
   C   sF   zt | j|| W S  tk
r@ } zt||  W 5 d }~X Y nX d S r%   )r&   r   get_templater   reraise)r   template_nameexcr#   r#   r$   r)      s    zDjangoTemplates.get_templatec                 C   s   t  }|| |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__app_dirnamer   r'   r)   r   __classcell__r#   r#   r!   r$   r      s
   r   c                   @   s*   e Zd Zdd Zedd ZdddZdS )	r&   c                 C   s   || _ || _d S r%   )templatebackend)r   r4   r5   r#   r#   r$   r   0   s    zTemplate.__init__c                 C   s   | j jS r%   )r4   origin)r   r#   r#   r$   r6   4   s    zTemplate.originNc              
   C   sV   t ||| jjjd}z| j|W S  tk
rP } zt|| j W 5 d }~X Y nX d S )N)r   )r   r5   r   r   r4   renderr   r*   )r   contextrequestr,   r#   r#   r$   r7   8   s      zTemplate.render)NN)r/   r0   r1   r   propertyr6   r7   r#   r#   r#   r$   r&   /   s   
r&   Nc                 C   s:   |p| j }| j| j| j|| jd}t| dr6| j|_|S )z
    Create a new TemplateDoesNotExist. Preserve its declared attributes and
    template debug data but discard __traceback__, __context__, and __cause__
    to make this object suitable for keeping around (in a cache, for example).
    )triedr5   chaintemplate_debug)r5   r"   argsr;   r<   hasattrr=   r,   r5   newr#   r#   r$   copy_exceptionB   s
    

rB   c                 C   s   t | |}|| dS )zT
    Reraise TemplateDoesNotExist while maintaining template debug information.
    N)rB   r@   r#   r#   r$   r*   O   s    
r*   c               	   c   s   dg} |  dd t D  | D ]\}zt|}W n tk
rJ   Y q"Y nX t|dr"t|D ]}|t|d d |fV  q^q"dS )z^
    Yield (module_name, module_path) pairs for all installed template tag
    libraries.
    zdjango.templatetagsc                 s   s   | ]}|j  d V  qdS )z.templatetagsN)name).0
app_configr#   r#   r$   	<genexpr>]   s    z+get_template_tag_modules.<locals>.<genexpr>__path__r
   N)extendr   get_app_configsr   ImportErrorr?   get_package_librarieslen)
candidates	candidatepkgrC   r#   r#   r$   get_template_tag_modulesW   s    


rP   c                   C   s   dd t  D 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.
    c                 S   s   i | ]\}}||qS r#   r#   )rD   module_nameZ	full_namer#   r#   r$   
<dictcomp>t   s     z+get_installed_libraries.<locals>.<dictcomp>)rP   r#   r#   r#   r$   r-   m   s    r-   c                 c   sz   t | j| jd D ]b}zt|d }W n8 tk
r^ } ztd|d |f |W 5 d}~X Y nX t|dr|d V  qd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   rJ   r	   r?   )rO   entrymoduleer#   r#   r$   rK   y   s    

rK   )N)	importlibr   pkgutilr   django.appsr   django.confr   django.templater   django.template.contextr   Zdjango.template.enginer   Zdjango.template.libraryr	   baser   r   r&   rB   r*   rP   r-   rK   r#   r#   r#   r$   <module>   s   !
