HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_code.cpython-37.pyc
B

��g�)�@s�dZddlZddlZddlZddlZddlZyddlZWnek
rPdZYnXddlm	Z	m
Z
mZmZdd�Z
dd�Zdd	�ZGd
d�dej�Zdd
�ZGdd�dej�ZGdd�dej�Zedd��rtedk	�rtejZe�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)a7This 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
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
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
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
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
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
kwonlyargcount: 1
names: ()
varnames: ('a', 'b', 'k1')
cellvars: ()
freevars: ()
nlocals: 3
flags: 67
consts: ('None',)

�N)�run_doctest�run_unittest�cpython_only�check_impl_detailccs8x2|D]*}t|�}|�d�r*d|jVq|VqWdS)z.Yield a doctest-safe sequence of object reprs.z<code objectz<code object %s>N)�repr�
startswith�co_name)�tZelt�r�r�*/usr/local/lib/python3.7/test/test_code.py�constsvs


r
cCs@x&dD]}td|t|d|�f�qWtdtt|j���dS)z1Print out a text representation of a code object.)	�nameZargcountZkwonlyargcount�namesZvarnamesZcellvarsZfreevarsZnlocals�flagsz%s: %sZco_zconsts:N)�print�getattr�tupler
�	co_consts)�co�attrrrr�dumps
rcCsdt��|���S)NzForeign getitem: )�super�__getitem__)�self�irrr�external_getitem�src@s$eZdZedd��Zedd��ZdS)�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�m�dd���fdd�����fdd�}Gd	d
�d
t�}||dt�|j}|jdj}|�||�|�	|j
jtj
@t|j
j��|dd
dg�}|�|dd�dS)Nr)�FunctionType�CodeTypecs�fdd�jS)Ncs�S)Nrr)�	__class__rr�<lambda>��zICodeTest.test_closure_injection.<locals>.create_closure.<locals>.<lambda>)�__closure__)r(r)r(r�create_closure�sz7CodeTest.test_closure_injection.<locals>.create_closurecsF�|j|j|j|j|j|j|j|j|j|j	|j
|j|j|j
d|j�S)z9A new code object with a __class__ cell added to freevars)r()�co_argcount�co_kwonlyargcount�
co_nlocals�co_stacksize�co_flags�co_coder�co_names�co_varnamesr#rr$�	co_lnotab�co_freevars�co_cellvars)�c)r'rr�new_code�s
z1CodeTest.test_closure_injection.<locals>.new_codec	s@�|j�}|jrt��|�}|j}t||�|t�|||��dS)N)�__code__r+�AssertionError�__defaults__�setattr�globals)�clsr�f�codeZclosure�defaults)r&r,r9rr�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�srGr���zForeign getitem: 1)�typesr&r'�listrrr+�
cell_contentsZassertIs�assertFalser:r1�inspectZ	CO_NOFREE�hexr")rrCrGZfunctionZ	class_ref�objr)r'r&r,r9r�test_closure_injection�szCodeTest.test_closure_injectionN)rDrErFrr%rRrrrrr�srcCs|t�d|ddd��kS)N�_rH���)�sys�intern)�srrr�
isinterned�srXc@s`eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Zedd��Z	ed
d��Z
edd��ZdS)�CodeConstsTestcCs4x|D]}||kr|SqW|�||�|�d�dS)NzShould never be reached)ZassertIn�fail)rr
�value�vrrr�
find_const�s

zCodeConstsTest.find_constcCst|�s|�d|f�dS)NzString %r is not interned)rXrZ)rrWrrr�assertIsInterned�szCodeConstsTest.assertIsInternedcCst|�r|�d|f�dS)NzString %r is interned)rXrZ)rrWrrr�assertIsNotInterned�sz"CodeConstsTest.assertIsNotInternedcCs(tddd�}|�|jd�}|�|�dS)Nzres = "str_value"�?�exec�	str_value)�compiler]rr^)rrr\rrr�test_interned_string�sz#CodeConstsTest.test_interned_stringcCs,tddd�}|�|jd�}|�|d�dS)Nzres = ("str_value",)r`ra)rbr)rcr]rr^)rrr\rrr�test_interned_string_in_tuple�sz,CodeConstsTest.test_interned_string_in_tuplecCs4tddd�}|�|jtd��}|�t|�d�dS)Nzres = a in {"str_value"}r`ra)rbr)rcr]r�	frozensetr^r)rrr\rrr�!test_interned_string_in_frozenset�sz0CodeConstsTest.test_interned_string_in_frozensetcCsddd�}|�|��dS)NrbcSs|S)Nr)�arrrr@�sz6CodeConstsTest.test_interned_string_default.<locals>.f)rb)r^)rr@rrr�test_interned_string_default�s
z+CodeConstsTest.test_interned_string_defaultcCs(tddd�}|�|jd�}|�|�dS)Nzres = "str\0value!"r`raz
strvalue!)rcr]rr_)rrr\rrr�test_interned_string_with_null�sz-CodeConstsTest.test_interned_string_with_nullN)rDrErFr]r^r_rrdrergrirjrrrrrY�srYc@seZdZdd�ZdS)�CodeWeakRefTestcsni}tdt�|�|d}~d�_�fdd�}t�|j|�}��t|���~��t|������j�dS)Nz
def f(): passr@Fcs
d�_dS)NT)�called)rA)rrr�callback�sz,CodeWeakRefTest.test_basic.<locals>.callback)	rar>rl�weakref�refr:Z
assertTrue�boolrN)r�	namespacer@rmZcoderefr)rr�
test_basic�szCodeWeakRefTest.test_basicN)rDrErFrrrrrrrk�srkT)�cpythoncCs|adS)N)�
LAST_FREED)Zptrrrr�myfreesruc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�CoExtracCstd�S)Nz	lambda:42)�eval)rrrr�get_func$szCoExtra.get_funcc	Cs<|��}|�ttdtt�d��|�ttdtt�d��dS)N�*�d)rx�assertRaises�SystemError�SetExtra�
FREE_INDEX�ctypes�c_voidp�GetExtra)rr@rrr�test_get_non_code*s
zCoExtra.test_get_non_codec	CsJ|��}|�tt|jtdt�d��|�t	|jtdt�d��d�dS)Nrzr)
rxr{r|r}r:r~rr�r"r�)rr@rrr�test_bad_index2s
zCoExtra.test_bad_indexcCs.|��}t|jtt�d��~|�td�dS)Nrz)rxr}r:r~rr�r"rt)rr@rrr�test_free_called9szCoExtra.test_free_calledcCsn|��}t��}t|jtt�d��t|jtt�d��|�td�t��}t|jt|�|�|j	d�~dS)N��i,)
rxrr�r}r:r~r"rtr�r[)rr@Zextrarrr�test_get_setBszCoExtra.test_get_setcCsZ|��}Gdd�dtj�}t|jtt�d��|||�}~|��|�	�|�
td�dS)Ncs$eZdZ�fdd�Zdd�Z�ZS)z6CoExtra.test_free_different_thread.<locals>.ThreadTestcst���||_||_dS)N)r�__init__r@�test)rr@r�)r(rrr�Ws
z?CoExtra.test_free_different_thread.<locals>.ThreadTest.__init__cSs|`|j�td�dS)Ni�)r@r�r"rt)rrrr�run[sz:CoExtra.test_free_different_thread.<locals>.ThreadTest.run)rDrErFr�r��
__classcell__rr)r(r�
ThreadTestVsr�i�)rx�	threadingZThreadr}r:r~rr��start�joinr"rt)rr@r��ttrrr�test_free_different_threadRs	
z"CoExtra.test_free_different_threadN)	rDrErFrxr�r�r�r�r�rrrrrv#s	rvcCsHddlm}t||�tttg}tdd�r<tdk	r<|�t	�t
|�dS)Nr)�	test_codeT)rs)r�r�rrrYrkrr�appendrvr)�verboser�Ztestsrrr�	test_mainfs


r��__main__)N)-�__doc__rOrUr�Zunittestrnr�ImportErrorZtest.supportrrrrr
rrZTestCaserrXrYrkZ	pythonapi�pyZ	CFUNCTYPEr�ZfreefuncZ_PyEval_RequestCodeExtraIndexZRequestCodeExtraIndexZargtypesZ	c_ssize_tZrestypeZ_PyCode_SetExtrar}Z	py_objectZc_intZ_PyCode_GetExtrar�ZPOINTERrtruZ	FREE_FUNCr~rvr�rDrrrr�<module>gsL
		30C