Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_embed.cpython-310.pyc
o

�9j���@s`ddlmZddlmZddlmZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZe
jdkZejdkZdZdZd	Zd
ZdZd	ZdZdZd
d�Zdd�ZGdd�d�ZGdd�deej �Z!Gdd�deej �Z"Gdd�dej �Z#Gdd�deej �Z$Gdd�deej �Z%Gdd�deej �Z&e'dkr�e�(�dSdS) �)�support)�
import_helper)�	os_helperN)�
namedtuple�nt�darwin����l��cCs.tj�|�}tj�|�d}|���d���S)Nr�_d)�os�path�basename�splitext�casefold�endswith)�program�name�r�&/usr/lib/python3.10/test/test_embed.py�debug_build%srcCs,ttj�}t|�D]
}|�d�r||=q	|S)N�PYTHON)�dictr
�environ�list�
startswith)�env�keyrrr�remove_python_envvars+s

�rc@s:eZdZdd�Zdd�Zdddddd�dd	�Zd
d�ZdS)�EmbeddingTestsMixincCs�tj�t�}tj�tj�tj�|���}d}tr/ttj�rdndd}||7}tj�tj�}ntj�	|d�}tj�	||�|_
}tj�|�sM|�d|�t�
�|_t�|�dS)N�
_testembedr�z.exe�Programsz%r doesn't exist)r
r�abspath�__file__�dirname�
MS_WINDOWSr�sys�
executable�join�test_exe�exists�skipTest�getcwd�oldcwd�chdir)�self�here�basepath�exename�ext�exepath�exerrr�setUp5s
zEmbeddingTestsMixin.setUpcCst�|j�dS�N)r
r0r/�r1rrr�tearDownHszEmbeddingTestsMixin.tearDownNr)r�timeout�
returncode�input�cwdcGs�|jg}|�|�|durtr|��}tjd|d<tj|tjtjd||d�}z|j	||d�\}	}
Wn|�
�|���|j|krat
jratd|�d��td|	���td	|
���td
�|�|j|d|j|
f�|	|
fS)z'Runs a test in the embedded interpreterN�
SYSTEMROOTT)�stdout�stderr�universal_newlinesrr?)r>r<z--- z failed ---zstdout:
zstderr:
z------zbad returncode %d, stderr is %r)r+�extendr'�copyr
r�
subprocess�Popen�PIPE�communicate�	terminate�waitr=r�verbose�print�assertEqual)r1rr<r=r>r?�args�cmd�p�out�errrrr�run_embedded_interpreterKs:
�
��z,EmbeddingTestsMixin.run_embedded_interpreterccs$�|�d�\}}|�|d�d}tdd�}d}g}|��D]r}|d�|�kr<|�t|�d�tjdkr7t|�|d7}q|�	t|�d	�t
�||�}|durT|�||�||�
��}	tjdkrct|	�|�|	j�|�|	j�|�|	j�|�|	�t|�d	kr�|d}
|�|	|
�|Vg}qdS)
N�&test_repeated_init_and_subinterpretersr"zS^interp (\d+) <(0x[\dA-F]+)>, thread state <(0x[\dA-F]+)>: id\(modules\) = ([\d]+)$�Interpzid interp tstate modulesr
z--- Pass {} ---r�)rTrNr�
splitlines�format�lenrrLrM�
assertLess�re�match�assertRegex�groups�
assertTrue�interp�tstate�modules�append)r1rRrS�
interp_patrV�numloops�current_run�liner]ra�mainrrr�%run_repeated_init_and_subinterpretersns@�



��z9EmbeddingTestsMixin.run_repeated_init_and_subinterpreters)�__name__�
__module__�__qualname__r8r;rTrjrrrrr 4s�#r c@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�EmbeddingTestsi�cCs(|��D]
}|d}|�|jd�qdS)Nr�0)rjrN�id)r1�runrirrr�test_subinterps_main�s�z#EmbeddingTests.test_subinterps_maincCsT|��D]#}|�^}}}t|j�}t|�D]\}}|�|jt||d��qqdS)Nr
)rj�intrp�	enumeraterN�str)r1rqri�subs�_�mainid�i�subrrr�test_subinterps_different_ids�s
��z,EmbeddingTests.test_subinterps_different_idscCsj|��D].}|�^}}}d|vrt�d��|D]}|�|j|j�|�|j|j�|�|j|j�qqdS)N�0x0zplatform prints pointers as 0x0)rj�unittest�SkipTest�assertNotEqualrarbrc)r1rqrirvrwrzrrr�test_subinterps_distinct_state�s
��z-EmbeddingTests.test_subinterps_distinct_statecCsP|�d�\}}|�|d�dd�tdtd�D�}d�|�d}|�||�dS)N�test_repeated_init_and_inittabr"cSsg|]}d|�d��qS)z	--- Pass z ---r)�.0ryrrr�
<listcomp>�szAEmbeddingTests.test_repeated_init_and_inittab.<locals>.<listcomp>r
�
)rTrN�range�
INIT_LOOPSr*)r1rRrS�linesrrrr��s
z-EmbeddingTests.test_repeated_init_and_inittabcCs�ttjdd�}|jd|d�\}}tjdkr t�t|�t|�d}d}d�gd	��}|j|||d
�}d|_	|�
|��|�dS)Nzutf-8:surrogateescape)�PYTHONIOENCODING�test_forced_io_encoding�rr
�utf-8�surrogateescaper�)z--- Use defaults ---�Expected encoding: default�Expected errors: defaultzstdin: {in_encoding}:{errors}zstdout: {out_encoding}:{errors}�'stderr: {out_encoding}:backslashreplacez--- Set errors only ---r�zExpected errors: ignorezstdin: {in_encoding}:ignorezstdout: {out_encoding}:ignorer�z--- Set encoding only ---�Expected encoding: iso8859-1r�zstdin: iso8859-1:{errors}zstdout: iso8859-1:{errors}�"stderr: iso8859-1:backslashreplacez--- Set encoding and errors ---r�zExpected errors: replacezstdin: iso8859-1:replacezstdout: iso8859-1:replacer�)�in_encoding�out_encoding�errors)rr
rrTrrLrMr*rY�maxDiffrN�strip)r1rrRrS�expected_stream_encoding�expected_errors�expected_outputrrrr��s 
�z&EmbeddingTests.test_forced_io_encodingcCspttjtj�tj�d�}|jd|d�\}}tr|j	}n	tj�t�
�d�}d|�d�}|�||�|�|d�dS)	z�
        Checks some key parts of the C-API that need to work before the runtime
        is initialized (via Py_Initialize()).
        )�
PYTHONPATH�test_pre_initialization_apir��spamzsys.executable: r�r"N)
rr
r�pathsepr*r(rrTr'r+r.�assertInrN)r1rrRrS�
expected_pathr�rrrr��sz*EmbeddingTests.test_pre_initialization_apicCsJt�}tj�tj�|d<|jd|d�\}}d}|�||�|�|d�dS)z�
        Checks that sys.warnoptions and sys._xoptions can be set before the
        runtime is initialized (otherwise they won't be effective).
        r��#test_pre_initialization_sys_optionsr�z�sys.warnoptions: ['once', 'module', 'default']
sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}
warnings.filters[:3]: ['default', 'module', 'once']
r"N)	rr
r�r*r(rrTr�rN)r1rrRrSr�rrrr�
s
��z2EmbeddingTests.test_pre_initialization_sys_optionscC�*|�d�\}}|�|d�|�|d�dS)ze
        bpo-20891: Calling PyGILState_Ensure in a non-Python thread must not
        crash.
        �
test_bpo20891r"N�rTrN�r1rRrSrrrr��zEmbeddingTests.test_bpo20891cCr�)zf
        bpo-33932: Calling Py_Initialize() twice should do nothing (and not
        crash!).
        �test_initialize_twicer"Nr�r�rrrr�$r�z$EmbeddingTests.test_initialize_twicecCs.|�d�\}}|�|��d�|�|d�dS)zS
        bpo-34008: Calling Py_Main() after Py_Initialize() must not fail.
        �test_initialize_pymainz6Py_Main() after Py_Initialize: sys.argv=['-c', 'arg2']r"N�rTrN�rstripr�rrrr�-sz%EmbeddingTests.test_initialize_pymaincCs.|�d�\}}|�|��d�|�|d�dS)N�
test_run_mainz%Py_RunMain(): sys.argv=['-c', 'arg2']r"r�r�rrrr�5szEmbeddingTests.test_run_maincCs2d}|�d�\}}|�|d|�|�|d�dS)NrW�test_run_main_loopz&Py_RunMain(): sys.argv=['-c', 'arg2']
r"r�)r1�nlooprRrSrrrr�:sz!EmbeddingTests.test_run_main_loopN)rkrlrmr�rrr{r�r�r�r�r�r�r�r�r�r�rrrrrn�s+		rnc
@sDeZdZdZer
dndZe�Ze�Ze	e
dddddd�Zer%e�ddi�e
eedeed�Ze
eeddddddd	�Zgd
�Zide	�dd�d
d�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�de�de�dd�de�idd�ddg�d g�d!g�d"g�d#d�d$d�d%e�d&e�d'e�d(e�d)e�d*e�d+e�d,d�d-ej�d.d��id/d�d0d�d1d�d2d�d3d�d4d�d5d�d6d�d7d�d8d�d9d�d:d�d;e�d<e�d=d�d>d�d?d��ddd@ddddA��Zer�e�dBdi�e
eeddCdD�Ze
eeddddddddddE�Ze�rdedB<ddddF�ZdGgZgdH�Ze�r)e�dI�e�dJ�e�r3dKdKedL�ZniZgdM�Ze�rAe�dN�dZedOdP��Z dQdR�Z!dSdT�Z"dUdV�Z#	d�dWdX�Z$dYdZ�Z%d[d\�Z&d]d^�Z'd_d`�Z(				d�dddaddb�dcdd�Z)dedf�Z*dgdh�Z+didj�Z,dkdl�Z-dmdn�Z.dodp�Z/dqdr�Z0dsdt�Z1dudv�Z2dwdx�Z3dydz�Z4d{d|�Z5d}d~�Z6dd��Z7d�d��Z8d�d��Z9d�d��Z:d�d��Z;d�d��Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d�d��ZGeHjId�d���ZJd�d��ZKd�d��ZLeM�Ned��d�d���ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTdS)��InitConfigTestsi�
surrogatepassr�rr
)�_config_init�	allocator�
parse_argv�configure_locale�coerce_c_locale�coerce_c_locale_warn�	utf8_mode�legacy_windows_fs_encoding)r�r�r�r�)r�r��isolated�use_environmentr��dev_moder�)r�r�r�r�r�r�r��install_signal_handlers�
use_hash_seed�	hash_seed�faulthandler�tracemalloc�import_time�show_ref_count�	dump_refs�malloc_stats�filesystem_encoding�filesystem_errors�pycache_prefixN�program_namer��argvr"�	orig_argv�xoptions�warnoptions�pythonpath_env�homer)�base_executable�prefix�base_prefix�exec_prefix�base_exec_prefix�module_search_paths�module_search_paths_set�
platlibdir�site_import�
bytes_warning�warn_default_encoding�inspect�interactive�optimization_level�parser_debug�write_bytecoderL�quiet�user_site_directory�configure_c_stdio�buffered_stdio�stdio_encoding�stdio_errors�skip_source_first_line�run_command�
run_module�default)�run_filename�_install_importlib�check_hash_pycs_mode�pathconfig_warnings�
_init_main�_isolated_interpreter�legacy_windows_stdior)r�r�r�)
r�r�r�r�r�r�r�r�r�r�)�Py_HasFileSystemDefaultEncoding�Py_HashRandomizationFlag�$_Py_HasFileSystemDefaultEncodeErrors)�Py_UTF8Moder�))�Py_BytesWarningFlagr�)�Py_DebugFlagr�)�Py_DontWriteBytecodeFlagr�T)� Py_FileSystemDefaultEncodeErrorsr�)�Py_FileSystemDefaultEncodingr�)�
Py_FrozenFlagr�T)�Py_IgnoreEnvironmentFlagr�T)�Py_InspectFlagr�)�Py_InteractiveFlagr�)�Py_IsolatedFlagr�)�
Py_NoSiteFlagr�T)�Py_NoUserSiteDirectoryr�T)�Py_OptimizeFlagr�)�Py_QuietFlagr�)�Py_UnbufferedStdioFlagr�T)�Py_VerboseFlagrL))�Py_LegacyWindowsFSEncodingFlagr�))�Py_LegacyWindowsStdioFlagr����)r�r��python3_dll)r�r�r�r�)r�cCs
d|_dSr9)�EXPECTED_CONFIG)�clsrrr�
tearDownClasss
zInitConfigTests.tearDownClasscCs<i}|D]}d|vr|�dd�\}}|||<qd||<q|S)N�=r
T)�split)r1�
xoptions_listr��optr�valuerrr�
main_xoptionss

