Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.146.221.131
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_code.cpython-310.pyc
o

`b�2�@s�dZddlZddlZddlZddlZddlZzddlZWney'dZYnwddlm	Z	m
Z
mZmZm
Z
dd�Zdd�Zdd	�ZGd
d�dej�Zdd
�ZGdd�dej�ZGdd�dej�Zedd�r�edur�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-dkr�e,�dSdS)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_detail�
gc_collectccs6�|D]}t|�}|�d�rd|jVq|VqdS)z.Yield a doctest-safe sequence of object reprs.z<code objectz<code object %s>N)�repr�
startswith�co_name)�t�elt�r�r
�7/usr/local/python-3.10/lib/python3.10/test/test_code.py�consts�s�
�rcCs<dD]}td|t|d|�f�qtdtt|j���dS)z1Print out a text representation of a code object.)
�nameZargcountZposonlyargcountZkwonlyargcount�names�varnamesZcellvarsZfreevarsZnlocals�flagsz%s: %sZco_zconsts:N)�print�getattr�tupler�	co_consts)�co�attrr
r
r�dump�srcCsdt��|���S)NzForeign getitem: )�super�__getitem__)�self�ir
r
r�external_getitem�src@s<eZdZedd��Zedd��Zdd�Zdd�Zd	d
�ZdS)�CodeTestcCsDddl}|�ddd�}|�|jd�|�|jd�|�|jd�dS)Nr�filename�funcname�)�	_testcapiZ
code_newempty�assertEqual�co_filenamer	�co_firstlineno)rr$rr
r
r�
test_newempty�s
zCodeTest.test_newemptycs�ddlm�dd��dd�����fdd�}Gd	d
�d
t�}||dt�|j}|jdj}|�||�|�|j	j
tj@t
|j	j
��|gd��}|�|dd
�dS)Nr)�FunctionTypecs�fdd�jS)Ncs�S�Nr
r
��	__class__r
r�<lambda>��zICodeTest.test_closure_injection.<locals>.create_closure.<locals>.<lambda>)�__closure__r+r
r+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)�replacer1)�cr
r
r�new_code�sz1CodeTest.test_closure_injection.<locals>.new_codec	s@�|j�}|jr
J��|�}|j}t||�|t�|||��dSr*)�__code__r/�__defaults__�setattr�globals)�clsr�f�codeZclosure�defaults�r)r0r4r
r�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__r
r
r
r�List�srBr)���zForeign getitem: 1)�typesr)�listrrr/�
cell_contentsZassertIs�assertFalser5�co_flags�inspectZ	CO_NOFREE�hexr%)rr>rB�functionZ	class_ref�objr
r=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�dS)NcS�dSr*r
r
r
r
r�func�r.z'CodeTest.test_constructor.<locals>.func)r5�type�co_argcount�co_posonlyargcount�co_kwonlyargcount�
co_nlocals�co_stacksizerJ�co_coder�co_names�co_varnamesr&r	r'�	co_lnotabr1�co_cellvars)rrQr�CodeTyper
r
r�test_constructor�s(�zCodeTest.test_constructorcCs�dd�}|j}dd�}|j}ddddd	d
|jtjBfdd|jfd
|jfdd|jfddddd|jffD].\}}|j||d��|j	di||i��}|�
t||�|�Wd�n1s[wYq2dS)NcS�d}|S)NrCr
)�xr
r
rrQ��z#CodeTest.test_replace.<locals>.funccSr_)NrDr
)�yr
r
r�func2�raz$CodeTest.test_replace.<locals>.func2)rSr)rTr)rUr)rVr)rWrrJ)r'�drXr)rY)ZmynamerZ)r1)Zfreevar)r\)Zcellvar)r&Znewfilename)r	Znewname�co_linetable)r�valuer
)r5rJrKZCO_COROUTINErXrrZreZsubTestr2r%r)rrQr;rc�code2rrfr4r
r
r�test_replace�s6����zCodeTest.test_replacecCs2dd�}|jjdd�}}|�t|���g�dS)NcSrPr*r
r
r
r
rrQ�z+CodeTest.test_empty_linetable.<locals>.func�)re)r5r2r%rG�co_lines)rrQr4r;r
r
r�test_empty_linetableszCodeTest.test_empty_linetableN)	r?r@rArr(rOr^rhrlr
r
r
rr �s

$"r cCs|t�d|ddd��uS)N�_rC���)�sys�intern)�sr
r
r�
isinternedsrrc@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)rrrf�vr
r
r�
find_consts�zCodeConstsTest.find_constcCs t|�s|�d|f�dSdS)NzString %r is not interned�rrrt�rrqr
r
r�assertIsInterned��zCodeConstsTest.assertIsInternedcCs t|�r|�d|f�dSdS)NzString %r is internedrwrxr
r
r�assertIsNotInterned"rzz"CodeConstsTest.assertIsNotInternedcC�(tddd�}|�|jd�}|�|�dS)Nzres = "str_value"�?�exec�	str_value��compilervrry�rrrur
r
r�test_interned_string&�z#CodeConstsTest.test_interned_stringcCs,tddd�}|�|jd�}|�|d�dS)Nzres = ("str_value",)r}r~�rrr�r�r
r
r�test_interned_string_in_tuple,sz,CodeConstsTest.test_interned_string_in_tuplecCs4tddd�}|�|jtd��}|�t|�d�dS)Nzres = a in {"str_value"}r}r~r�r)r�rvr�	frozensetryrr�r
r
r�!test_interned_string_in_frozenset2sz0CodeConstsTest.test_interned_string_in_frozensetcCsddd�}|�|��dS)NrcSs|Sr*r
)�ar
r
rr::riz6CodeConstsTest.test_interned_string_default.<locals>.fr�)ry�rr:r
r
r�test_interned_string_default8s
z+CodeConstsTest.test_interned_string_defaultcCr|)Nzres = "str\0value!"r}r~z
strvalue!)r�rvrr{r�r
r
r�test_interned_string_with_null>r�z-CodeConstsTest.test_interned_string_with_nullN)r?r@rArvryr{rr�r�r�r�r�r
r
r
rrss



rsc@seZdZdd�ZdS)�CodeWeakRefTestcsti}tdt�|�|d}~d�_�fdd�}t�|j|�}��t|���~t���	t|������j�dS)Nz
def f(): passr:Fcs
d�_dS)NT)�called)r;�rr
r�callbackPs
z,CodeWeakRefTest.test_basic.<locals>.callback)
r~r8r��weakref�refr5Z
assertTrue�boolrrI)r�	namespacer:r�Zcoderefr
r�r�
test_basicGszCodeWeakRefTest.test_basicN)r?r@rAr�r
r
r
rr�Esr�T�ZcpythoncCs|adSr*)�
LAST_FREED)Zptrr
r
r�myfreeqsr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�CoExtracCstd�S)Nz	lambda:42)�evalr�r
r
r�get_funcyszCoExtra.get_funcc	Cs<|��}|�ttdtt�d��|�ttdtt�d��dS)N�*rd)r��assertRaises�SystemError�SetExtra�
FREE_INDEX�ctypes�c_voidp�GetExtrar�r
r
r�test_get_non_codes��zCoExtra.test_get_non_codec	CsJ|��}|�tt|jtdt�d��|�t	|jtdt�d��d�dS)Nrdr)
r�r�r�r�r5r�r�r�r%r�r�r
r
r�test_bad_index�s���zCoExtra.test_bad_indexcCs.|��}t|jtt�d��~|�td�dS)Nrd)r�r�r5r�r�r�r%r�r�r
r
r�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�r5r�r%r�r�rf)rr:�extrar
r
r�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__r:�test)rr:r�r+r
rr��s

z?CoExtra.test_free_different_thread.<locals>.ThreadTest.__init__cSs|`|j�td�dS)N��)r:r�r%r�r�r
r
r�run�sz:CoExtra.test_free_different_thread.<locals>.ThreadTest.run)r?r@rAr�r��
__classcell__r
r
r+r�
ThreadTest�sr�r�)r��	threading�Threadr�r5r�r�r��start�joinr%r�)rr:r��ttr
r
r�test_free_different_thread�s	
z"CoExtra.test_free_different_threadN)	r?r@rAr�r�r�r�r�r�r
r
r
rr�xs	r�cCsHddlm}t||�tttg}tdd�rtdur|�t	�t
|�dS)Nr)�	test_codeTr�)r�r�rr rsr�rr��appendr�r)�verboser�Ztestsr
r
r�	test_main�s


r��__main__r*).�__doc__rKror�Zunittestr�r��ImportErrorZtest.supportrrrrrrrrZTestCaser rrrsr�Z	pythonapi�pyZ	CFUNCTYPEr�ZfreefuncZ_PyEval_RequestCodeExtraIndexZRequestCodeExtraIndex�argtypesZ	c_ssize_tZrestypeZ_PyCode_SetExtrar�Z	py_objectZc_intZ_PyCode_GetExtrar�ZPOINTERr�r�Z	FREE_FUNCr�r�r�r?r
r
r
r�<module>sT�	
o0
�
D
�
© 2025 GrazzMean