o
    'h                  
   @   s   d dl Z d dl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
 ejr/ddlmZ dd	eje d
efddZdedeje deded
ef
ddZdejeejf d
ejeejf fddZdS )    N)CodeType)TracebackType   )TemplateSyntaxError)internal_code)missing)Contextsourcereturnc           	      C   s  t  \}}}tt|}tt|}t|tr2|js2d|_| |_	|
d t|d|jp-d|j}n|j}g }|durp|jjtv rE|j}q7|jjd}|durd||j}t|||j|}|| n|| |j}|dus;d}t|D ]}||_|}qv|
|S )ax  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 source: For ``TemplateSyntaxError``, the original source if
        known.
    :return: The original exception with the rewritten traceback.
    TNz	<unknown>__jinja_template__)sysexc_infotcastBaseExceptionr   
isinstancer   
translatedr	   with_tracebackfake_tracebackfilenamelinenotb_nexttb_framef_coder   	f_globalsgetget_corresponding_lineno	tb_linenoappendreversed)	r	   _	exc_valuetbstacktemplater   fake_tbr    r&   H/var/www/html/olx_land/venv/lib/python3.10/site-packages/jinja2/debug.pyrewrite_traceback_stack   s:   


r(   r!   r"   r   r   c           	      C   s  |durt |jj}|dd ni }||| d}td|d  d |d}d}|durE|jjj}|d	kr7d
}n|drEd|dd }tj	dkrQ|j
|d}n t|j|j|j|j|j|j|j|j|j|j||j|j|j|j}z	t||| W dS  ty   t d j Y S w )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)   
r   zraise __jinja_exception__execr$   rootztop-level template codeblock_zblock    )      )co_name   )get_template_localsr   f_localspopcompiler   r3   
startswithr   version_inforeplacer   co_argcountco_kwonlyargcount
co_nlocalsco_stacksizeco_flagsco_code	co_constsco_namesco_varnamesco_filenameco_firstlineno	co_lnotabco_freevarsco_cellvarsr-   r   r   r   )	r!   r"   r   r   localsglobalscodelocationfunctionr&   r&   r'   r   L   sT   


r   real_localsc           
   	   C   s   |  d}|dur|  }ni }i }|  D ]9\}}|dr%|tu r&qz|dd\}}}t|}W n	 ty>   Y qw | |dd }	|	|k rQ||f||< q| D ]\}\}}|tu rg|	|d qV|||< qV|S )zlBased on the runtime locals, get the context that would be
    available at that point in the template.
    contextNl_r    r4   )r   )
r   get_allcopyitemsr9   r   splitint
ValueErrorr7   )
rO   ctxdatalocal_overridesnamevaluer    	depth_strdepth	cur_depthr&   r&   r'   r5      s.   

r5   )N)r   typingr   typesr   r   
exceptionsr   utilsr   r   TYPE_CHECKINGruntimer   Optionalstrr   r(   rW   r   MappingAnyDictr5   r&   r&   r&   r'   <module>   s,    >
.J