zInitConfigTests.main_xoptionscCs�t�}t�d�}tjdd|g}tj||tjtjd�}|jr)t	d|j
�d|j����|j
�d�}zt
�|�WSt
jyH|�d|���YdSw)	Na4
            import json
            import sys
            import _testinternalcapi

            configs = _testinternalcapi.get_configs()

            data = json.dumps(configs)
            data = data.encode('utf-8')
            sys.stdout.buffer.write(data)
            sys.stdout.buffer.flush()
        z-S�-c)rrArBz)failed to get the default config: stdout=z stderr=r��fail to decode stdout: )r�textwrap�dedentr(r)rFrqrHr=�	ExceptionrArB�decode�json�loads�JSONDecodeError�fail)r1r�coderO�procrArrr�_get_expected_config_impls&
����z)InitConfigTests._get_expected_config_implcCslt}|jdur|��|_i}|j��D] \}}i}|��D]\}}t|t�r*|��}|||<q|||<q|Sr9)r�rr�items�
isinstancerrE)r1r�configs�
config_key�config_value�configrr
rrr�_get_expected_config<s




z$InitConfigTests._get_expected_configcCsD|��}|d}|��D]\}	}
|
|jur||	||	<q|d}|��D]\}	}
|
|jur3||	||	<q$|dr<|tkrFdD]}	|j||	<q>|dsO|j|d<|ddkr�|d|jur`d|d<|d	|jurl|j|d	<|d
|jurwd|d
<|d|jur�d|d<tr�|j}n|d
|jur�tj	�
|d
�}n	tj	�t��d�}|d|jur�||d<|d|jur�||d<|d
|jur�d|d
<|d}
|��D]\}	}
|
|jur�|
|	||	<q�|d|ju�r|d}|dur�|�
tj	j�}g|�|d�|d<|du�r|d��|d<||d�|jD]}	|	|v�r||	||	<�qdS)N�
pre_config�path_configr�)r�r�r�r�r�r
r�r�r�r�r�r�r�r!r)r�z./_testembedr!r�r�)r"r�GET_DEFAULT_CONFIG�
API_COMPAT�
IGNORE_CONFIG�UTF8_MODE_ERRORSr'r+r
rr$r*r.r
r�rE�COPY_PRE_CONFIG)r1�expected_preconfig�expected�expected_pathconfigr�api�modify_path_cbrr#rr
r$�default_executabler!r��pathsrrr�get_expected_configLsl
�
�


�


��z#InitConfigTests.get_expected_configcC�Nt|d�}t|���D]\}}||jur|�|d�||=q|�||�dS)Nr#�rrrr'�poprN)r1rr+r#rr
rrr�check_pre_config��
�z InitConfigTests.check_pre_configcCr2)Nr!r3)r1rr+r!rr
rrr�check_config�r6zInitConfigTests.check_configc	Cs�|d}|d}t|j�}|jD]"}t|�dkr(|\}}}||r#dnd||<q|\}}||||<q|jD]"}t|�dkrN|\}}}||rIdnd||<q6|\}}||||<q6|�|d|�dS)Nr#r!r	rr
�
global_config)r�DEFAULT_GLOBAL_CONFIG�COPY_GLOBAL_CONFIGrZ�COPY_GLOBAL_PRE_CONFIGrN)	r1rr#r!r+�item�
global_key�core_key�oppositerrr�check_global_config�s 




z#InitConfigTests.check_global_configcCsV|d}|jD]}||||<qtjj�|d�|d<|d|d<|�|d|�dS)Nr!r��module_search_pathr)�program_full_pathr$)�COPY_PATH_CONFIGr
rr�r*rN)r1rr+r!rrrr�check_path_config�s
z!InitConfigTests.check_path_configF)�
preconfig_apir�
ignore_stderrr?cCs�t�}|	dur|�|	�|}	|dur|}|tkr|j}
n|tkr$|j}
n|j}
|dur-i}t|
fi|��}|dur;i}|durAi}t|jfi|��}|tkrR|j	}n|tkrZ|j
}n|j}t|fi|��}|�||||	||�|j
||	|d�\}}|dur�|ds�d}|dur�|
s�|�|��|�zt�|�}Wntjy�|�d|���Ynw|�||�|�||�|�|�|�||�|S)N)rr?rLr"r)r�update�API_ISOLATED�PRE_CONFIG_ISOLATED�
API_PYTHON�PRE_CONFIG_PYTHON�PRE_CONFIG_COMPATr�PATH_CONFIG�
CONFIG_PYTHON�CONFIG_ISOLATED�
CONFIG_COMPATr1rTrNr�rrrrr5r7r@rD)r1�testname�expected_configr*r,r.rBr-rErrFr?�new_env�default_preconfig�default_configrRrSrrrr�check_all_configs�s`
�
��
z!InitConfigTests.check_all_configscC�|jdtd�dS)N�test_init_initialize_config�r-�rVr&r:rrr�test_init_default_config��z(InitConfigTests.test_init_default_configcCrW)N�test_preinit_compat_configrYrZr:rrrr]r\z*InitConfigTests.test_preinit_compat_configcCrW)N�test_init_compat_configrYrZr:rrrr^r\z'InitConfigTests.test_init_compat_configcCs@ddi}ddddgdddddddddd�
}|jd||td	�dS)
Nr�r
z./globalvarr�default::BytesWarningr)
r�r�r�r�r�r�r�r�rLr�r�r�r��test_init_global_configrYrZ�r1�	preconfigr!rrrr`s&��

�z'InitConfigTests.test_init_global_configcCstdd�}idd�dd�dd�dd	�d
d�dd�dd�d
d�dd�dd�dd�dddg�dgd��dd	�dgd��dgd��dd �id!d�d"d�d#d�d$d�d%d	�d&d�d'd�d(d�d)d�d*d�d+d�d,d�d-d.�d/|j�d0d1�d2d�d3d��}|jd4||td5�dS)6Nr
�r�r�r�rr�r��{r�rr�r�r�r��	iso8859-1r��replacer��conf_pycache_prefixr�z./conf_program_namer�r�arg2r�)�python3�-W�cmdline_warnoption�-X�cmdline_xoptionr�passrhr�r�)zconfig_xoption1=3zconfig_xoption2=�config_xoption3rmr�)rkr_�config_warnoptionr��pass
r�r�r�r�r�r�rLr�r�r�r�r�r��
my_platlibdirr�r��alwaysr�r��test_init_from_configrY��PYMEM_ALLOCATOR_MALLOCr'rVr&rarrrrts���������	�
��
������ �"�#�$�%�&�'�(�)�*�+�,�-�.�/�1�2�4�
6
�z%InitConfigTests.test_init_from_configcCs�dti}idd�dd�dd�dd�d	d�d
d�dd�dd
�dd�dd�dd�dd�dd�dd�dd�dd�ddg�d|jd��}|jd||td�dS) Nr�r�r
r��*r�rr�r�r�r�r��/my/pathr��env_pycache_prefixr�rrLr�r�rer�rfr�r�r��EnvVar�env_platlibdir�r�r��test_init_compat_envrYrurarrrr}[sV���������	�
���
������

�z$InitConfigTests.test_init_compat_envcCs�tdd�}idd�dd�dd�dd�d	d�d
d�dd�dd
�dd�dd�dd�dd�dd�dd�dd�dd�ddg�d|jd��}|jd||td�dS) Nr
rcr�r�rwr�rr�r�r�r�r�rxr�ryr�rrLr�r�rer�rfr�r�r�rzr{r|�test_init_python_envrY)rvr'rVrJrarrrr~wsX���������	�
���
������

�z$InitConfigTests.test_init_python_envcC�0ttd�}tdddgd�}|jd||td�dS)N�r�r
r��r�r�r��test_init_env_dev_moderY)r�PYMEM_ALLOCATOR_DEBUGrVr&rarrrr���
�

�z&InitConfigTests.test_init_env_dev_modecCr)Nr�r
r�r��test_init_env_dev_mode_allocrY)rrvrVr&rarrrr��r�z,InitConfigTests.test_init_env_dev_mode_alloccCs,dti}dddgd�}|jd||td�dS)Nr�r
r�)r�r�r��test_init_dev_moderY)r�rVrJrarrrr��s��

�z"InitConfigTests.test_init_dev_modecCsDdti}dggd�tj�d�dddgdgd�}|jd||td	�dS)
Nr��	script.py)rirl�devr�r
r�r�)r�r�r�r�r�r�r��test_preinit_parse_argvrY)r�r
rr$rVrJrarrrr��s�
�
	
�z'InitConfigTests.test_preinit_parse_argvcCs2ddi}gd�}||dd�}|jd||td�dS)Nr�r)ri�-E�-Irlr�rl�utf8r�)r�r�r��test_preinit_dont_parse_argvrY�rVrH)r1rbr�r!rrrr��s��

�z,InitConfigTests.test_preinit_dont_parse_argvcC� dddd�}|jd|td�dS)Nr
r�r�r�r��test_init_isolated_flagrY�rVrJ�r1r!rrrr��s
�z'InitConfigTests.test_init_isolated_flagcCr�)Nr
rr��test_preinit_isolated1rYrZr�rrrr���
�z&InitConfigTests.test_preinit_isolated1cCr�)Nr
rr��test_preinit_isolated2rYrZr�rrrr��r�z&InitConfigTests.test_preinit_isolated2cCrW)N�test_preinit_isolated_configrYr�r:rrrr��r\z,InitConfigTests.test_preinit_isolated_configcCrW)N�test_init_isolated_configrYr�r:rrrr��r\z)InitConfigTests.test_init_isolated_configcCrW)N�test_preinit_python_configrYr�r:rrrr��r\z*InitConfigTests.test_preinit_python_configcCrW)N�test_init_python_configrYr�r:rrrr��r\z'InitConfigTests.test_init_python_configcCs ddd�}|jdi|td�dS)Nr)r�r��test_init_dont_configure_localerYr�)r1rbrrrr��s�

�z/InitConfigTests.test_init_dont_configure_localecCs(ddd�}dd�}|jd|t|d�dS)Nz./init_read_set�
my_executable)r�r)cSs|�dd�|�d�dS)Nr
�test_path_insert1�test_path_append)�insertrd)rrrr�modify_pathsz7InitConfigTests.test_init_read_set.<locals>.modify_path�test_init_read_set)r-r.r�)r1r!r�rrrr�s�
�z"InitConfigTests.test_init_read_setcCs.dgd�gd�gd�d�}|jd|td�dS)Nr
)�config_xoptionrm�sysadd_xoptionr�)�ignore:::cmdline_warnoptionzignore:::sysadd_warnoptionzignore:::config_warnoption)rirjr�rlrm)r�r�r�r��test_init_sys_addrYr�r�rrrr�s�z!InitConfigTests.test_init_sys_addcCs8d}ddgdd|dgd|ddd�}|jd	|td
�dS)N�Rimport _testinternalcapi, json; print(json.dumps(_testinternalcapi.get_configs()))rrhri�	./python3r�r)r�r�r�r�r��test_init_run_mainrYr��r1rr!rrrr�#s
�z"InitConfigTests.test_init_run_maincCs<d}ddgdd|dgd|dddd	�}|jd
|tdd�dS)
Nr�rrhrir�r�rr)r�r�r�r�r�r��test_init_mainz)Run Python code before _Py_InitializeMain)r-rBr�r�rrrr�/s��

�zInitConfigTests.test_init_maincCs.dgd�gd�dddd�}|jd|td	�dS)
Nr)r�arg1�-v�arg3��./argv0r�rrnr�r�r�r�rqr)r�r�r�r�r�r��test_init_parse_argvrYr�r�rrrr�@s�z$InitConfigTests.test_init_parse_argvcCs4ddi}dgd�gd�dd�}|jd||td�dS)Nr�rr�r�)r�r�r�r��test_init_dont_parse_argvrYr�)r1r#r!rrrr�Ks��

�z)InitConfigTests.test_init_dont_parse_argvcCsDtrd}|j}nd}tr|j}nt�|�pd}|�|||d��dS)N�pythonrir")r�r�r))r'r+�MACOS�shutil�whichrG)r1r!r�r)rrr�default_program_nameXs�z$InitConfigTests.default_program_namecCsX|��}|dd}|ddddd�}|�|�dtjj�|�i}|jd|t|dd�dS)	Nr!r�r")r�r�r�r�r��TESTPATH�test_init_setpathT�r-rrF)r"r�r
rr�r*rVr&�r1r!r0rrrrr�hs�

�z!InitConfigTests.test_init_setpathc	CsT|��}|dd}|dddddddd�}dtjj�|�i}|jd|t|d	d
�dS)Nr!r�r"�conf_program_name�conf_executable)r�r�r�r�r�r�r�r)r��test_init_setpath_configTr�)r"r
rr�r*rVrJr�rrrr�{s�
�z(InitConfigTests.test_init_setpath_configc
Cs�|��}|dur|dd}|dur|dd}tr |ddStj}tj�|tjd|j�|j	�d��tj�|tjd|j�d|j	���tj�|tjd|j�d|j	��d�gS)Nr!r�r�r�z.zip�.�lib-dynload)
r"r'r(�version_infor
rr*r��major�minor)r1r�r�r!�verrrrr��s$����z#InitConfigTests.module_search_pathsc	cs��t���Z}tj�|�}tr7ddl}tj�|j�}t�	|�D]}|�|d�r6t
�tj�||�tj�||��qtj�|tj�
|j��}t
�|j|�t
�|j|�||_|VWd�dS1sbwYdS)Nrz*.dll)�tempfile�TemporaryDirectoryr
r�realpathr'�fnmatchr&r+�listdirr��copyfiler*r�copystat)r1�tmpdirr��exedir�f�	exec_copyrrr�tmpdir_with_python�s �
 �"�z"InitConfigTests.tmpdir_with_pythonc
Cs�|��}|dd}tjj�|�}|D]}tj�|�sqtj�tj�|d��r/tj�|�}n	q|�d|���|}}|j	||d�}|||||||d�}|�
|�||d�}	|jd|t|	d	�dS)
Nr!r��os.pyzUnable to find home in )r�r�)r�r�r�r�r�r�r�)�TESTHOMEr��test_init_setpythonhome)r-r)
r"r
rr�r*�isdirr,r&rr�r�rVr&)
r1r!r0�	paths_strrr�r�r��expected_pathsrrrrr��s4��
	

�z'InitConfigTests.test_init_setpythonhomecCs6|��}|dd}tjj�|�}||d<d|i}|S)Nr!r�r�r�)r"r
rr�r*)r1r!�all_configsr0r�rrrr�copy_paths_by_env�sz!InitConfigTests.copy_paths_by_envz#Windows does not use pybuilddir.txtc
	Cs�|���[}d}tj�||�}t�|�tj�|d�}t|ddd��
}|�|�Wd�n1s1wY|��}||d<|j}|||d�}|�	|�}	|j
d|t|	d	|d
�Wd�dS1sbwYdS)N�libdirzpybuilddir.txt�wr���encodingr)r�r)r�r^T)r-rrFr?)r�r
rr*�mkdir�open�writer�r+r�rVr&)
r1r��subdirr��filename�fpr�r)r!rrrr�test_init_pybuilddir�s*

��
�"�z$InitConfigTests.test_init_pybuilddircCs6|����}t����}tj}ts(tj�|tj	d|j
�d|j��d�}t�|�ntj�|d�}t�|�t
�tjtj�|d��tj�|d�}t|ddd	��}td
||d�td|d�Wd�n1sgwY|��}tsw||d
<n,t|�D]#\}}	|dkr�tj�|tj�|	��||<q{tj�|tj�|	��||<q{||d
<|j}
|}|||
|
|d�}i}
tr�||d<||d<tj}d|j
��}t|
�r�|d7}|d7}tj�tj�|
�|�}||
d<|�|�}|jd||
t|d|d�Wd�n1s�wYWd�dSWd�dS1�swYdS)Nr�r�r��libr�z
pyvenv.cfgr�r�r�z	home = %s��filez$include-system-site-packages = falserr)r�r�r�r)r�r�r�rz.DLLrr^T)r,r-rrFr?)r�r�r�r(r�r'r
rr*r�r�r��makedirsr�r�r%r�rMr�rtrr+rr&r�rVr&)r1r��pyvenv_homer��lib_dynloadr�r�r0�indexrr)r�r!r$�dllrrrr�test_init_pyvenv_cfgsl��
�
�
�R�z$InitConfigTests.test_init_pyvenv_cfgc
s�t�d��t�d�}�fdd�}|d�}|d�}|d�}|d�}|d	�}|d
�}|��d}	|�|��tjj�|	d�|�|�|	d
�|�|�|	d�|�|�|	d�|�|�|	d�|�|�|	d�dS)N�ctypes�_testinternalcapicst�j|�}d|_�j|_|S)Nr)�getattr�	pythonapi�argtypes�	c_wchar_p�restype)r�func�r�rr�get_funcOsz8InitConfigTests.test_global_pathconfig.<locals>.get_func�
Py_GetPath�Py_GetPrefix�Py_GetExecPrefix�Py_GetProgramName�Py_GetProgramFullPath�Py_GetPythonHomer!r�r�r�r�r)r�)r�
import_module�get_configsrNr
r
rr�)
r1r�r�r�r�r�r�r�r�r!rr�r�test_global_pathconfig@s$

�z&InitConfigTests.test_global_pathconfigcCs<gd�}ttd�}ddd|gd�d�}|jd||td�dS)N)zignore:::PyConfig_Insert0r�z
ignore:::env1z
ignore:::env2zignore:::cmdline1zignore:::cmdline2r_zignore:::PySys_AddWarnOption1zignore:::PySys_AddWarnOption2zignore:::PyConfig_BeforeReadzignore:::PyConfig_AfterReadr�r
)riz-Wignore:::cmdline1z-Wignore:::cmdline2)r�r�r�r�r��test_init_warnoptionsrY)rr�rVrJ)r1r�rbr!rrrr�fs
�
	
�z%InitConfigTests.test_init_warnoptionscCs"dddgd�}|jd|td�dS)Nrrzerror::BytesWarning)r�r�r��test_init_set_configrYr�r�rrrr�s�
�z$InitConfigTests.test_init_set_configcC�|�d�dS)N�test_get_argc_argv�rTr:rrrr��z"InitConfigTests.test_get_argc_argvr9)NNNNN)NN)Urkrlrmr�r'r(�objectr%r'r&�PYMEM_ALLOCATOR_NOT_SETrLrGrrJrKrHrIr)r(r�rPrNrOr9r;r:rDrMrCr�classmethodrrrr"r1r5r7r@rDrVr[r]r^r`rtr}r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
contextlib�contextmanagerr�r�r�r}�skipIfr�r�r�r�rrrrrrr�Cs��	���
�������	�
���
���������������!�"�#�$�%�&�'�)�*�+�,�-�.�/�0�1�2�3�4�5�7�8�:�;�<�=�E�����

�	



�E
��<>			


 

?&	r�c@�eZdZdd�ZdS)�SetConfigTestscCsBtjdddg}tj|tjtjd�}|�|jd|j|j|jf�dS)Nr�z-mztest._test_embed_set_config)rArBr)	r(r)rFrqrHrNr=rArB)r1rPrrrr�test_set_config�s�
�zSetConfigTests.test_set_configN)rkrlrmr
rrrrr��rc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�
AuditingTestscCr)N�test_open_code_hookrr:rrrr�rz!AuditingTests.test_open_code_hookcCr)N�
test_auditrr:rrrr�rzAuditingTests.test_auditcCr)N�test_audit_subinterpreterrr:rrrr�rz'AuditingTests.test_audit_subinterpretercC�|jdtjdd�dS)N�test_audit_run_commandr
�r<r=�rTr�
SHORT_TIMEOUTr:rrrr��
�z$AuditingTests.test_audit_run_commandcCr)N�test_audit_run_filer
rrr:rrrr�rz!AuditingTests.test_audit_run_filec	Cs�tj�|jtj�d}t|ddd��}td|d�td|d�Wd�n1s)wYzit��d|i�}|j	d	t
jd
|d�Wt�|�dSt�|�w)N�.pyr�r�r�z
import sysr�z&sys.__interactivehook__ = lambda: None�
PYTHONSTARTUP�test_audit_run_interactivehook�
�r<r=r�
r
rr*r/r�TESTFNr�rMrrTrr�unlink�r1�startupr�rrrrr�s��z,AuditingTests.test_audit_run_interactivehookc	Cs�tj�|jtj�d}t|ddd��}td|d�Wd�n1s#wYzit��d|i�}|j	dt
jd	|d
�Wt�|�dSt�|�w)Nrr�r�r�rnr�r�test_audit_run_startuprrrr"rrrr$�s��z$AuditingTests.test_audit_run_startupcCr)N�test_audit_run_stdinr
rrr:rrrr%�rz"AuditingTests.test_audit_run_stdinN)rkrlrmrrrrrrr$r%rrrrr�s
rc@r)�	MiscTestscCr)N�test_unicode_id_initrr:rrrr'�szMiscTests.test_unicode_id_initN)rkrlrmr'rrrrr&�rr&c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StdPrinterTestsr
cCs,t�d�}|jj}|jf|_|j|_||�S)Nr�)rr�r��PyFile_NewStdPrinter�c_intr��	py_objectr�)r1�fdr�r)rrr�create_printer�s


