
    aM	                         d Z ddlZddlZd ZdZ	  ej                    dk    r
 e            Zn?# e$ r7Zej        	                    d
                    e                     Y dZ[ndZ[ww xY w[dS )zc
Taken verbatim from Jinja2.

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/debug.py#L267
    Nc                  f   ddl ddlm t          j        d          rj        } nj        }  G d dj                  }d| fd                    |          fg|_	        t          t          d	          r_ G d
 dj                  }d                    |          fd                    |          fd| fd                    |          fg|_	         G d d|          d                              fd                    |          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dS "_init_ugly_crap.<locals>._PyObjectN__name__
__module____qualname__     -lib/python3.11/site-packages/tblib/cpython.py	_PyObjectr              r   r   	ob_refcntob_type
getobjectsc                       e Zd ZdS r   r	   r   r   r   r   z"_init_ugly_crap.<locals>._PyObject$   s        Dr   _ob_next_ob_prevc                       e Zd ZdS )#_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                              t          |                     }| j        7                    t          | j                            }|xj        dz  c_        |$                                           |_        dS                     t          |                    }|xj        dz  c_                            |          |_        dS )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}-- 	O4<:dTaCbCb<MNNN%%bff--:!))"RZ..99CMMQMM<4&..4466CKKK**2d8844DNNaNN ....CKKKr   )r+   typesr   hasattr	pythonapic_int64c_int	Structurer%   _fields_sys)_Py_ssize_tr   r,   r   r   r+   s      @@@r   _init_ugly_crapr6   
   s    MMM###### v!455 #nl    F$    
k"	FNN9--.I sL!! 	
	 	 	 	 	( 	 	 	 	223	223+&y112	
	    Y    
FNN:../	V^^I../	V\"	fl#	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4%o'' O O OJAHHMMNNNNNNNNOOOs   / A+-A&&A+