o
    ˷e                     @   s   d dl m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G dd dZG dd dZdd ZdS )    )PathN)settings)TemplateDoesNotExistTemplateSyntaxError)cached_propertyimport_string   )
BaseEnginec                       s<   e Zd ZdZ fddZdd Zdd Zedd	 Z  Z	S )
Jinja2jinja2c                    s   |  }|d  }t | |dg | _|dd}t|}d|vr.t| j|d< |	dd |	dt
j |	d	t
jrDtjntj |d
i || _d S )NOPTIONScontext_processorsenvironmentzjinja2.Environmentloader
autoescapeTauto_reload	undefined )copypopsuper__init__r   r   r   FileSystemLoadertemplate_dirs
setdefaultr   DEBUGDebugUndefined	Undefinedenv)selfparamsoptionsr   environment_cls	__class__r   V/var/www/ideatree/venv/lib/python3.10/site-packages/django/template/backends/jinja2.pyr      s   zJinja2.__init__c                 C   s   t | j|| S N)Templater   from_string)r    template_coder   r   r&   r)   %   s   zJinja2.from_stringc              
   C   sr   z
t | j|| W S  tjy } zt|j| d|d }~w tjy8 } zt|j}t	||_
||d }~ww )N)backend)r(   r   get_templater   TemplateNotFoundr   namer   argsget_exception_infotemplate_debug)r    template_nameexcnewr   r   r&   r,   (   s   

zJinja2.get_templatec                 C   s   dd | j D S )Nc                 S   s   g | ]}t |qS r   r   ).0pathr   r   r&   
<listcomp>4   s    z6Jinja2.template_context_processors.<locals>.<listcomp>)r   )r    r   r   r&   template_context_processors2   s   z"Jinja2.template_context_processors)
__name__
__module____qualname__app_dirnamer   r)   r,   r   r8   __classcell__r   r   r$   r&   r      s    
r   c                   @   s   e Zd Zdd ZdddZdS )r(   c                 C   s"   || _ || _t|j|jd| _d S )Nr.   r2   )templater+   Originfilenamer.   origin)r    r?   r+   r   r   r&   r   8   s   zTemplate.__init__Nc              
   C   s   ddl m}m} |d u ri }|d ur0||d< |||d< |||d< | jjD ]	}||| q&z| j|W S  tj	yQ } zt	|j
}t||_||d }~ww )Nr	   )csrf_input_lazycsrf_token_lazyrequest
csrf_input
csrf_token)utilsrC   rD   r+   r8   updater?   renderr   r   r/   r0   r1   )r    contextrE   rC   rD   context_processorr3   r4   r   r   r&   rJ   @   s"   

zTemplate.render)NN)r9   r:   r;   r   rJ   r   r   r   r&   r(   7   s    r(   c                   @   s   e Zd ZdZdd ZdS )r@   zc
    A container to hold debug information as described in the template API
    documentation.
    c                 C   s   || _ || _d S r'   r>   )r    r.   r2   r   r   r&   r   Y   s   
zOrigin.__init__N)r9   r:   r;   __doc__r   r   r   r   r&   r@   S   s    r@   c           
      C   s   d}| j }| j}|du rt| j}| r| }|durGtt| 	ddd}||d  d }t
|}td|| d }t||| }	n
d}g }d } }}	| j| j|||	 |d|d|||	d
S )	z
    Format exception information for display on the debug page using the
    structure described in the template API documentation.
    
   N
r	   )startr    )
r.   messagesource_lineslinebeforeduringaftertotaltopbottom)linenosourcer   rA   exists	read_textlist	enumeratestripsplitlenmaxminrR   )
	exceptioncontext_linesr[   r\   exception_filelinesrV   rX   rY   rZ   r   r   r&   r0   ^   s6   

r0   )pathlibr   r   django.confr   django.templater   r   django.utils.functionalr   django.utils.module_loadingr   baser
   r   r(   r@   r0   r   r   r   r&   <module>   s    *