o
    4c$                  
   @   s  d dl Z 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r3d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ejdkr|dedeje d
efddZdS e  dkrzd dlZW n ey   dedeje d
efddZY dS w dedeje d
efddZdS d dlZG dd dejZ dedeje d
e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 ]}t||}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tb_set_next)	r	   _	exc_valuetbstacktemplater   fake_tbr    r'   B/var/www/html/gps/gps/lib/python3.10/site-packages/jinja2/debug.pyrewrite_traceback_stack   s8   


r)   r"   r#   r   r   c                 C   sb  |durt |jj}|dd ni }||| d}td|d  d |d}zhd}|durF|jjj}|d	kr8d
}n|drFd|dd }g }	ddddddddddd|fd|fdddddfD ](}
t|
t	rn|	
|
d  q_z|	
t|dtt|
  W q_ ty   Y q_w t|	 }W n	 ty   Y nw 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    argcountposonlyargcountkwonlyargcountnlocals	stacksizeflagscodeconstsnamesvarnamesr   namefirstlinenolnotabfreevarscellvars	linetableco_   )get_template_localsr   f_localspopcompiler   co_name
startswithr   tupler   getattrr   r   strAttributeErrorr   	Exceptionr.   r   r   r   r   )r"   r#   r   r   localsglobalsr8   locationfunction	code_argsattrr'   r'   r(   r   L   sj   


 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!   rC   )r   )
r   get_allcopyitemsrI   r   splitint
ValueErrorrF   )
rU   ctxdatalocal_overridesr<   valuer!   	depth_strdepth	cur_depthr'   r'   r(   rD      s.   

rD   )      r   c                 C   s
   || _ | S Nr   r#   r   r'   r'   r(   r       s   r    PyPyc                 C   s   | S rh   r'   rj   r'   r'   r(   r       s   c                    s    fdd}t j|| dS )Nc                    s$   | j dkr| jd dkr S |  S )N__getattribute__r   r   )opnameargsdelegate)opri   r'   r(   
controller   s   ztb_set_next.<locals>.controller)obj)tputil
make_proxy)r#   r   rq   r'   ri   r(   r       s   c                   @   s*   e Zd Zdeje   fdejfgZdS )_CTracebackPyObject_HEADr   N)	r+   
__module____qualname__ctypesc_byteobject
__sizeof__	py_object_fields_r'   r'   r'   r(   ru      s    ru   c                 C   sb   t t| }| jd urt| j}t |_tj| |d ur/t|}tj| ||_| S rh   )	ru   from_addressidr   ry   r}   	pythonapi	Py_DecRef	Py_IncRef)r#   r   c_tb	c_tb_nextr'   r'   r(   r      s   


rh   )!platformr   typingr   typesr   r   
exceptionsr   utilsr   r   TYPE_CHECKINGruntimer   OptionalrL   r   r)   r]   r   MappingAnyDictrD   version_infor    python_implementationrs   ImportErrorry   	Structureru   r'   r'   r'   r(   <module>   sv    =
*^
,
