U a$@sddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ej rfddl mZdejeed d d Zeejeeeed d dZejeejfejeejfdddZejdkreejeedddZnedkrJz 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}|dk r|jjtkr|j}qn|jjd}|dk r||j}t |||j |}||n |||j}qnd}t|D]}t||}q| |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#MC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-8gbwd15f\jinja2\debug.pyrewrite_traceback_stacks<          r%)rr rrr c Csv|dk r"t|jj}|ddni}|||d}td|dd|d}zd}|dk r|jjj}|d krpd }n|d rd |d d}g} ddddddddddd|fd|fdddddfD]Z} t| t r| | dqz | t |dt t| Wqtk rYqYqXqt| }Wntk r:YnXzt|||Wn$tk rptd jYSXdS)!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 ZargcountZposonlyargcountZkwonlyargcountZnlocalsZ stacksizeflagscodeZconstsnamesvarnamesrnameZ firstlinenoZlnotabZfreevarsZcellvarsZ linetableZco_)get_template_localsrf_localspopcompilerco_name startswithrtuplergetattrr rstrAttributeErrorr Exceptionr*rr r r) rr rrlocalsglobalsr.locationfunctionZ code_argsattrr#r#r$rLsd       r) real_localsr c Cs|d}|dk r |}ni}i}|D]x\}}|dr0|tkrLq0z|dd\}}}t|}Wntk rYq0YnX||dd} | |kr0||f||<q0|D]*\}\}}|tkr| |dq|||<q|S)zlBased on the runtime locals, get the context that would be available at that point in the template. contextNZl_rr2)r) rget_allcopyitemsr8rsplitint ValueErrorr5) rCctxdataZlocal_overridesr1valuerZ depth_strdepthZ cur_depthr#r#r$r3s*    r3))r rr cCs ||_|SNrr rr#r#r$rsrPyPycCs|SrRr#rTr#r#r$rscsfdd}tj||dS)Ncs$|jdkr|jddkrS|S)N__getattribute__rr)opnameargsZdelegate)oprSr#r$ controllersztb_set_next..controller)obj)tputilZ make_proxy)r rrZr#rSr$rs c@s*eZdZdejefdejfgZdS) _CTracebackZ PyObject_HEADrN) r' __module__ __qualname__ctypesc_byteobject __sizeof__ py_object_fields_r#r#r#r$r]sr]cCsbtt|}|jdk r:t|j}t|_tj||dk r^t|}tj|||_|SrR) r] from_addressidrr`rd pythonapiZ Py_DecRefZ Py_IncRef)r rZc_tbZ c_tb_nextr#r#r$rs      )N)!platformr typingr typesrr exceptionsrutilsrr TYPE_CHECKINGZruntimerOptionalr;rr%rJrMappingAnyDictr3 version_inforpython_implementationr\ ImportErrorr` Structurer]r#r#r#r$sP      > ^(,