o Fa.! @sddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ej r3ddl mZd d ejed efd d Zd edejededed ef ddZdejeejfd ejeejffddZejdkr|dedejed efddZdSedkrzddlZWneydedejed efddZYdSwdedejed efddZdSddlZGdddejZ dedejed efddZdS)!N)CodeType) TracebackType)TemplateSyntaxError) internal_code)missing)Contextsourcereturnc Cst\}}}tt|}tt|}t|tr2|js2d|_||_ | dt |d|j p-d|j }n|j}g}|durp|jjtvrE|j}q7|jjd}|durd||j}t |||j |}||n|||j}|dus;d}t|D]}t||}qv| |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 __jinja_template__)sysexc_infotcast BaseExceptionr isinstancer translatedr with_tracebackfake_tracebackfilenamelinenotb_nexttb_framef_coder f_globalsgetget_corresponding_lineno tb_linenoappendreversed tb_set_next) r _ exc_valuetbstacktemplaterfake_tbrr'./usr/lib/python3/dist-packages/jinja2/debug.pyrewrite_traceback_stacks8          r)r"r#rrc Cs|durt|jj}|ddni}|||d}td|dd|d}d}|durE|jjj}|d kr7d }n|d rEd |d d}tj dkrQ|j |d}n t |j |j |j|j|j|j|j|j|j|j||j|j|j|j}z t|||WdStytdjYSw)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 codeblock_zblock ))co_name)get_template_localsrf_localspopcompilerr4 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) r"r#rrlocalsglobalscodelocationfunctionr'r'r(rLsT     r real_localsc Cs|d}|dur|}ni}i}|D]9\}}|dr%|tur&qz|dd\}}}t|}Wn ty>Yqw||dd} | |krQ||f||<q|D]\}\}}|turg| |dqV|||<qV|S)zlBased on the runtime locals, get the context that would be available at that point in the template. contextNl_r!r5)r) rget_allcopyitemsr:rsplitint ValueErrorr8) rPctxdatalocal_overridesnamevaluer! depth_strdepth cur_depthr'r'r(r6s.     r6)r2rcCs ||_|SNrr#rr'r'r(r sr PyPycCs|Srcr'rer'r'r(r scsfdd}tj||dS)Ncs$|jdkr|jddkrS|S)N__getattribute__rr)opnameargsdelegate)oprdr'r( controllersztb_set_next..controller)obj)tputil make_proxy)r#rrlr'rdr(r s c@s*eZdZdejefdejfgZdS) _CTraceback PyObject_HEADrN) r+ __module__ __qualname__ctypesc_byteobject __sizeof__ py_object_fields_r'r'r'r(rpsrpcCsbtt|}|jdurt|j}t|_tj||dur/t|}tj|||_|Src) rp from_addressidrrtrx pythonapi Py_DecRef Py_IncRef)r#rc_tb c_tb_nextr'r'r(r s      rc)!platformr typingrtypesrr exceptionsrutilsrr TYPE_CHECKINGruntimerOptionalstrrr)rXrMappingAnyDictr6r;r python_implementationrn ImportErrorrt Structurerpr'r'r'r(sv      = *J ,