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: //proc/thread-self/root/usr/local/lib/python3.7/test/__pycache__/test_site.cpython-37.pyc
B

��g6l�@s^dZddlZddlZddlmZddlmZmZmZmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZddlmZejjr�e�d��ddlZdadd	�Zd
d�ZGdd
�d
ej�Z Gdd�de!�Z"Gdd�dej�Z#Gdd�dej�Z$e�%ej&dkd�Gdd�dej��Z'e(dk�rZe�)�dS)zTests for 'site'.

Tests assume the initial paths in sys.path once the interpreter has begun
executing have not been removed.

�N)�support)�captured_stderr�TESTFN�EnvironmentVarGuard�
change_cwd)�mock)�copyzPython was invoked with -Sc
Csztjdd�atjrvtj�tj�svyt�tj�t�	tj�Wn6t
k
rt}zt�dtj|f��Wdd}~XYnXdS)Nz-unable to create user site directory (%r): %s)
�sys�path�OLD_SYS_PATH�site�ENABLE_USER_SITE�os�isdir�	USER_SITE�makedirs�
addsitedir�PermissionError�unittest�SkipTest)�exc�r�*/usr/local/lib/python3.7/test/test_site.py�setUpModule'srcCsttjdd�<dS)N)rr	r
rrrr�tearDownModule6src@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	de
fdd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Ze�ejd�dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S))�HelperFunctionsTestsz Tests for helper functions.
    cCs@tjdd�|_tj|_tj|_tj|_	t
