Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_code.cpython-38.pyc
U

>��g�6�@s�dZddlZddlZddlZddlZddlZddlZzddlZWnek
rXdZYnXddl	m
Z
mZmZm
Z
dd�Zdd�Zdd	�ZGd
d�dej�Zdd
�ZGdd�dej�ZGdd�dej�Ze
dd��r|edk	�r|ejZe�dej�ZejZefe_eje_ej Z!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)a�This module includes tests of the code object representation.

>>> def f(x):
...     def g(y):
...         return x + y
...     return g
...

>>> dump(f.__code__)
name: f
argcount: 1
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('x', 'g')
cellvars: ('x',)
freevars: ()
nlocals: 2
flags: 3
consts: ('None', '<code object g>', "'f.<locals>.g'")

>>> dump(f(4).__code__)
name: g
argcount: 1
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('y',)
cellvars: ()
freevars: ('x',)
nlocals: 1
flags: 19
consts: ('None',)

>>> def h(x, y):
...     a = x + y
...     b = x - y
...     c = a * b
...     return c
...

>>> dump(h.__code__)
name: h
argcount: 2
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('x', 'y', 'a', 'b', 'c')
cellvars: ()
freevars: ()
nlocals: 5
flags: 67
consts: ('None',)

>>> def attrs(obj):
...     print(obj.attr1)
...     print(obj.attr2)
...     print(obj.attr3)

>>> dump(attrs.__code__)
name: attrs
argcount: 1
posonlyargcount: 0
kwonlyargcount: 0
names: ('print', 'attr1', 'attr2', 'attr3')
varnames: ('obj',)
cellvars: ()
freevars: ()
nlocals: 1
flags: 67
consts: ('None',)

>>> def optimize_away():
...     'doc string'
...     'not a docstring'
...     53
...     0x53

>>> dump(optimize_away.__code__)
name: optimize_away
argcount: 0
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ()
cellvars: ()
freevars: ()
nlocals: 0
flags: 67
consts: ("'doc string'", 'None')

>>> def keywordonly_args(a,b,*,k1):
...     return a,b,k1
...

>>> dump(keywordonly_args.__code__)
name: keywordonly_args
argcount: 2
posonlyargcount: 0
kwonlyargcount: 1
names: ()
varnames: ('a', 'b', 'k1')
cellvars: ()
freevars: ()
nlocals: 3
flags: 67
consts: ('None',)

>>> def posonly_args(a,b,/,c):
...     return a,b,c
...

>>> dump(posonly_args.__code__)
name: posonly_args
argcount: 3
posonlyargcount: 2
kwonlyargcount: 0
names: ()
varnames: ('a', 'b', 'c')
cellvars: ()
freevars: ()
nlocals: 3
flags: 67
consts: ('None',)

�N)�run_doctest�run_unittest�cpython_only�check_impl_detailccs4|D]*}t|�}|�d�r(d|jVq|VqdS)z.Yield a doctest-safe sequence of object reprs.z<code objectz<code object %s>N)�repr�
startswith�co_name)�tZelt�r�r�-/opt/cppython/lib/python3.8/test/test_code.py�consts�s

