Your IP : 216.73.217.129


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_code.cpython-38.opt-2.pyc

U

i�f�6�@s�ddlZddlZddlZddlZddlZddlZzddlZWnek
rTdZYnXddlm	Z	m
Z
mZmZdd�Z
dd�Zdd�ZGd	d
�d
ej�Zdd�ZGd
d�dej�ZGdd�dej�Zedd��rxedk	�rxejZe�dej�ZejZefe_eje_ejZ ej!ejejfe _ej"e _ej#Z$ej!eje�%ej�fe$_ej"e$_da&dd�Z'ee'�Z(ee(�Z)Gdd�dej�Z*ddd�Z+e,dk�r�e+�dS)�N)�run_doctest�run_unittest�cpython_only�check_impl_detailccs4|D]*}t|�}|�d�r(d|jVq|VqdS)Nz<code objectz<code object %s>)�repr�
startswith�co_name)�tZelt�r�r�3/opt/alt/python38/lib64/python3.8/test/test_code.py�consts�s

r
cCs<dD]}td|t|d|�f�qtdtt|j���dS)N)
�nameZargcountZposonlyargcountZkwonlyargcount�namesZvarnamesZcellvarsZfreevarsZnlocals�flagsz%s: %sZco_zconsts:)�print�getattr�tupler
�	co_consts)�co�attrrrr�dump�srcCsdt��|���S)NzForeign getitem: )�super�__getitem__)�self�irrr�external_getitem�src@s4eZdZedd��Zedd��Zdd�Zdd�Zd	S)
�CodeTestcCsDddl}|�ddd�}|�|jd�|�|jd�|�|jd�dS)Nr�filename�funcname�)�	_testcapiZ
code_newempty�assertEqual�co_filenamer�co_firstlineno)rr!rrrr�
test_newempty�s
zCodeTest.test_newemptycs�ddlm�dd��dd�����fdd�}Gd	d
�d
t�}||dt�|j}|jdj}|�||�|�|j	j
tj@t
|j	j
��|dd
dg�}|�|dd�dS)Nr)�FunctionTypecs�fdd�jS)Ncs�S�Nrr��	__class__rr�<lambda>��zICodeTest.test_closure_injection.<locals>.create_closure.<locals>.<lambda>)�__closure__r(rr(r�create_closure�sz7CodeTest.test_closure_injection.<locals>.create_closurecSs|j|jdd�S)Nr()�co_freevars)�replacer.)�crrr�new_code�sz1CodeTest.test_closure_injection.<locals>.new_codec	s6�|j�}�|�}|j}t||�|t�|||��dSr')�__code__�__defaults__�setattr�globals)�clsr�f�codeZclosure�defaults�r&r-r1rr�add_foreign_method�s
z;CodeTest.test_closure_injection.<locals>.add_foreign_methodc@seZdZdS)z-CodeTest.test_closure_injection.<locals>.ListN��__name__�
__module__�__qualname__rrrr�List�sr@r���zForeign getitem: 1)�typesr&�listrrr,�
cell_contentsZassertIs�assertFalser2�co_flags�inspectZ	CO_NOFREE�hexr")rr;r@ZfunctionZ	class_ref�objrr:r�test_closure_injection�s
�zCodeTest.test_closure_injectioncCs\dd�}|j}t|�}||j|j|j|j|j|j|j|j	|j
|j|j|j
|j|j|j|j�S)NcSsdSr'rrrrr�func�r+z'CodeTest.test_constructor.<locals>.func)r2�type�co_argcount�co_posonlyargcount�co_kwonlyargcount�
co_nlocals�co_stacksizerH�co_coder�co_names�co_varnamesr#rr$�	co_lnotabr.�co_cellvars)rrMr�CodeTyperrr�test_constructor�s(�zCodeTest.test_constructorcCs�dd�}|j}dd�}|j}ddddd	d
|jtjBfdd|jfd
|jfdd|jfddddd|jffD]D\}}|j||d��(|j	f||i�}|�
t||�|�W5QRXqddS)NcSsd}|S)NrAr��xrrrrM�sz#CodeTest.test_replace.<locals>.funccSsd}|S)NrBr)�yrrr�func2�sz$CodeTest.test_replace.<locals>.func2)rOr)rPr)rQr)rRr)rSrrH)r$�drTr)rU)ZmynamerV)r.)Zfreevar)rX)Zcellvar)r#Znewfilename)rZnewnamerW)r�value)r2rHrIZCO_COROUTINErTrrVrWZsubTestr/r"r)rrMr8r^�code2rr`r1rrr�test_replace�s0�zCodeTest.test_replaceN)r=r>r?rr%rLrZrbrrrrr�s

$rcCs|t�d|ddd��kS)N�_rA���)�sys�intern)�srrr�
isinterned
srhc@s`eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Zedd��Z	ed
d��Z
edd��ZdS)�CodeConstsTestcCs4|D]}||kr|Sq|�||�|�d�dS)NzShould never be reached)ZassertIn�fail)rr
r`�vrrr�
find_consts

