o
    :ZcZ                     @   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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                    s   |  }|d  }|dd |dtj |dtj |di }| ||d< t 	| t
| j| jfi || _d S )NOPTIONS
autoescapeTdebugfile_charset	libraries)copypop
setdefaultr   DEBUGFILE_CHARSETgetget_templatetag_librariessuper__init__r   dirsapp_dirsengine)selfparamsoptionsr   	__class__ U/var/www/chikooza/env/lib/python3.10/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y" } zt||  W Y d }~d S d }~ww 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   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   r6   r7   r$   r$   r%   r   2   s   
zTemplate.__init__c                 C   s   | j jS r&   )r6   origin)r   r$   r$   r%   r8   6   s   zTemplate.originNc              
   C   sV   t ||| jjjd}z| j|W S  ty* } zt|| j W Y d }~d S d }~ww )N)r   )r   r7   r   r   r6   renderr   r+   )r   contextrequestr-   r$   r$   r%   r9   :   s   zTemplate.render)NN)r1   r2   r3   r   propertyr8   r9   r$   r$   r$   r%   r'   0   s
    
r'   Nc                 C   s:   |p| j }| j| j| j|| jd}t| dr| 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).
    )triedr7   chaintemplate_debug)r7   r#   argsr=   r>   hasattrr?   r-   r7   newr$   r$   r%   copy_exceptionB   s
   

rD   c                 C   s   t | |}|| )zT
    Reraise TemplateDoesNotExist while maintaining template debug information.
    )rD   rB   r$   r$   r%   r+   O   s   
r+   c               	   C   s   i } dg}| dd t D  |D ]*}zt|}W n	 ty$   Y qw t|dr=t|D ]}|| |t|d d < q.q| 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).0
app_configr$   r$   r%   	<genexpr>`   s
    
z*get_installed_libraries.<locals>.<genexpr>__path__r
   N)extendr   get_app_configsr   ImportErrorrA   get_package_librarieslen)r   
candidates	candidatepkgrE   r$   r$   r%   r.   W   s    

r.   c                 c   sp    t | j| jd D ]+}zt|d }W n ty* } z
td|d |f d}~ww t|dr5|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   rI   r1   r   rL   r	   rA   )rQ   entrymoduleer$   r$   r%   rM   r   s    


rM   r&   )	importlibr   pkgutilr   django.appsr   django.confr   django.templater   django.template.contextr   django.template.enginer   django.template.libraryr	   baser   r   r'   rD   r+   r.   rM   r$   r$   r$   r%   <module>   s    "