r
cCs<dD]}td|t|d|�f�qtdtt|j���dS)z1Print out a text representation of a code object.)
�nameZargcountZposonlyargcountZkwonlyargcount�namesZvarnamesZcellvarsZfreevarsZnlocals�flagsz%s: %sZco_zconsts:N)�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)z9A new code object with a __class__ cell added to freevarsr()�co_freevars)�replacer.)�crrr�new_code�sz1CodeTest.test_closure_injection.<locals>.new_codec	s@�|j�}|jrt��|�}|j}t||�|t�|||��dSr')�__code__r,�AssertionError�__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�srAr���zForeign getitem: 1)�typesr&�listrrr,�
cell_contentsZassertIs�assertFalser2�co_flags�inspectZ	CO_NOFREE�hexr")rr<rA�functionZ	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_stacksizerI�co_coder�co_names�co_varnamesr#rr$�	co_lnotabr.�co_cellvars)rrOr�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)NrBr��xrrrrO�sz#CodeTest.test_replace.<locals>.funccSsd}|S)NrCr)�yrrr�func2�sz$CodeTest.test_replace.<locals>.func2)rQr)rRr)rSr)rTr)rUrrI)r$�drVr)rW)ZmynamerX)r.)Zfreevar)rZ)Zcellvar)r#Znewfilename)rZnewnamerY)r�value)r2rIrJZCO_COROUTINErVrrXrYZsubTestr/r"r)rrOr9r`�code2rrbr1rrr�test_replace�s0�zCodeTest.test_replaceN)r>r?r@rr%rNr\rdrrrrr�s

$rcCs|t�d|ddd��kS)N�_rB���)�sys�intern)�srrr�
isinterned
srjc@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
rb�vrrr�
find_consts

zCodeConstsTest.find_constcCst|�s|�d|f�dS)NzString %r is not interned�rjrl�rrirrr�assertIsInternedszCodeConstsTest.assertIsInternedcCst|�r|�d|f�dS)NzString %r is internedrorprrr�assertIsNotInternedsz"CodeConstsTest.assertIsNotInternedcCs(tddd�}|�|jd�}|�|�dS)Nzres = "str_value"�?�exec�	str_value��compilernrrq�rrrmrrr�test_interned_string!sz#CodeConstsTest.test_interned_stringcCs,tddd�}|�|jd�}|�|d�dS)Nzres = ("str_value",)rsrt�rurrvrxrrr�test_interned_string_in_tuple'sz,CodeConstsTest.test_interned_string_in_tuplecCs4tddd�}|�|jtd��}|�t|�d�dS)Nzres = a in {"str_value"}rsrtrzr)rwrnr�	frozensetrqrrxrrr�!test_interned_string_in_frozenset-sz0CodeConstsTest.test_interned_string_in_frozensetcCsddd�}|�|��dS)NrucSs|Sr'r)�arrrr85sz6CodeConstsTest.test_interned_string_default.<locals>.f)ru)rq�rr8rrr�test_interned_string_default3s
z+CodeConstsTest.test_interned_string_defaultcCs(tddd�}|�|jd�}|�|�dS)Nzres = "str\0value!"rsrtz
strvalue!)rwrnrrrrxrrr�test_interned_string_with_null9sz-CodeConstsTest.test_interned_string_with_nullN)r>r?r@rnrqrrrryr{r}r�r�rrrrrks



rkc@seZdZdd�ZdS)�CodeWeakRefTestcsni}tdt�|�|d}~d�_�fdd�}t�|j|�}��t|���~��t|������j�dS)Nz
def f(): passr8Fcs
d�_dS)NT)�called)r9�rrr�callbackKsz,CodeWeakRefTest.test_basic.<locals>.callback)	rtr6r��weakref�refr2Z
assertTrue�boolrH)r�	namespacer8r�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�*ra)r��assertRaises�SystemError�SetExtra�
FREE_INDEX�ctypes�c_voidp�GetExtrarrrr�test_get_non_codeys��zCoExtra.test_get_non_codec	CsJ|��}|�tt|jtdt�d��|�t	|jtdt�d��d�dS)Nrar)
r�r�r�r�r2r�r�r�r"r�rrrr�test_bad_index�s���zCoExtra.test_bad_indexcCs.|��}t|jtt�d��~|�td�dS)Nra)r�r�r2r�r�r�r"r�rrrr�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�rb)rr8�extrarrr�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__r8�test)rr8r�r(rrr��s
z?CoExtra.test_free_different_thread.<locals>.ThreadTest.__init__cSs|`|j�td�dS)N��)r8r�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��	threading�Threadr�r2r�r�r��start�joinr"r�)rr8r��ttrrr�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�|�}	||�~|	�dks�t�dS)
NcSs|Sr'rr]rrrr8�sz-CoExtra.test_clean_stack_on_return.<locals>.f���Z	LOAD_FASTrrBZnfc@seZdZdS)z/CoExtra.test_clean_stack_on_return.<locals>.VarNr=rrrr�Var�sr�)r2rPrFrV�insert�opcodeZopmaprQrRrSrTrUrI�bytesrrWrXr#rr$rYr.rZ�__globals__r4r,r�r�r3)
rr8r9�ct�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�rrrkr�rr��appendr�r)�verboser�Ztestsrrr�	test_main�s


r��__main__)N).�__doc__rJrgr�Zunittestr�r�r��ImportErrorZtest.supportrrrrr
rrZTestCaserrjrkr�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>sP
	
i0
�h



F1le Man4ger