o |nh @sddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ej r/ddl m Z dd ejed efd d Zd edejededed ef ddZdejeejfd ejeejffddZdS)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]}||_|}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) r _ exc_valuetbstacktemplaterfake_tbrr&D/usr/local/bin/dhwp/env/lib/python3.10/site-packages/jinja2/debug.pyrewrite_traceback_stacks:         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_localspopcompilerr3 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 r4)r) rget_allcopyitemsr9rsplitint ValueErrorr7) rOctxdatalocal_overridesnamevaluer depth_strdepth cur_depthr&r&r'r5s.     r5)N)r typingrtypesrr exceptionsrutilsrr TYPE_CHECKINGruntimerOptionalstrrr(rWrMappingAnyDictr5r&r&r&r's,      > .J