zCodeConstsTest.find_constcCst|�s|�d|f�dS)NzString %r is not interned�rhrj�rrgrrr�assertIsInternedszCodeConstsTest.assertIsInternedcCst|�r|�d|f�dS)NzString %r is internedrmrnrrr�assertIsNotInternedsz"CodeConstsTest.assertIsNotInternedcCs(tddd�}|�|jd�}|�|�dS)Nzres = "str_value"�?�exec�	str_value��compilerlrro�rrrkrrr�test_interned_string!sz#CodeConstsTest.test_interned_stringcCs,tddd�}|�|jd�}|�|d�dS)Nzres = ("str_value",)rqrr�rsrrtrvrrr�test_interned_string_in_tuple'sz,CodeConstsTest.test_interned_string_in_tuplecCs4tddd�}|�|jtd��}|�t|�d�dS)Nzres = a in {"str_value"}rqrrrxr)rurlr�	frozensetrorrvrrr�!test_interned_string_in_frozenset-sz0CodeConstsTest.test_interned_string_in_frozensetcCsddd�}|�|��dS)NrscSs|Sr'r)�arrrr75sz6CodeConstsTest.test_interned_string_default.<locals>.f)rs)ro�rr7rrr�test_interned_string_default3s
z+CodeConstsTest.test_interned_string_defaultcCs(tddd�}|�|jd�}|�|�dS)Nzres = "str\0value!"rqrrz
strvalue!)rurlrrprvrrr�test_interned_string_with_null9sz-CodeConstsTest.test_interned_string_with_nullN)r=r>r?rlrorprrwryr{r~rrrrrris



ric@seZdZdd�ZdS)�CodeWeakRefTestcsni}tdt�|�|d}~d�_�fdd�}t�|j|�}��t|���~��t|������j�dS)Nz
def f(): passr7Fcs
d�_dS)NT)�called)r8�rrr�callbackKsz,CodeWeakRefTest.test_basic.<locals>.callback)	rrr5r��weakref�refr2Z
assertTrue�boolrG)r�	namespacer7r�Zcoderefrr�r�
test_basicBszCodeWeakRefTest.test_basicN)r=r>r?r�rrrrr�@sr�T�ZcpythoncCs|adSr')�
LAST_FREED)Zptrrrr�myfreeksr�c@sHeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dS)�CoExtracCstd�S)Nz	lambda:42)�evalr�rrr�get_funcsszCoExtra.get_funcc	Cs<|��}|�ttdtt�d��|�ttdtt�d��dS)N�*r_)r��assertRaises�SystemError�SetExtra�
FREE_INDEX�ctypes�c_voidp�GetExtrar}rrr�test_get_non_codeys��zCoExtra.test_get_non_codec	CsJ|��}|�tt|jtdt�d��|�t	|jtdt�d��d�dS)Nr_r)
r�r�r�r�r2r�r�r�r"r�r}rrr�test_bad_index�s���zCoExtra.test_bad_indexcCs.|��}t|jtt�d��~|�td�dS)Nr_)r�r�r2r�r�r�r"r�r}rrr�test_free_called�szCoExtra.test_free_calledcCsn|��}t��}t|jtt�d��t|jtt�d��|�td�t��}t|jt|�|�|j	d�~dS)N��i,)
r�r�r�r�r2r�r"r�r�r`)rr7Zextrarrr�test_get_set�szCoExtra.test_get_setcCsZ|��}Gdd�dtj�}t|jtt�d��|||�}~|��|�	�|�
td�dS)Ncs$eZdZ�fdd�Zdd�Z�ZS)z6CoExtra.test_free_different_thread.<locals>.ThreadTestcst���||_||_dSr')r�__init__r7�test)rr7r�r(rrr��s
z?CoExtra.test_free_different_thread.<locals>.ThreadTest.__init__cSs|`|j�td�dS)N��)r7r�r"r�r�rrr�run�sz:CoExtra.test_free_different_thread.<locals>.ThreadTest.run)r=r>r?r�r��
__classcell__rrr(r�
ThreadTest�sr�r�)r��	threadingZThreadr�r2r�r�r��start�joinr"r�)rr7r�Zttrrr�test_free_different_thread�s	
z"CoExtra.test_free_different_threadc
Cs�dd�}|j}t|j�}t|j�}|�dtjd�|�dd�||j|j|j	|j
|jd|jt
|�|j|j|j|j|j|j|j|j|j�}t|�||jd|j|j�}Gdd	�d	�}|�}t�|�}	||�~dS)
NcSs|Sr'rr[rrrr7�sz-CoExtra.test_clean_stack_on_return.<locals>.f���Z	LOAD_FASTrrAZnfc@seZdZdS)z/CoExtra.test_clean_stack_on_return.<locals>.VarNr<rrrr�Var�sr�)r2rNrErT�insert�opcodeZopmaprOrPrQrRrSrH�bytesrrUrVr#rr$rWr.rX�__globals__r3r,r�r�)
rr7r8Zct�bytecoder0Znew_functionr�Z
the_object�varrrr�test_clean_stack_on_return�s:


�
z"CoExtra.test_clean_stack_on_returnN)r=r>r?r�r�r�r�r�r�rr�rrrrr�rs	r�cCsHddlm}t||�tttg}tdd�r<tdk	r<|�t	�t
|�dS)Nr)�	test_codeTr�)r�r�rrrir�rr��appendr�r)�verboser�Ztestsrrr�	test_main�s


r��__main__)N)-rIrer�Zunittestr�r�r��ImportErrorZtest.supportrrrrr
rrZTestCaserrhrir�Z	pythonapi�pyZ	CFUNCTYPEr�ZfreefuncZ_PyEval_RequestCodeExtraIndexZRequestCodeExtraIndexZargtypesZ	c_ssize_tZrestypeZ_PyCode_SetExtrar�Z	py_objectZc_intZ_PyCode_GetExtrar�ZPOINTERr�r�Z	FREE_FUNCr�r�r�r=rrrr�<module>�sN
	
i0
�h