Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_site.cpython-39.pyc

a

��g�j�@srdZddlZddlZddlmZddlmZddlmZmZmZm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZejjr�e�d��ddlZdad	d
�Zdd�Z Gd
d�dej!�Z"Gdd�de#�Z$Gdd�dej!�Z%Gdd�dej!�Z&e�'ej(dkd�Gdd�dej!��Z)e*dk�rne�+�dS)zTests for 'site'.

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

�N)�support)�
socket_helper)�captured_stderr�TESTFN�EnvironmentVarGuard�
change_cwd)�mock)�copyzPython was invoked with -Sc
Cs|tjdd�atjrxtj�tj�sxzt�tj�t�	tj�Wn8t
yv}z t�dtj|f��WYd}~n
d}~00dS)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.9/test/test_site.py�setUpModule)s�rcCsttjdd�<dS�N)rr
rrrrr�tearDownModule8src@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	de
fdd�Zdd�Zdd�Z
dd�Zdd�Zdd�Ze�eed�d�dd��Ze�ejdkd �d!d"��Zd#d$�Zd%d&�Ze�ejd'�d(d)��Zd*d+�Zd,d-�Zd.d/�Z d0d1�Z!d2S)3�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.setUpcCsV|jtjdd�<|jt_|jt_|jt_	|j
t_tjdurRtj�
�tj�|j�dS�zRestore sys.pathN)rr
rr r
rr!rr#r"r&r$r%�clear�updater'r(rrr�tearDownIs

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_makepathUsz"HelperFunctionsTests.test_makepathcCs8t��}dd�tjD�D]}|�||d||f�qdS)NcSs*g|]"}|rtj�|�rt�|�d�qS)�)rr�existsr
r0)�.0rrrr�
<listcomp>ds�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_pathinfobs��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)r;�importedr
�modulesr
r0�
good_dir_pathr�assertFalserr7�bad_dir_path�r)�pth_filerrr�pth_file_testsjs
�z#HelperFunctionsTests.pth_file_testscCsTt�}|jdd�z2|��t�|j|jt��|�|�W|��n
|��0dS�NT��prep)	�PthFile�cleanup�creater
�
addpackage�base_dir�filename�setrErCrrr�test_addpackageqsz$HelperFunctionsTests.test_addpackage�.csttj�|�}|d}tj�||��t�ddd��,}|��fdd��|�|�Wd�n1sb0Y||fS)N�.pth�w�utf-8)�encodingcs
t���Sr)r�remover��pth_fnrr�<lambda>��z/HelperFunctionsTests.make_pth.<locals>.<lambda>)rrr2r/�open�
addCleanup�write)r)�contents�pth_dirZpth_nameZpth_basenamerDrrWr�make_pth�s(zHelperFunctionsTests.make_pthc	Cs�|�d�\}}t�� }t�||t��Wd�n1s:0Y|�|��d�|�|��t�t	j
�||���|�|��d�|�|��d�|�|��d�dS)Nzimport bad-syntax
zline 1�	Tracebackzimport bad-syntax�SyntaxError�r`rr
rLrOZassertRegex�getvalue�re�escaperrr/�r)r_rX�err_outrrr�!test_addpackage_import_bad_syntax�s.
�z6HelperFunctionsTests.test_addpackage_import_bad_syntaxc	Cs�|�d�\}}t�� }t�||t��Wd�n1s:0Y|�|��d�|�|��t�t	j
�||���|�|��d�|�|��d�dS)Nzrandompath
import nosuchmodule
zline 2ra�ModuleNotFoundErrorrcrgrrr�test_addpackage_import_bad_exec�s.
�z4HelperFunctionsTests.test_addpackage_import_bad_execcCs�|�d�\}}t��&}|�t�||t���Wd�n1s@0Yd|_|�|��d�t	j
D]}t|t�rf|�
d|�qfdS)Nzabcdef
�zabcdef)r`rrAr
rLrOZmaxDiffr1rdr
r�
isinstance�str�assertNotIn)r)r_rXrhrrrr�#test_addpackage_import_bad_pth_file�s4

