B Fa.!@sddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ej rfddl mZdejeed d d Zeejeeeed d dZejeejfejeejfdddZejdkreejeedddZnedkrJy ddlZWn.ek r.eejeedddZYnXeejeedddZn2ddlZGdddejZ eejeedddZdS)N)CodeType) TracebackType)TemplateSyntaxError) internal_code)missing)Context)sourcereturnc Cst\}}}tt|}tt|}t|trd|jsdd|_||_ | dt |d|j pZd|j }n|j}g}xn|dk r|jjtkr|j}qp|jjd}|dk r||j}t |||j |}||n |||j}qpWd}xt|D]}t||}qW| |S)axRewrite 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 Z__jinja_template__)sysexc_infotcast BaseExceptionr isinstancerZ translatedr with_tracebackfake_tracebackfilenamelinenotb_nexttb_framef_coder f_globalsgetZget_corresponding_lineno tb_linenoappendreversed tb_set_next) r _ exc_valuetbstacktemplaterZfake_tbrr#=/opt/alt/python37/lib/python3.7/site-packages/jinja2/debug.pyrewrite_traceback_stacks4          r%)rr rrr c Cs|dk r"t|jj}|ddni}|||d}td|dd|d}d}|dk r|jjj}|d krnd }n|d rd |d d}tj dkr|j |d}n@t |j |j |j|j|j|j|j|j|j|j||j|j|j|j}yt|||Wn tk rtdjSXdS)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__execr"rootztop-level template codeZblock_zblock ))co_name)get_template_localsrf_localspopcompilerr/ startswithr version_inforeplacer co_argcountco_kwonlyargcount co_nlocals co_stacksizeco_flagsco_code co_constsco_names co_varnames co_filenameco_firstlineno co_lnotab co_freevars co_cellvarsr*rr r) rr rrlocalsglobalscodelocationfunctionr#r#r$rLsL    r) real_localsr c Cs|d}|dk r |}ni}i}x|D]v\}}|dr2|tkrNq2y|dd\}}}t|}Wntk rw2YnX||dd} | |kr2||f||<q2Wx6|D]*\}\}}|tkr| |dq|||<qW|S)zlBased on the runtime locals, get the context that would be available at that point in the template. contextNZl_rr0)r) rget_allcopyitemsr5rsplitint ValueErrorr3) rKctxdataZlocal_overridesnamevaluerZ depth_strdepthZ cur_depthr#r#r$r1s*   r1)r-)r rr cCs ||_|S)N)r)r rr#r#r$rsrPyPycCs|S)Nr#)r rr#r#r$rscsfdd}tj||dS)Ncs$|jdkr|jddkrS|S)N__getattribute__rr)opnameargsZdelegate)op)rr#r$ controllersztb_set_next..controller)obj)tputilZ make_proxy)r rr_r#)rr$rs c@s*eZdZdejefdejfgZdS) _CTracebackZ PyObject_HEADrN) r' __module__ __qualname__ctypesc_byteobject __sizeof__ py_object_fields_r#r#r#r$rbsrbcCsbtt|}|jdk r:t|j}t|_tj||dk r^t|}tj|||_|S)N) rb from_addressidrreri pythonapiZ Py_DecRefZ Py_IncRef)r rZc_tbZ c_tb_nextr#r#r$rs      )N)!platformr typingr typesrr exceptionsrutilsrr TYPE_CHECKINGZruntimerOptionalstrrr%rRrMappingAnyDictr1r6rpython_implementationra ImportErrorre Structurerbr#r#r#r$s8      >H(,