3

U'íc.!ã@s€ddlZddlZddlZddlmZddlmZddlmZddl	m
Z
ddl	mZejrfddl
mZdejeed	œd
d„Zeejeeeedœd
d„Zejeejfejeejfdœdd„Zejdkræeejeedœdd„Zn–ejƒdkrJyddlZWn.ek
r.eejeedœdd„ZYnXeejeedœdd„Zn2ddlZGdd„dejƒZ eejeedœdd„ZdS)éN)ÚCodeType)Ú
TracebackTypeé)ÚTemplateSyntaxError)Ú
internal_code)Úmissing)ÚContext)ÚsourceÚreturnc	Cs
tjƒ\}}}tjt|ƒ}tjt|ƒ}t|tƒrf|jrfd|_||_	|j
dƒt|d|jp\d|j
ƒ}n|j}g}xn|dk	rÞ|jjtkrŽ|j}qr|jjjdƒ}|dk	rÌ|j|jƒ}t|||j|ƒ}|j|ƒn
|j|ƒ|j}qrWd}xt|ƒD]}t||ƒ}qîW|j
|ƒ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	<unknown>Z__jinja_template__)ÚsysÚexc_infoÚtÚcastÚ
BaseExceptionrÚ
isinstancerZ
translatedr	Úwith_tracebackÚfake_tracebackÚfilenameÚlinenoÚtb_nextÚtb_frameÚf_coderÚ	f_globalsÚgetZget_corresponding_linenoÚ	tb_linenoÚappendÚreversedÚtb_set_next)	r	Ú_Ú	exc_valueÚtbÚstackÚtemplaterZfake_tbr©r#ú./tmp/pip-build-gk9425m9/Jinja2/jinja2/debug.pyÚrewrite_traceback_stacks4



r%)rr rrr
c	Cs|dk	r"t|jjƒ}|jddƒni}|||dœ}td|dd|dƒ}d}|dk	rŠ|jjj}|d	krnd
}n|jdƒrŠd|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
rtjƒdjSXdS)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é)r-r.)Úget_template_localsrÚf_localsÚpopÚcompilerr/Ú
startswithrÚversion_infoÚreplacerÚco_argcountÚco_kwonlyargcountÚ
co_nlocalsÚco_stacksizeÚco_flagsÚco_codeÚ	co_constsÚco_namesÚco_varnamesÚco_filenameÚco_firstlinenoÚ	co_lnotabÚco_freevarsÚco_cellvarsr*rrr)	rr rrÚlocalsÚglobalsÚcodeÚlocationÚfunctionr#r#r$rLsL


r)Úreal_localsr
c
Csê|jdƒ}|dk	r |jƒjƒ}ni}i}x„|jƒD]x\}}|jdƒs2|tkrPq2y|jddƒ\}}}t|ƒ}Wntk
r„w2YnX|j|d	ƒd}	|	|kr2||f||<q2Wx6|jƒD]*\}\}}|tkrÚ|j	|dƒq¸|||<q¸W|S)
zlBased on the runtime locals, get the context that would be
    available at that point in the template.
    ÚcontextNZl_rr0rréÿÿÿÿ)rM)
rÚget_allÚcopyÚitemsr5rÚsplitÚintÚ
ValueErrorr3)
rKÚctxÚdataZlocal_overridesÚnameÚvaluerZ	depth_strÚdepthZ	cur_depthr#r#r$r1–s*
r1r-é)r rr
cCs
||_|S)N)r)r rr#r#r$rÄsrÚPyPycCs|S)Nr#)r rr#r#r$rÑscs‡fdd„}tj||dS)Ncs$|jdkr|jddkrˆS|jƒS)NÚ__getattribute__rr)ÚopnameÚargsZdelegate)Úop)rr#r$Ú
controllerÜsztb_set_next.<locals>.controller)Úobj)ÚtputilZ
make_proxy)r rr_r#)rr$rÙsc@s*eZdZdejeƒjƒfdejfgZdS)Ú_CTracebackZ
PyObject_HEADrN)	r'Ú
__module__Ú__qualname__ÚctypesÚc_byteÚobjectÚ
__sizeof__Ú	py_objectÚ_fields_r#r#r#r$rbêsrbcCsbtjt|ƒƒ}|jdk	r:tj|jƒ}tjƒ|_tjj|ƒ|dk	r^tj|ƒ}tjj|ƒ||_|S)N)	rbÚfrom_addressÚidrreriÚ	pythonapiZ	Py_DecRefZ	Py_IncRef)r rZc_tbZ	c_tb_nextr#r#r$ròs


)N)r-rY)!ÚplatformrÚtypingr
ÚtypesrrÚ
exceptionsrÚutilsrrZ
TYPE_CHECKINGZruntimerÚOptionalÚstrrr%rRrÚMappingZAnyÚDictr1r6rÚpython_implementationraÚImportErrorreÚ	Structurerbr#r#r#r$Ú<module>s8>H(,