z8HelperFunctionsTests.test_addpackage_import_bad_pth_filecCsPt�}|jdd�z.|��t�|jt��|�|�W|��n
|��0dSrF)rIrJrKr
rrMrOrErCrrr�test_addsitedir�sz$HelperFunctionsTests.test_addsitedircCsrtd�}|jdd�zN|��t�|jt��|�t�|j	�dt
j�|�|jt
j�W|��n
|��0dS)Nz.dotfileTrGr)
rIrJrKr
rrMrOror0r@r
rr;rCrrr�test_addsitedir_dotfile�sz,HelperFunctionsTests.test_addsitedir_dotfile�chflagsztest needs os.chflags()cCs�t�}|jdd�zp|��t�|j�}t�|j|jtjB�t	�
|jt��|�
t	�|j�dtj�|�|jtj�W|��n
|��0dS)NTrGr)rIrJrKr�stat�	file_pathrs�st_flags�	UF_HIDDENr
rrMrOror0r@r
rr;)r)rD�strrr�test_addsitedir_hidden_flags�sz1HelperFunctionsTests.test_addsitedir_hidden_flags�win32ztest needs WindowscCs�t�}|jdd�z`|��t�dd|jg�t�|jt	��|�
t�|j�dt
j�|�|jt
j�W|��n
|��0dS)NTrGZattribz+Hr)rIrJrK�
subprocess�
check_callrur
rrMrOror0r@r
rr;rCrrr�%test_addsitedir_hidden_file_attribute�sz:HelperFunctionsTests.test_addsitedir_hidden_file_attributecCs|�t��t���dSr)r1r
�_getuserbaser$r(rrr�test__getuserbase�sz&HelperFunctionsTests.test__getuserbasecCsBtjdkrtjrd}n
tjd}|�t�t���t	�
d|��dS)N�darwinZosx_framework_user�_userZpurelib)r
�platform�
_frameworkr�namer1r
�	_get_pathr~r$Zget_path)r)�schemerrr�
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)��envr6z-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
rr;r
rr�environr	r{�call�
executabler1�getsitepackages)r)Zusersiter��rcrrr�
test_s_option�sP

��
��

���

���z"HelperFunctionsTests.test_s_optioncCs|dt_t��}|�tj|�dt_ddl}d|_t��2}d|d<|�t���d�t���Wd�n1sn0YdS)Nr�xoxor�)	r
r�getuserbaser1r$r%r�
assertTrue�
startswith)r)�	user_baser$r�rrr�test_getuserbases�z%HelperFunctionsTests.test_getuserbasecCsLdt_dt_t��}|�tj|�|�|�tj�|�|�tjt���dSr)r
rr�getusersitepackagesr1r�r�r�)r)�	user_siterrr�test_getusersitepackages*sz-HelperFunctionsTests.test_getusersitepackagescCs�dgt_t��}tjdkr�tjdkrh|�t|�d�tj	�
dtjdtjdd�d�}|�|d|�n|�t|�d�tj	�
dddtjdd�d�}|�|d	|�n@|�t|�d�|�|dd�tj	�
ddd�}|�|d|�dS)
Nr��/�lib�zpython%d.%dz
site-packagesrr6���)r
r"r�r�sepr
�
platlibdirr1�lenrr/�version_info)r)�dirsZwantedrrr�test_getsitepackages4s(

�
�z)HelperFunctionsTests.test_getsitepackagesc
Cshdt_dt_t���}t�ddd���V|d=|d=t��}|�|�dt	j
�|�t��}|�|�|�|�Wd�n1s�0YWd�n1s�0Ytjddd	���}tj�td
��l}t
�tdd��<t�}t�|�|�|�|��|�|�Wd�n1�s0YWd�n1�s:0YWd�n1�sZ0YdS)
Nzos.path.expandusercSs|Srr)rrrrrYTrZz=HelperFunctionsTests.test_no_home_directory.<locals>.<lambda>r��APPDATA�~z
os.path.isdirF)Zreturn_valuerrT)r
rrrrZpatchr�r�r�rr�r��objectrZ	swap_attrrO�addusersitepackagesZassert_called_once_withZassert_not_calledrA)r)r�r�r�Z
mock_isdirZmock_addsitedir�known_pathsrrr�test_no_home_directoryLs0��N��

z+HelperFunctionsTests.test_no_home_directoryN)"�__name__�
__module__�__qualname__�__doc__r*r.r5r=rErPrr`rirkrprqrrr�
skipUnless�hasattrrryr
r�r}rr�r
rr�r�r�r�r�rrrrr<s2	






