a
���gy! � @ s� d dl Z d dlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddd �Z
d
d� Zdd
� Ze j
dkrrdd� ZnXer�zd dlZW n ey� dd� ZY q�0 dd� Zn"d dlZG dd� dej�Zdd� ZdS )� N)�CodeType� )�TemplateSyntaxError)�PYPY)�
internal_code)�missingc C s t �� \}}}t|t�rd|jsdd|_| |_z|�d� W n tyJ Y n0 t|d|j pZd|j
�}n|j}g }|dur�|jj
tv r�|j}qn|jj�d�}|dur�|�|j�}t|||j |�}|�|� n
|�|� |j}qnd}t|�D ]}t||�}q�|||fS )a� Rewrite the current exception to replace any tracebacks from
within compiled template code with tracebacks that look like they
came from the template source.
This must be called within an ``except`` block.
:param exc_info: A :meth:`sys.exc_info` tuple. If not provided,
the current ``exc_info`` is used.
:param source: For ``TemplateSyntaxError``, the original source if
known.
:return: A :meth:`sys.exc_info` tuple that can be re-raised.
TNz <unknown>Z__jinja_template__)�sys�exc_info�
isinstancer Z
translated�source�with_traceback�AttributeError�fake_traceback�filename�lineno�tb_next�tb_frame�f_coder � f_globals�getZget_corresponding_lineno� tb_lineno�append�reversed�tb_set_next) r �exc_type� exc_value�tb�stack�templater Zfake_tbr � r �0/usr/lib/python3.9/site-packages/jinja2/debug.py�rewrite_traceback_stack
s8
�
r! c C sf |dur"t |jj�}|�dd� ni }||| d�}td|d d |d�}z�d}|dur�|jjj}|d krpd
}n|�d�r�d|d
d� }g } ddddddddddd|fd|fdddddfD ]P}
t|
t �r�| �
|
d � q�z| �
t|d|
�� W q� t�y
Y q�Y q�0 q�t
| � }W n t�y, Y n0 zt|||� W n" t�y` t�� d j Y S 0 dS )!a, Produce a new traceback object that looks like it came from the
template source instead of the compiled code. The filename, line
number, and location name will point to the template, and the local
variables will be the current template context.
:param exc_value: The original exception to be re-raised to create
the new traceback.
:param tb: The original traceback to get the local variables and
code info from.
:param filename: The template filename.
:param lineno: The line number in the template source.
N�__jinja_exception__)�__name__�__file__r"