
    aM	                         d Z ddlZddlZd ZdZ	  ej
                         dk(  r e       Z[y# e$ r5Zej                  j                  dj                  e             Y dZ[[ydZ[ww xY w)zc
Taken verbatim from Jinja2.

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/debug.py#L267
    Nc                  X   ddl ddlm t        j                  d      rj
                  } nj                  }  G d dj                        }d| fdj                  |      fg|_	        t        t        d	      rU G d
 dj                        }dj                  |      fdj                  |      fd| fdj                  |      fg|_	         G d d|      dj                        fdj                  |      fdj                  fdj                  fg_	        fd}|S )zThis function implements a few ugly things so that we can patch the
    traceback objects.  The function returned allows resetting `tb_next` on
    any python traceback object.  Do not attempt to use this on non cpython
    interpreters
    r   N)TracebackTypePy_InitModule4_64c                       e Zd Zy"_init_ugly_crap.<locals>._PyObjectN__name__
__module____qualname__     -lib/python3.12/site-packages/tblib/cpython.py	_PyObjectr          r   r   	ob_refcntob_type
getobjectsc                       e Zd Zyr   r	   r   r   r   r   z"_init_ugly_crap.<locals>._PyObject$   s    r   _ob_next_ob_prevc                       e Zd Zy)#_init_ugly_crap.<locals>._TracebackNr	   r   r   r   
_Tracebackr   .   r   r   r   tb_nexttb_frametb_lasti	tb_linenoc                    t        |       r|t        |      st        d      j                  t        |             }| j                  9j                  t        | j                              }|xj
                  dz  c_        | j                               |_        yj                  t        |            }|xj
                  dz  c_        j                  |      |_        y)z0Set the tb_next attribute of a traceback object.Nz/tb_set_next arguments must be traceback objects   )
isinstance	TypeErrorfrom_addressidr   r   POINTERpointer)tbnextobjoldr   r   ctypess       r   tb_set_nextz$_init_ugly_crap.<locals>.tb_set_next8   s    2}-4<:dTaCbMNN%%bf-::!))"RZZ.9CMMQM<4&..46CK**2d84DNNaN ...CKr   )r+   typesr   hasattr	pythonapic_int64c_int	Structurer%   _fields_sys)_Py_ssize_tr   r,   r   r   r+   s      @@@r   _init_ugly_crapr6   
   s+    # v!45nnllF$$  
k"	FNN9-.I sL!	(( 	 	23	23+&y12	
	Y  
FNN:./	V^^I./	V\\"	fll#	J/ r   CPythonz*Failed to initialize cpython support: {!r})__doc__platformr4   r6   r,   python_implementation	Exceptionexcstderrwriteformatr   r   r   <module>r@      s}   
  
=@ O%x%%'94%'   OJJAHHMNNOs   . A(*A##A(