o
    [hK                     @   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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 )    )defaultdict)import_module)walk_packages)apps)settings)ErrorWarning)TemplateDoesNotExist)make_context)Engine)InvalidTemplateLibrary   )
BaseEnginec                       sP   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
  ZS )DjangoTemplatesZ	templatesc                    s~   |  }|d  }|dd |dtj |dd |di }| ||d< t | t	| j
| jfi || _d S )NOPTIONS
autoescapeTdebugZfile_charsetzutf-8	libraries)copypop
setdefaultr   DEBUGgetget_templatetag_librariessuper__init__r   dirsZapp_dirsengine)selfparamsoptionsr   	__class__ /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/django/template/backends/django.pyr      s   zDjangoTemplates.__init__c                 K   s   g |   |  S N)"_check_string_if_invalid_is_string+_check_for_template_tags_with_the_same_name)r   kwargsr#   r#   r$   check   s
   zDjangoTemplates.checkc                 C   s2   | j j}t|tstd|t|f | ddgS g S )NzK'string_if_invalid' in TEMPLATES OPTIONS must be a string but got: %r (%s).ztemplates.E002objid)r   Zstring_if_invalid
isinstancestrr   type)r   valuer#   r#   r$   r&   $   s   

z2DjangoTemplates._check_string_if_invalid_is_stringc                 C   s   t t}t D ]\}}|| | q| jj D ]\}}|| | qg }| D ]%\}}t|dkrPddd t	|D }|
t|d| | dd q+|S )Nr   z, c                 s   s    | ]}t |V  qd S r%   )repr).0itemr#   r#   r$   	<genexpr>>   s    zNDjangoTemplates._check_for_template_tags_with_the_same_name.<locals>.<genexpr>z, is used for multiple template tag modules: ztemplates.W003r*   )r   setget_template_tag_modulesaddr   r   itemslenjoinsortedappendr   )r   r   module_namemodule_patherrorsZlibrary_namer8   r#   r#   r$   r'   1   s(   	z;DjangoTemplates._check_for_template_tags_with_the_same_namec                 C   s   t | j|| S r%   )Templater   from_string)r   Ztemplate_coder#   r#   r$   rA   J   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   Ztemplate_nameexcr#   r#   r$   rB   M   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   s   
z)DjangoTemplates.get_templatetag_libraries)__name__
__module____qualname__Zapp_dirnamer   r)   r&   r'   rA   rB   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   rK   rL   r#   r#   r$   r   ^   s   
zTemplate.__init__c                 C   s   | j jS r%   )rK   origin)r   r#   r#   r$   rM   b   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
   rL   r   r   rK   renderr	   rC   )r   contextrequestrD   r#   r#   r$   rN   f   s   zTemplate.render)NN)rG   rH   rI   r   propertyrM   rN   r#   r#   r#   r$   r@   ]   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).
    )triedrL   chaintemplate_debug)rL   r"   argsrR   rS   hasattrrT   rD   rL   newr#   r#   r$   copy_exceptionp   s
   

rY   c                 C   s   t | |}|| )zT
    Reraise TemplateDoesNotExist while maintaining template debug information.
    )rY   rW   r#   r#   r$   rC   }   s   
rC   c               	   c   s|    dg} |  dd t D  | D ])}zt|}W n	 ty#   Y qw t|dr;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)r2   Z
app_configr#   r#   r$   r4      s    
z+get_template_tag_modules.<locals>.<genexpr>__path__.N)	extendr   Zget_app_configsr   ImportErrorrV   get_package_librariesremoveprefixlstrip)
candidates	candidatepkgrZ   r#   r#   r$   r6      s    

r6   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#   )r2   r=   Z	full_namer#   r#   r$   
<dictcomp>   s    
z+get_installed_libraries.<locals>.<dictcomp>)r6   r#   r#   r#   r$   rE      s   rE   c                 c   sr    t | j| jd D ],}zt|d }W n ty+ } ztd|d |f |d}~ww t|dr6|d V  q
dS )zZ
    Recursively yield template tag libraries defined in submodules of a
    package.
    r\   r   zSInvalid template library specified. ImportError raised when trying to load '%s': %sNregister)r   r[   rG   r   r^   r   rV   )rd   entrymoduleer#   r#   r$   r_      s$   


r_   r%   )collectionsr   	importlibr   pkgutilr   Zdjango.appsr   Zdjango.confr   Zdjango.core.checksr   r   Zdjango.templater	   Zdjango.template.contextr
   Zdjango.template.enginer   Zdjango.template.libraryr   baser   r   r@   rY   rC   r6   rE   r_   r#   r#   r#   r$   <module>   s$    M
