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_site.cpython-38.opt-2.pyc
U

>��g�h�@sbddlZddlZddlmZddlmZmZmZmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZddlmZejjr�e�d��ddlZdadd�Zd	d
�ZGdd�dej�Z Gd
d�de!�Z"Gdd�dej�Z#Gdd�dej�Z$e�%ej&dkd�Gdd�dej��Z'e(dk�r^e�)�dS)�N)�support)�captured_stderr�TESTFN�EnvironmentVarGuard�
change_cwd)�mock)�copyzPython was invoked with -Sc
Csztjdd�atjrvtj�tj�svzt�tj�t�	tj�Wn6t
k
rt}zt�dtj|f��W5d}~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�-/opt/cppython/lib/python3.8/test/test_site.py�setUpModule(s�rcCsttjdd�<dS�N)rr	r
rrrr�tearDownModule7src@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
e	fdd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Ze�eed�d�dd��Ze�ejdkd�d d!��Zd"d#�Zd$d%�Ze�ejd&�d'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1S)2�HelperFunctionsTestscCs@tjdd�|_tj|_tj|_tj|_	t
j|_t
t
j�|_dSr)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�dSr)rr	r
rrrr rr"r!r%r#r$�clear�updater&r'rrr�tearDownHs
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_makepathRsz"HelperFunctionsTests.test_makepathcCs8t��}dd�tjD�D]}|�||d||f�qdS)NcSs*g|]"}|rtj�|�rt�|�d�qS)�)rr
�existsrr.)�.0r
rrr�
<listcomp>as�z;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)Nz%s not in sys.modulesr)r9�importedr	�modulesrr.�
good_dir_pathr
�assertFalserr5�bad_dir_path�r(�pth_filerrr�pth_file_testsgs
�z#HelperFunctionsTests.pth_file_testscCsLt�}|jdd�z*|��t�|j|jt��|�|�W5|��XdS�NT��prep)	�PthFile�cleanup�creater�
addpackage�base_dir�filename�setrCrArrr�test_addpackagensz$HelperFunctionsTests.test_addpackage�.c	s`tj�|�}|d}tj�||��t�ddd��"}|��fdd��|�|�W5QRX||fS)N�.pth�w�utf-8)�encodingcs
t���Sr)r�remover��pth_fnrr�<lambda>��z/HelperFunctionsTests.make_pth.<locals>.<lambda>)rr
r0r-�open�
addCleanup�write)r(�contents�pth_dirZpth_nameZpth_basenamerBrrUr�make_pth}szHelperFunctionsTests.make_pthc	Cs�|�d�\}}t��}t�||t��W5QRX|�|��d�|�|��t�t	j
�||���|�|��d�|�|��d�|�|��d�dS)Nzimport bad-syntax
zline 1�	Tracebackzimport bad-syntax�SyntaxError�r^rrrJrMZassertRegex�getvalue�re�escaperr
r-�r(r]rV�err_outrrr�!test_addpackage_import_bad_syntax�s
�z6HelperFunctionsTests.test_addpackage_import_bad_syntaxc	Cs�|�d�\}}t��}t�||t��W5QRX|�|��d�|�|��t�t	j
�||���|�|��d�|�|��d�dS)Nzrandompath
import nosuchmodule
zline 2r_�ModuleNotFoundErrorrarerrr�test_addpackage_import_bad_exec�s
�z4HelperFunctionsTests.test_addpackage_import_bad_execc	Csr|�d�\}}t��}|�t�||t���W5QRXd|_|�|��d�t	j
D]}t|t�rR|�
d|�qRdS)Nzabcdef
�zabcdef)r^rr?rrJrMZmaxDiffr/rbr	r
�
isinstance�str�assertNotIn)r(r]rVrfr
rrr�#test_addpackage_import_bad_pth_file�s 

z8HelperFunctionsTests.test_addpackage_import_bad_pth_filecCsHt�}|jdd�z&|��t�|jt��|�|�W5|��XdSrD)rGrHrIrrrKrMrCrArrr�test_addsitedir�sz$HelperFunctionsTests.test_addsitedircCsjtd�}|jdd�zF|��t�|jt��|�t�|j	�dt
j�|�|jt
j�W5|��XdS)Nz.dotfileTrEr)
rGrHrIrrrKrMrmr.r>r	r
r9rArrr�test_addsitedir_dotfile�sz,HelperFunctionsTests.test_addsitedir_dotfile�chflagsztest needs os.chflags()cCs�t�}|jdd�zh|��t�|j�}t�|j|jtjB�t	�
|jt��|�
t	�|j�dtj�|�|jtj�W5|��XdS)NTrEr)rGrHrIr�stat�	file_pathrq�st_flags�	UF_HIDDENrrrKrMrmr.r>r	r
r9)r(rB�strrr�test_addsitedir_hidden_flags�sz1HelperFunctionsTests.test_addsitedir_hidden_flags�win32ztest needs WindowscCszt�}|jdd�zX|��t�dd|jg�t�|jt	��|�
t�|j�dt
j�|�|jt
j�W5|��XdS)NTrEZattribz+Hr)rGrHrI�
subprocess�
check_callrsrrrKrMrmr.r>r	r
r9rArrr�%test_addsitedir_hidden_file_attribute�sz:HelperFunctionsTests.test_addsitedir_hidden_file_attributecCs|�t��t���dSr)r/r�_getuserbaser#r'rrr�test__getuserbase�sz&HelperFunctionsTests.test__getuserbasecCsBtjdkrtjrd}n
tjd}|�t�t���t	�
d|��dS)N�darwinZosx_framework_user�_userZpurelib)r	�platform�
_frameworkr�namer/r�	_get_pathr|r#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)N�-cz$import sys; sys.exit(%r in sys.path)��envr4z-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rr9r	r
r�environrry�call�
executabler/�getsitepackages)r(Zusersiter��rcrrr�
test_s_option�sP

��
��

���

���z"HelperFunctionsTests.test_s_optionc	Cshdt_t��}|�tj|�dt_ddl}d|_t��(}d|d<|�t���d�t���W5QRXdS)Nr�xoxor�)	rr�getuserbaser/r#r$r�
assertTrue�
startswith)r(�	user_baser#r�rrr�test_getuserbases�z%HelperFunctionsTests.test_getuserbasecCsLdt_dt_t��}|�tj|�|�|�tj�|�|�tjt���dSr)rrr�getusersitepackagesr/r�r�r�)r(�	user_siterrr�test_getusersitepackages'sz-HelperFunctionsTests.test_getusersitepackagescCs�dgt_t��}tjdkr\|�t|�d�tj�dddt	j
dd�d�}|�|d|�n@|�t|�d�|�|dd�tj�ddd�}|�|d|�dS)	Nr��/r4�libzpython%d.%d�z
site-packagesr)rr!r�r�sepr/�lenr
r-r	�version_info)r(�dirsZwantedrrr�test_getsitepackages1s

�z)HelperFunctionsTests.test_getsitepackagescCs�dt_dt_t��h}t�ddd���L|d=|d=t��}|�|�dt	j
�|�t��}|�|�|�|�W5QRXW5QRXtjddd	��f}tj�td
��L}t
�tdd��2t�}t�|�|�|�|��|�|�W5QRXW5QRXW5QRXdS)
Nzos.path.expandusercSs|Srr)r
rrrrWJrXz=HelperFunctionsTests.test_no_home_directory.<locals>.<lambda>r��APPDATA�~z
os.path.isdirF)Zreturn_valuerr
T)rrrrrZpatchr�r�r�rr�r��objectrZ	swap_attrrM�addusersitepackagesZassert_called_once_withZassert_not_calledr?)r(r�r�r�Z
mock_isdirZmock_addsitedir�known_pathsrrr�test_no_home_directoryBs0��&��

z+HelperFunctionsTests.test_no_home_directoryN)!�__name__�
__module__�__qualname__r)r,r3r;rCrNrr^rgrirnrorpr�
skipUnless�hasattrrrwr	r�r{r}r�rr
r�r�r�r�r�rrrrr;s0	







'
rc@s0eZdZedddfdd�Zdd�Zdd	d
�ZdS)
rG�timeZ__testdir__Z__badcCsj|d|_tj�d�|_tj�|j|j�|_||_||_||_	tj�|j|j�|_
tj�|j|j	�|_dS)NrPrj)rLrr
r0rKr-rsr<�good_dirname�bad_dirnamer>r@)r(�
filename_baser<r�r�rrr�__init__gs
zPthFile.__init__cCsrt|jd�}zJtd|d�td|d�td|j|d�t|j|d�t|j|d�W5|��Xt�|j	�dS)NrQz#import @bad module name��file�
z	import %s)
rYrs�close�printr<r�r�r�mkdirr>)r(�FILErrrrIss
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�dSr)
rr
r5rsrTr	r=�getr<Zimported_moduler>�rmdirr@)r(rFrrrrH�szPthFile.cleanupN)F)r�r�r�rr�rIrHrrrrrGds�
rGc@s�eZdZdd�Zdd�Zdd�Zdd�Ze�d	�d
d��Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zej�d�ejje�eejd�d�dd����ZdS)�ImportSideEffectTestscCstjdd�|_dSr)r	r
rr'rrrr)�szImportSideEffectTests.setUpcCs|jtjdd�<dSr)rr	r
r'rrrr,�szImportSideEffectTests.tearDowncCs*dtjd_t��|�tjdj�dS)N�test)r	r=�
__cached__r�	abs_pathsZassertIsNoner'rrr�test_abs_paths_cached_None�sz0ImportSideEffectTests.test_abs_paths_cached_NonecCs4t��t�}tjD]}|�||�|�|�qdSr)r�removeduppathsrMr	r
rm�add)r(Z
seen_pathsr
rrr�test_no_duplicate_paths�s

z-ImportSideEffectTests.test_no_duplicate_pathsztest not implementedcCsdSrrr'rrr�test_add_build_dir�sz(ImportSideEffectTests.test_add_build_dircCs$|�ttd��|�ttd��dS)N�quit�exit�r�r��builtinsr'rrr�test_setting_quit�sz'ImportSideEffectTests.test_setting_quitcCs4|�ttd��|�ttd��|�ttd��dS)N�	copyright�credits�licenser�r'rrr�test_setting_copyright�sz,ImportSideEffectTests.test_setting_copyrightcCs|�ttd��dS)N�helpr�r'rrr�test_setting_help�sz'ImportSideEffectTests.test_setting_helpcCsPtjdkrLddl}|��d�d�rLtjj��D]}|dkr0qLq0|�d�dS)Nrxrr4Zcp�mbcszdid not alias mbcs)	r	r��locale�getdefaultlocaler��	encodings�aliases�values�fail)r(r��valuerrr�test_aliasing_mbcs�s
z(ImportSideEffectTests.test_aliasing_mbcscCs:dtjkr6z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_executedZnetworkZHTTPSHandlerz$need SSL support to download licensec
Cs�tj��d}tjj|dd�}|�tjj�z<tj	�
|��&tj�|��}|��}W5QRXW5QRXWn,tj
jk
r�}z
|j}W5d}~XYnX|j|dd|d�dS)Nr4ZHEAD)�method��zCan't find )�msg)r��_Printer__data�split�urllib�requestZRequestrZ�
urlcleanupr�rZtransient_internet�urlopenZgetcode�error�	HTTPError�coder/)r(ZurlZreq�datar��errr�test_license_exists_at_url�s z0ImportSideEffectTests.test_license_exists_at_urlN)r�r�r�r)r,r�r�r�skipr�r�r�r�r�r�r�rZrequires_resourceZsystem_must_validate_certr�r�r�r�r�rrrrr��s"	



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

CsNtjtjdddgtjdd�}|��d}|�|jdt|��t	|�}|D]<}t
�
tj�
t
�|�d��}|rH|�dt|��d	|���qHtjtjdd
ddgtjtjdd�}|��\}}|�|jd||f�t	|�}|�d
|�dddddh}|�|�|�|�|�d||�|�d||�ddddddddddh
�tj�}	|�|�|	�|�dS)N�-Ir�z!import sys; print(repr(sys.path))rR)�stdoutrSrz*.pthzfound z .pth files in: z-vz#import sys; print(set(sys.modules)))r��stderrrSrrc�_sre�sre_compile�
sre_constants�	sre_parser��copyreg�_collections�collections�	functools�heapq�	itertools�keyword�operator�reprlib�types�weakref)ry�Popenr	r��PIPE�communicater/�
returncode�repr�eval�globrr
r-rdZskipTestr�r9r?�intersectionrm�
difference�builtin_module_names)
r(�popenr�Zisolated_pathsr
Z	pth_filesr�r=Zre_modsZcollection_modsrrr�test_startup_imports�sP������z'StartupImportTests.test_startup_importscCs&t�tjddg���}|�|d�dS)Nr��9import sys; sys.exit(hasattr(sys, "__interactivehook__"))z''__interactivehook__' not added by site�ryr�r	r��waitr��r(�rrrr�test_startup_interactivehook*s
�
z/StartupImportTests.test_startup_interactivehookcCs(t�tjdddg���}|�|d�dS)Nr�r�r	z,'__interactivehook__' added in isolated mode)ryr�r	r�rr?rrrr�%test_startup_interactivehook_isolated/s�
z8StartupImportTests.test_startup_interactivehook_isolatedcCs(t�tjdddg���}|�|d�dS)Nr�r�zYimport site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))z6'__interactivehook__' not added by enablerlcompleter()r
rrrr�.test_startup_interactivehook_isolated_explicit5s�
zAStartupImportTests.test_startup_interactivehook_isolated_explicitN)r�r�r�rrrrrrrrr��s0r�rxzonly 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��}	|D]}
t|
|	d�q�W5QRX|S)Nrr4z._pthrQr�)�_winapi�tempfile�mkdtemprZr�r�rmtreerr
r-r�r	r�ZGetModuleFileNameZ	dllhandle�shutilr�splitextrYr�)r(�lines�exe_pthrZtemp_dir�exe_fileZdll_src_fileZdll_fileZ	_pth_file�f�linerrr�_create_underpth_exe?sz"_pthFileTests._create_underpth_execCsDg}|D]6}|r|ddkrqtj�tj�||��}|�|�q|S)Nr�#)rr
r0r-�append)r(�
sys_prefixrrrZabs_pathrrr�"_calc_sys_path_for_underpth_nositeQs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�r6�_�Zlibpathrrr7_sz;_pthFileTests.test_underpth_nosite_file.<locals>.<listcomp>r�rj�	# comment�from-env�
PYTHONPATH�{};{}�PATHr�zCimport sys; print("\n".join(sys.path) if sys.flags.no_site else "")�ansi)r�rSr�zsys.flags.no_site was False�sys.path is incorrect)r")rjr&)rr
�dirnamer��__file__r	r��rangerr!r�r�format�getenvry�check_output�rstripr�r�r/)r(�
exe_prefixZ	pth_linesrrr��outputZactual_sys_pathrr%r�test_underpth_nosite_fileZs:��

�
���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)Nr"csg|]}��qSrrr#r%rrr7{sz4_pthFileTests.test_underpth_file.<locals>.<listcomp>r�rjr&�import siter'r(r)r*r���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))r�r,)r")rjr&r7�rr
r-r�r.r	r�rr/r�rr0r1ryr�r-r��r(r4rr r�r�rr%r�test_underpth_filevs2��
����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)Nr"csg|]}��qSrrr#r%rrr7�sz8_pthFileTests.test_underpth_dll_file.<locals>.<listcomp>r�rjr&r7F)rr'r(r)r*r�r8r�r,)r")rjr&r7r9r:rr%r�test_underpth_dll_file�s6���
����z$_pthFileTests.test_underpth_dll_fileN)T)r�r�r�rr!r6r;r<rrrrr<s

	r�__main__)*rZtest.supportr�rrrrrr�rrr	rcr�Zurllib.requestr�Zurllib.errorrrrryr#rrr�flags�no_siterrrrrZTestCaserr�rGr�r�r�r�rr��mainrrrr�<module>sD
+7]Dk


F1le Man4ger