zStdPrinterTests.create_printerc
Cs�d}|j}t�|�}|�tj|�t��\}}|�tj|�|�tj|�zt�||�|�|�}|�|�Wt�||�nt�||�wt�	|d�}|�
||�dd��dS)Nuunicode:é-€-�!
�dr��backslashreplace)�	STDOUT_FDr
�dup�
addCleanup�close�pipe�dup2r-r��readrN�encode)r1�message�	stdout_fd�stdout_fd_copy�rfd�wfd�printer�datarrr�
test_write�s

zStdPrinterTests.test_writecCsJ|j}|�|�}|�|��|�|�|��t�|��|��|��dSr9)r0r-rN�fileno�isattyr
�flushr3�r1r,r=rrr�test_methods�s
zStdPrinterTests.test_methodscCs$|j}|�|�}t�|t|��dSr9)r0r-r�check_disallow_instantiation�typerCrrr�test_disallow_instantiations
z+StdPrinterTests.test_disallow_instantiationN)rkrlrmr0r-r?rDrGrrrrr(�sr(�__main__))�testr�test.supportrrr}�collectionsrrrr
r\r�rFr(r�rrr'�platformr�rr�rvr&rJrHr��
MAX_HASH_SEEDrrr �TestCasernr�rrr&r(rkrirrrr�<module>sZ

	n"T33�

Youez - 2016 - github.com/yon3zu
LinuXploit