'
rc@s4eZdZdZedddfdd�Zdd�Zd
d
d�ZdS)rIz/Helper class for handling testing of .pth files�timeZ__testdir__Z__badcCsj|d|_tj�d�|_tj�|j|j�|_||_||_||_	tj�|j|j�|_
tj�|j|j	�|_dS)zInitialize instance variablesrRrlN)rNrrr2rMr/rur>�good_dirname�bad_dirnamer@rB)r)�
filename_baser>r�r�rrr�__init__qs
zPthFile.__init__cCszt|jd�}zRtd|d�td|d�td|j|d�t|j|d�t|j|d�W|��n
|��0t�|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.

        rSz#import @bad module name��file�
z	import %sN)
r[ru�printr>r�r��closer�mkdirr@)r)�FILErrrrK}s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)
rrr7rurVr
r?�getr>Zimported_moduler@�rmdirrB)r)rHrrrrJ�szPthFile.cleanupN)F)r�r�r�r�rr�rKrJrrrrrIns�
rIc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	d
�dd��Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zej�d�ejje�eejd�d�dd����ZdS)�ImportSideEffectTestsz(Test side-effects from importing 'site'.cCstjdd�|_dS)zMake a copy of sys.pathN)r
rrr(rrrr*�szImportSideEffectTests.setUpcCs|jtjdd�<dSr+)rr
rr(rrrr.�szImportSideEffectTests.tearDowncCs*dtjd_t��|�tjdj�dS)z�Test for __cached__ is None.

        Regarding to PEP 3147, __cached__ can be None.

        See also: https://bugs.python.org/issue30167
        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
�removeduppathsrOr
rro�add)r)Z
seen_pathsrrrr�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)Nrzrr6Zcp�mbcszdid not alias mbcs)	r
r��locale�getdefaultlocaler��	encodings�aliases�values�fail)r)r��valuerrr�test_aliasing_mbcs�s
z(ImportSideEffectTests.test_aliasing_mbcscCs8dtjvr4zddl}Wnty(Yn0|�d�dS)N�
sitecustomizerz(sitecustomize not imported automatically)r
r?r��ImportErrorr�)r)r�rrr�test_sitecustomize_executed�s
z1ImportSideEffectTests.test_sitecustomize_executed�networkZHTTPSHandlerz$need SSL support to download licensec
Cs�tj��d}tjj|dd�}|�tjj�zbt�	|��Dtj�
|��}|��}Wd�n1sd0YWd�n1s�0YWn.tjj
y�}z|j}WYd}~n
d}~00|j|dd|d�dS)Nr6ZHEAD)�method��zCan't find )�msg)r��_Printer__data�split�urllib�requestZRequestr\�
urlcleanuprZtransient_internet�urlopenZgetcode�error�	HTTPError�coder1)r)�urlZreq�datar��errr�test_license_exists_at_url�sHz0ImportSideEffectTests.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�rrrrr��s$	



