a &gy!@sddlZddlmZddlmZddlmZddlmZddlm Z ddd Z d d Z d d Z ej dkrrddZnXerz ddlZWneyddZYq0ddZn"ddlZGdddejZddZdS)N)CodeType)TemplateSyntaxError)PYPY) internal_code)missingc Cst\}}}t|trd|jsdd|_||_z|dWntyJYn0t|d|j pZd|j }n|j }g}|dur|j j tvr|j }qn|j jd}|dur||j}t|||j |}||n |||j }qnd}t|D]}t||}q|||fS)aRewrite 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 Z__jinja_template__)sysexc_info isinstancerZ translatedsourcewith_tracebackAttributeErrorfake_tracebackfilenamelinenotb_nexttb_framef_coder f_globalsgetZget_corresponding_lineno tb_linenoappendreversed tb_set_next) r exc_type exc_valuetbstacktemplaterZfake_tbrr0/usr/lib/python3.9/site-packages/jinja2/debug.pyrewrite_traceback_stack s8        r!c Csf|dur"t|jj}|ddni}|||d}td|dd|d}zd}|dur|jjj}|d krpd }n|d rd |d d}g} ddddddddddd|fd|fdddddfD]P} t| t r| | dqz| t |d| Wqt y YqYq0qt | }Wnty,Yn0zt|||Wn"ty`td jYS0dS)!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" rzraise __jinja_exception__execrrootztop-level template codeZblock_z block "%s"ZargcountZposonlyargcountZkwonlyargcountZnlocalsZ stacksizeflagscodeZconstsnamesZvarnamesrnameZ firstlinenoZlnotabZfreevarsZcellvarsZ linetableZco_)get_template_localsrf_localspopcompilerco_name startswithr tuplergetattrr r Exceptionr& BaseExceptionrr r) rrrrlocalsglobalsr*locationfunctionZ code_argsattrrrr rLsd       rc Cs|d}|r|}ni}i}|D]v\}}|dr,|turHq,z|dd\}}}t|}Wnty|Yq,Yn0||dd}||kr,||f||<q,|D]*\}\}}|tur| |dq|||<q|S)zlBased on the runtime locals, get the context that would be available at that point in the template. contextZl__r-)rN) rZget_allcopyitemsr3rsplitint ValueErrorr0) Z real_localsctxdataZlocal_overridesr,valuer>depthZ cur_depthrrr r.s*     r.)cCs ||_|SNrrrrrr rsrcCs|SrKrrMrrr rscsfdd}tj||dS)Ncs$|jdkr|jddkrS|S)N__getattribute__rr)opnameargsZdelegate)oprLrr controllersztb_set_next..controller)obj)tputilZ make_proxy)rrrRrrLr rs c@s*eZdZdejefdejfgZdS) _CTracebackZ PyObject_HEADrN) r# __module__ __qualname__ctypesZc_byteobject __sizeof__ py_objectZ_fields_rrrr rUsrUcCsbtt|}|jdur:t|j}t|_tj||dur^t|}tj|||_|SrK) rUZ from_addressidrrXr[Z pythonapiZ Py_DecRefZ Py_IncRef)rrZc_tbZ c_tb_nextrrr rs      )N)rtypesrrZ_compatrZutilsrrr!rr. version_inforrT ImportErrorrXZ StructurerUrrrr s&      B\,