j|_t
t
j�|_dS)zSave a copy of sys.pathN)r	r
�sys_pathr�	USER_BASE�old_baser�old_site�PREFIXES�old_prefixes�	sysconfig�_CONFIG_VARS�
original_varsr�old_vars)�selfrrr�setUp>szHelperFunctionsTests.setUpcCsL|jtjdd�<|jt_|jt_|jt_	|j
t_tj�
�tj�|j�dS)zRestore sys.pathN)rr	r
rrrrrr!r r$r"r#�clear�updater%)r&rrr�tearDownGs
zHelperFunctionsTests.tearDowncCshd}tjj|�}tj|�\}}|�tj�|�|�|tj�|�krP|�||�n|�tj�|�|�dS)N)Z	BeginningZEnd)rr
�joinr�makepath�assertEqual�abspath�normcase)r&�
path_partsZoriginal_dirZabs_dirZnorm_dirrrr�
test_makepathQsz"HelperFunctionsTests.test_makepathcCs<t��}x.dd�tjD�D]}|�||d||f�qWdS)NcSs*g|]"}|rtj�|�rt�|�d�qS)�)rr
�existsrr,)�.0r
rrr�
<listcomp>`sz;HelperFunctionsTests.test_init_pathinfo.<locals>.<listcomp>zB%s from sys.path not found in set returned by _init_pathinfo(): %s)r�_init_pathinfor	r
�assertIn)r&Zdir_set�entryrrr�test_init_pathinfo^s
z'HelperFunctionsTests.test_init_pathinfocCsJ|�|jtjd|j�|�t�|j�dtj�|�t	j�
|j��dS)z>Contain common code for testing results of reading a .pth filez%s not in sys.modulesrN)r7�importedr	�modulesrr,�
good_dir_pathr
�assertFalserr3�bad_dir_path)r&�pth_filerrr�pth_file_testsfsz#HelperFunctionsTests.pth_file_testscCsLt�}|jdd�z*|��t�|j|jt��|�|�Wd|��XdS)NT)�prep)	�PthFile�cleanup�creater�
addpackage�base_dir�filename�setr@)r&r?rrr�test_addpackagemsz$HelperFunctionsTests.test_addpackage�.cs\tj�|�}|d}tj�||��t�ddd�}|��fdd��|�|�|��||fS)Nz.pth�wzutf-8)�encodingcs
t���S)N)r�remover)�pth_fnrr�<lambda>��z/HelperFunctionsTests.make_pth.<locals>.<lambda>)rr
r.r+�open�
addCleanup�write�close)r&�contents�pth_dirZpth_nameZpth_basenamer?r)rNr�make_pth|s
zHelperFunctionsTests.make_pthc	Cs�|�d�\}}t��}t�||t��WdQRX|�|��d�|�|��t�t	j
�||���|�|��d�|�|��d�|�|��d�dS)Nzimport bad)syntax
zline 1�	Tracebackzimport bad\)syntax�SyntaxError)rWrrrErH�assertRegex�getvalue�re�escaperr
r+)r&rVrN�err_outrrr�!test_addpackage_import_bad_syntax�s
z6HelperFunctionsTests.test_addpackage_import_bad_syntaxc	Cs�|�d�\}}t��}t�||t��WdQRX|�|��d�|�|��t�t	j
�||���|�|��d�|�|��d�dS)Nzrandompath
import nosuchmodule
zline 2rX�ModuleNotFoundError)rWrrrErHrZr[r\r]rr
r+)r&rVrNr^rrr�test_addpackage_import_bad_exec�s
z4HelperFunctionsTests.test_addpackage_import_bad_execc	Cs�|�d�\}}t��}t�||t��WdQRX|�|��d�|�|��t�t	j
�||���|�|��d�|�|��d�dS)Nzabcdef
zline 1rX�
ValueError)rWrrrErHrZr[r\r]rr
r+)r&rVrNr^rrr�#test_addpackage_import_bad_pth_file�s
z8HelperFunctionsTests.test_addpackage_import_bad_pth_filecCsHt�}|jdd�z&|��t�|jt��|�|�Wd|��XdS)NT)rA)rBrCrDrrrFrHr@)r&r?rrr�test_addsitedir�sz$HelperFunctionsTests.test_addsitedircCs|�t��t���dS)N)r-r�_getuserbaser")r&rrr�test__getuserbase�sz&HelperFunctionsTests.test__getuserbasecCsBtjdkrtjrd}n
tjd}|�t�t���t	�
d|��dS)N�darwinZosx_framework_userZ_userZpurelib)r	�platform�
_frameworkr�namer-r�	_get_pathrer"Zget_path)r&Zschemerrr�
test_get_path�s

z"HelperFunctionsTests.test_get_pathz<requires access to PEP 370 user-site (site.ENABLE_USER_SITE)cCs(tj}|�|tj�tj��}tj	tj
dd|g|d�}|�|d�tj��}tj	tj
ddd|g|d�}|t��dkr�|�|d�n|�|dd�tj��}d|d	<tj	tj
dd|g|d�}|t��dkr�|�|d�n|�|dd
�tj��}d|d<tj	tj
dd
g|d�}|�|dd�dS)Nz-cz$import sys; sys.exit(%r in sys.path))�envr2z-srz%User site still added to path with -s�1ZPYTHONNOUSERSITEz3User site still added to path with PYTHONNOUSERSITEz/tmp�PYTHONUSERBASEz=import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))z#User base not set by PYTHONUSERBASE)
rrr7r	r
r�environr�
subprocess�call�
executabler-�getsitepackages)r&Zusersiterm�rcrrr�
test_s_option�s<






z"HelperFunctionsTests.test_s_optionc	Cshdt_t��}|�tj|�dt_ddl}d|_t��(}d|d<|�t���d�t���WdQRXdS)Nr�xoxoro)	rr�getuserbaser-r"r#r�
assertTrue�
startswith)r&�	user_baser"rprrr�test_getuserbase�sz%HelperFunctionsTests.test_getuserbasecCsLdt_dt_t��}|�tj|�|�|�tj�|�|�tjt���dS)N)rrr�getusersitepackagesr-ryrzrx)r&�	user_siterrr�test_getusersitepackagessz-HelperFunctionsTests.test_getusersitepackagescCs�dgt_t��}tjdkr\|�t|�d�tj�dddt	j
dd�d�}|�|d|�n@|�t|�d�|�|dd�tj�ddd�}|�|d|�dS)	Nrw�/r2�libzpython%d.%d�z
site-packagesr)rr rtr�sepr-�lenr
r+r	�version_info)r&�dirsZwantedrrr�test_getsitepackagess

z)HelperFunctionsTests.test_getsitepackagescCs�dt_dt_t��h}t�ddd���L|d=|d=t��}|�|�dt	j
�|�t��}|�|�|�|�WdQRXWdQRXtjddd	��f}tj�td
��L}t
�tdd��2t�}t�|�|�|�|��|�|�WdQRXWdQRXWdQRXdS)
Nzos.path.expandusercSs|S)Nr)r
rrrrO%rPz=HelperFunctionsTests.test_no_home_directory.<locals>.<lambda>ro�APPDATA�~z
os.path.isdirF)Zreturn_valuerr
T)rrrrrZpatchrxryrzrr�r}�objectrZ	swap_attrrH�addusersitepackagesZassert_called_once_withZassert_not_calledr=)r&rpr{r~Z
mock_isdirZmock_addsitedir�known_pathsrrr�test_no_home_directorys&&

z+HelperFunctionsTests.test_no_home_directoryN)�__name__�
__module__�__qualname__�__doc__r'r*r1r9r@rIrrWr_rarcrdrfrlr�
skipUnlessrr
rvr|rr�r�rrrrr:s&	

)
rc@s4eZdZdZedddfdd�Zdd�Zd
d
d�ZdS)rBz/Helper class for handling testing of .pth filesZtimeZ__testdir__Z__badcCsj|d|_tj�d�|_tj�|j|j�|_||_||_||_	tj�|j|j�|_
tj�|j|j	�|_dS)zInitialize instance variablesz.pth�N)rGrr
r.rFr+�	file_pathr:�good_dirname�bad_dirnamer<r>)r&�
filename_baser:r�r�rrr�__init__Bs
zPthFile.__init__cCsrt|jd�}zJtd|d�td|d�td|j|d�t|j|d�t|j|d�Wd|��Xt�|j	�dS)aoCreate a .pth file with a comment, blank lines, an ``import
        <self.imported>``, a line with self.good_dirname, and a line with
        self.bad_dirname.

        Creation of the directory for self.good_dir_path (based off of
        self.good_dirname) is also performed.

        Make sure to call self.cleanup() to undo anything done by this method.

        rKz#import @bad module name)�file�
z	import %sN)
rQr��printr:r�r�rTr�mkdirr<)r&�FILErrrrDNs
zPthFile.createFcCs�tj�|j�rt�|j�|r@tj�|j�|_	|j	rTtj|j=n|j	rT|j	tj|j<tj�|j
�rnt�|j
�tj�|j�r�t�|j�dS)z�Make sure that the .pth file is deleted, self.imported is not in
        sys.modules, and that both self.good_dirname and self.bad_dirname are
        not existing directories.N)
rr
r3r�rMr	r;�getr:Zimported_moduler<�rmdirr>)r&rArrrrCdszPthFile.cleanupN)F)r�r�r�r�rr�rDrCrrrrrB?s
rBc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	d
�dd��Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zej�d�ejje�ejddkd�e�eejd�d�dd�����ZdS) �ImportSideEffectTestsz(Test side-effects from importing 'site'.cCstjdd�|_dS)zMake a copy of sys.pathN)r	r
r)r&rrrr'yszImportSideEffectTests.setUpcCs|jtjdd�<dS)zRestore sys.pathN)rr	r
)r&rrrr*}szImportSideEffectTests.tearDownc	Cs�y"tj�tj�tj��}t��}Wn.tk
rPtj�tj�tj��\}}YnXt|���tj	�
�}||d<d}d�|�}tj
tjdd|g|tjd�}|��\}}|�|jd�|��dd�\}	}
|�tj�|	��|�tj�|
��tj
tjd|g|tjd�}|��\}}|�|jd�|��dd�\}	}
|�tj�|	�d	�|	�d
���|�tj�|
�d	�|
�d
���WdQRXdS)N�
PYTHONPATH)zimport os, sysz9os_file = os.__file__.encode("ascii", "backslashreplace")z(sys.stdout.buffer.write(os_file + b"\n")z=os_cached = os.__cached__.encode("ascii", "backslashreplace")z*sys.stdout.buffer.write(os_cached + b"\n")r�z-Sz-c)rm�stdoutrr�zexpected absolute path, got {}�ascii)rr
�relpath�dirname�__file__�getcwdrb�splitrrprr+rq�Popenr	rs�PIPE�communicater-�
returncode�
splitlinesr=�isabsry�format�decode)r&�parent�cwdrm�codeZcommand�procr��stderrZ
os__file__Zos__cached__rrr�test_abs_paths�s< 



z$ImportSideEffectTests.test_abs_pathscCs8t��t�}x$tjD]}|�||�|�|�qWdS)N)r�removeduppathsrHr	r
�assertNotIn�add)r&Z
seen_pathsr
rrr�test_no_duplicate_paths�s
z-ImportSideEffectTests.test_no_duplicate_pathsztest not implementedcCsdS)Nr)r&rrr�test_add_build_dir�sz(ImportSideEffectTests.test_add_build_dircCs$|�ttd��|�ttd��dS)N�quit�exit)ry�hasattr�builtins)r&rrr�test_setting_quit�sz'ImportSideEffectTests.test_setting_quitcCs4|�ttd��|�ttd��|�ttd��dS)N�	copyright�credits�license)ryr�r�)r&rrr�test_setting_copyright�sz,ImportSideEffectTests.test_setting_copyrightcCs|�ttd��dS)N�help)ryr�r�)r&rrr�test_setting_help�sz'ImportSideEffectTests.test_setting_helpcCsRtjdkrNddl}|��d�d�rNx(tjj��D]}|dkr2Pq2W|�d�dS)N�win32rr2Zcp�mbcszdid not alias mbcs)	r	rh�locale�getdefaultlocalerz�	encodings�aliases�values�fail)r&r��valuerrr�test_aliasing_mbcs�s
z(ImportSideEffectTests.test_aliasing_mbcscCs:dtjkr6yddl}Wntk
r*YnX|�d�dS)N�
sitecustomizerz(sitecustomize not imported automatically)r	r;r��ImportErrorr�)r&r�rrr�test_sitecustomize_executed�s
z1ImportSideEffectTests.test_sitecustomize_executedZnetwork��finalzonly for released versionsZHTTPSHandlerz$need SSL support to download licensec
Cs�tj��d}tjj|dd�}y<tj�|��&tj�	|��}|�
�}WdQRXWdQRXWn,tjjk
r�}z
|j
}Wdd}~XYnX|j|dd|d�dS)Nr2ZHEAD)�method��zCan't find )�msg)r��_Printer__datar��urllib�requestZRequest�testrZtransient_internetZurlopenZgetcode�errorZ	HTTPErrorr�r-)r&ZurlZreq�datar��errr�test_license_exists_at_url�s	 z0ImportSideEffectTests.test_license_exists_at_urlN)r�r�r�r�r'r*r�r�r�skipr�r�r�r�r�r�r�rZrequires_resourceZsystem_must_validate_certr�r	r�r�r�r�r�rrrrr�vs"1	


r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�StartupImportTestsc

CsLtjtjdddgtjdd�}|��d}|�|jdt|��t	|�}x>|D]6}t
�
tj�
|d��}|rJ|�dt|��d	|���qJWtjtjdd
ddgtjtjdd�}|��\}}|�|jd||f�t	|�}|�d
|�dddddh}|�|�|�|�|�d||�|�d||�ddddddddddh
�tj�}	|�|�|	�|�dS)Nz-Iz-cz!import sys; print(repr(sys.path))zutf-8)r�rLrz*.pthzfound z .pth files in: z-vz#import sys; print(set(sys.modules)))r�r�rLrr\�_sre�sre_compile�
sre_constants�	sre_parser��copyreg�_collections�collections�	functools�heapq�	itertools�keyword�operator�reprlib�types�weakref)rqr�r	rsr�r�r-r��repr�eval�globrr
r+ZskipTestr�r7r=�intersectionr��
difference�builtin_module_names)
r&�popenr�Zisolated_pathsr
Z	pth_filesr�r;Zre_modsZcollection_modsrrr�test_startup_imports�s:

z'StartupImportTests.test_startup_importscCs&t�tjddg���}|�|d�dS)Nz-cz9import sys; sys.exit(hasattr(sys, "__interactivehook__"))z''__interactivehook__' not added by site)rqr�r	rs�waitry)r&�rrrr�test_startup_interactivehook+s
z/StartupImportTests.test_startup_interactivehookcCs(t�tjdddg���}|�|d�dS)Nz-Iz-cz9import sys; sys.exit(hasattr(sys, "__interactivehook__"))z,'__interactivehook__' added in isolated mode)rqr�r	rsr�r=)r&r�rrr�%test_startup_interactivehook_isolated0sz8StartupImportTests.test_startup_interactivehook_isolatedcCs(t�tjdddg���}|�|d�dS)Nz-Iz-czYimport site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))z6'__interactivehook__' not added by enablerlcompleter())rqr�r	rsr�ry)r&r�rrr�.test_startup_interactivehook_isolated_explicit6szAStartupImportTests.test_startup_interactivehook_isolated_explicitN)r�r�r�r�r�r�r�rrrrr��s0r�r�zonly supported on Windowsc@s6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�
_pthFileTestsTc	Cs�ddl}t��}|�tjj|�tj�	|tj�
tj�d�}|�
tj�}tj�	|tj�
|�d�}t�tj|�t�||�|r�tj�|�dd}ntj�|�dd}t|d�� }	x|D]}
t|
|	d�q�WWdQRX|S)Nrr2z._pthrK)r�)�_winapi�tempfileZmkdtemprRr�rZrmtreerr
r+r�r	rsZGetModuleFileNameZ	dllhandle�shutilr�splitextrQr�)r&�lines�exe_pthrZtemp_dir�exe_fileZdll_src_fileZdll_fileZ	_pth_file�f�linerrr�_create_underpth_exe@s
z"_pthFileTests._create_underpth_execCsHg}x>|D]6}|r
|ddkr q
tj�tj�||��}|�|�q
W|S)Nr�#)rr
r.r+�append)r&�
sys_prefixrrrZabs_pathrrr�"_calc_sys_path_for_underpth_nositeRs
z0_pthFileTests._calc_sys_path_for_underpth_nositecs�tj�tj�tj���tj�tj�}d�fdd�td�D�d�}|�|�}|�	tj�|�|�}tj
��}d|d<d	�|t�
d
��|d
<tj|ddg|d
d�}|���d�}|�|d�|�||d�dS)N�fake-path-namecsg|]}��qSrr)r4�_)�libpathrrr5`sz;_pthFileTests.test_underpth_nosite_file.<locals>.<listcomp>r�r��	# commentzfrom-envr�z{};{}�PATHz-czCimport sys; print("\n".join(sys.path) if sys.flags.no_site else "")�ansi)rmrLr�zsys.flags.no_site was Falsezsys.path is incorrect)r)r�r)rr
r�r�r�r	rs�ranger	r
rprr��getenvrqZcheck_output�rstripr�ryr-)r&�
exe_prefixZ	pth_linesrrrm�outputZactual_sys_pathr)rr�test_underpth_nosite_file[s,



z'_pthFileTests.test_underpth_nosite_filec
s�tj�tj�tj���tj�tj�}|�d�fdd�td�D�d��}tj�|�}tj	�
�}d|d	<d
�|t�d��|d<t
j|dd
tj�|d��tj�|d�fg|d�}|�|d�dS)N�fake-path-namecsg|]}��qSrr)r4r)rrrr5|sz4_pthFileTests.test_underpth_file.<locals>.<listcomp>r�r��	# comment�import sitezfrom-envr�z{};{}rz-cz�import sys; sys.exit(not sys.flags.no_site and %r in sys.path and %r in sys.path and %r not in sys.path and all("\r" not in p and "\n" not in p for p in sys.path)))rmzsys.path is incorrect)r)r�rr)rr
r�r�r�r	rsr	rrprr�rrqrrr+ry)r&rrrrmrur)rr�test_underpth_filews&
z _pthFileTests.test_underpth_filec
s�tj�tj�tj���tj�tj�}|jd�fdd�td�D�d�dd	�}tj�|�}tj	�
�}d
|d<d�|t�d
��|d
<t
j|ddtj�|d��tj�|d
�fg|d�}|�|d�dS)N�fake-path-namecsg|]}��qSrr)r4r)rrrr5�sz8_pthFileTests.test_underpth_dll_file.<locals>.<listcomp>r�r��	# comment�import siteF)rzfrom-envr�z{};{}rz-cz�import sys; sys.exit(not sys.flags.no_site and %r in sys.path and %r in sys.path and %r not in sys.path and all("\r" not in p and "\n" not in p for p in sys.path)))rmzsys.path is incorrect)r)r�rr )rr
r�r�r�r	rsr	rrprr�rrqrrr+ry)r&rrrrmrur)rr�test_underpth_dll_file�s(
z$_pthFileTests.test_underpth_dll_fileN)T)r�r�r�r	r
rrr!rrrrr�=s

	r��__main__)*r�rZtest.supportr�rrrrrr�r�rr	r\r�Zurllib.requestr�Zurllib.errorrrqr"rrr�flags�no_siterrrrrZTestCaserr�rBr�r�r�rhr�r��mainrrrr�<module>sF
7D
k