�r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�StartupImportTestsc
Cs8tjtjdddgtjdd�}|��d}|�|jdt|��t	|�}|D]<}t
�
tj�
t
�|�d��}|rH|�dt|��d	|���qHtjtjdd
ddgtjtjdd�}|��\}}|�|jd||f�t	|�}|�d
|�hd�}|�|�|�|�|�d||�|�d||�hd��tj�}	|�|�|	�|�dS)N�-Ir�z!import sys; print(repr(sys.path))rT)�stdoutrUrz*.pthzfound z .pth files in: z-vz#import sys; print(set(sys.modules)))r��stderrrUr
>�	sre_parse�
sre_constants�_srere�sre_compiler��copyreg>
�heapq�types�keyword�collections�_collections�weakref�	functools�reprlib�	itertools�operator)r{�Popenr
r��PIPE�communicater1�
returncode�repr�eval�globrrr/rfZskipTestr�r;rA�intersectionro�
difference�builtin_module_names)
r)�popenr�Zisolated_pathsrZ	pth_filesr�r?Zre_modsZcollection_modsrrr�test_startup_importss@�����z'StartupImportTests.test_startup_importscCs&t�tjddg���}|�|d�dS)Nr��9import sys; sys.exit(hasattr(sys, "__interactivehook__"))z''__interactivehook__' not added by site�r{rr
r��waitr��r)�rrrr�test_startup_interactivehook4s
�
z/StartupImportTests.test_startup_interactivehookcCs(t�tjdddg���}|�|d�dS)Nr�r�rz,'__interactivehook__' added in isolated mode)r{rr
r�rrArrrr�%test_startup_interactivehook_isolated9s�
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()rrrrr�.test_startup_interactivehook_isolated_explicit?s�
zAStartupImportTests.test_startup_interactivehook_isolated_explicitN)r�r�r�rrrrrrrrr�s0r�rzzonly supported on Windowsc@s6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�
_pthFileTestsTcCs�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�Wd�n1s�0Y|S)Nrr6z._pthrSr�)�_winapi�tempfile�mkdtempr\r�r�rmtreerrr/r�r
r�ZGetModuleFileNameZ	dllhandle�shutilr	�splitextr[r�)r)�lines�exe_pthrZtemp_dir�exe_fileZdll_src_fileZdll_fileZ	_pth_file�f�linerrr�_create_underpth_exeIs,z"_pthFileTests._create_underpth_execCsDg}|D]6}|r|ddkrqtj�tj�||��}|�|�q|S)Nr�#)rrr2r/�append)r)�
sys_prefixr rr$Zabs_pathrrr�"_calc_sys_path_for_underpth_nosite[sz0_pthFileTests._calc_sys_path_for_underpth_nositecs�tj�tj�tj���tj�tj�}dg�fdd�td�D��d�d�}|�|�}|�	tj�|�|�}tj
��}d|d<d	�|t�
d
��|d
<tj|ddg|d
d�}|���d�}|�|d�|�||d�dS)N�fake-path-namecsg|]}��qSrr�r8�_�Zlibpathrrr9irZz;_pthFileTests.test_underpth_nosite_file.<locals>.<listcomp>r�rl�	# comment�from-env�
PYTHONPATH�{};{}�PATHr�zCimport sys; print("\n".join(sys.path) if sys.flags.no_site else "")�ansi)r�rUr�zsys.flags.no_site was False�sys.path is incorrect)rr�dirnamer��__file__r
r��ranger%r)r�r	�format�getenvr{�check_output�rstripr�r�r1)r)�
exe_prefixZ	pth_linesr"rr��outputZactual_sys_pathrr-r�test_underpth_nosite_fileds<����

�
���z'_pthFileTests.test_underpth_nosite_filec
s�tj�tj�tj���tj�tj�}|�dg�fdd�td�D��d�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-rrr9�rZz4_pthFileTests.test_underpth_file.<locals>.<listcomp>r�rlr.�import siter/r0r1r2r���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�r4�rrr5r�r6r
r�r%r7r�r	r8r9r{r�r/r��r)r<r"r(r�r�rr-r�test_underpth_file�s8�����
����z _pthFileTests.test_underpth_filec
s�tj�tj�tj���tj�tj�}|jdg�fdd�td�D��d�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-rrr9�rZz8_pthFileTests.test_underpth_dll_file.<locals>.<listcomp>r�rlr.r?F)r!r/r0r1r2r�r@r�r4rArBrr-r�test_underpth_dll_file�s<������
����z$_pthFileTests.test_underpth_dll_fileN)T)r�r�r�r%r)r>rCrDrrrrrFs

	r�__main__),r�rZtest.supportr�rrrrrrr�r�rrrerrtr{r
r$rZurllib.errorr�Zurllib.requestrr	�flags�no_siterr
rrrZTestCaserr�rIr�r�r�r�rr��mainrrrr�<module>sH
47]Dk


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists