
    6\hIw                     2   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ dd	lmZ ej        j        r ej         d
          ddl!Z!e!j"        duZ#da$d Z%d Z& G d dej'                  Z( G d de)          Z* G d dej'                  Z+ G d dej'                  Z, G d dej'                  Z-e.dk    r ej/                     dS dS )zTests for 'site'.

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

    N)support)	os_helper)socket_helper)captured_stderr)TESTFNEnvironmentVarGuard
change_cwd)mock)copyzPython was invoked with -Sc                     t           j        d d          at          j        rt
          j                            t          j                  sw	 t          j        t          j                   t          j	        t          j                   d S # t          $ r)} t          j        dt          j        d|           d } ~ ww xY wd S d S )Nz&unable to create user site directory (z): )syspathOLD_SYS_PATHsiteENABLE_USER_SITEosisdir	USER_SITEmakedirs
addsitedirPermissionErrorunittestSkipTest)excs    8/opt/python-3.11.14/usr/lib/python3.11/test/test_site.pysetUpModuler   -   s    8AAA;L =RW]]4>%B%B =	=K'''ODN+++++ 	= 	= 	=##'+~~~ss%< = = =	== = = =s   <B	 	
B<$B77B<c                  2    t           t          j        d d <   d S N)r   r   r        r   tearDownModuler!   <   s    CHQQQKKKr    c                   h   e Zd ZdZd Zd Zd Zd Zd Zd Z	de
fd	Zd
 Zd Zd Zd Zd Zd Z ej         eed          d          d             Z ej        ej        dk    d           ej                    d                         Zd Z ej        ed          d             Z ej        ej         d           ej                    d                         Z! ej        ed          d             Z" ej        ed          d             Z#d Z$ ej        ed          d             Z%d Z&d S )!HelperFunctionsTestsz Tests for helper functions.
    c                     t           j        dd         | _        t          j        | _        t          j        | _        t          j        | _	        t          j        | _        t          t          j                  | _        dS )zSave 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selfs    r   setUpzHelperFunctionsTests.setUpD   sP     M&3Y344r    c                 Z   | j         t          j        dd<   | j        t          _        | j        t          _        | j        t          _	        | j
        t          _        t          j        Dt          j                                         t          j                            | j                   dS dS zRestore sys.pathN)r%   r   r   r'   r   r&   r(   r   r*   r)   r-   r+   r,   clearupdater.   r/   s    r   tearDownzHelperFunctionsTests.tearDownM   s    m)!%!3	!-"((***"))$-88888 .-r    c                    d}t          j        j        | }t          j        | \  }}|                     t           j                            |          |           |t           j                            |          k    r|                     ||           d S |                     t           j                            |          |           d S )N)	BeginningEnd)r   r   joinr   makepathassertEqualabspathnormcase)r0   
path_partsoriginal_dirabs_dirnorm_dirs        r   test_makepathz"HelperFunctionsTests.test_makepathY   s     *
w|Z0 M:666@@@27++L9999Wh/////RW--g66AAAAAr    c                     t          j                    }d t          j        D             D ]}|                     |||d|           d S )Nc                     g | ]=}|t           j                            |          #t          j        |          d          >S )   )r   r   existsr   r;   ).0r   s     r   
<listcomp>z;HelperFunctionsTests.test_init_pathinfo.<locals>.<listcomp>h   sQ     : : ::$&GNN4$8$8:dmD))!, : : :r    z> from sys.path not found in set returned by _init_pathinfo(): )r   _init_pathinfor   r   assertIn)r0   dir_setentrys      r   test_init_pathinfoz'HelperFunctionsTests.test_init_pathinfof   s{    %'': : : : : 	H 	HEMM%7<uuggGH H H H	H 	Hr    c                 J   |                      |j        t          j        d|j        z             |                      t	          j        |j                  d         t          j                   |                     t          j        
                    |j                             dS )z>Contain common code for testing results of reading a .pth filez%s not in sys.modulesr   N)rK   importedr   modulesr   r;   good_dir_pathr   assertFalser   rG   bad_dir_pathr0   pth_files     r   pth_file_testsz#HelperFunctionsTests.pth_file_testsn   s    h'-0AA	C 	C 	CdmH$:;;A>III(=>>?????r    c                 T   t                      }|                    d           	 |                                 t          j        |j        |j        t                                 |                     |           |                                 d S # |                                 w xY wNTprep)	PthFilecleanupcreater   
addpackagebase_dirfilenamesetrW   rU   s     r   test_addpackagez$HelperFunctionsTests.test_addpackageu   s    
 99d###	OOOH-x/@#%%HHH)))Hs   AB B'.c                 B   t           j                            |          }|dz   }t           j                            ||          t	          dd          5 }|                     fd           |                    |           d d d            n# 1 swxY w Y   ||fS )N.pthwutf-8encodingc                  ,    t          j                   S r   )r   remove)pth_fns   r   <lambda>z/HelperFunctionsTests.make_pth.<locals>.<lambda>   s    BIf$5$5 r    )r   r   r=   r:   open
addCleanupwrite)r0   contentspth_dirpth_namepth_basenamerV   rm   s         @r   make_pthzHelperFunctionsTests.make_pth   s    '//'**&(g|44&#000 	%HOO5555666NN8$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% $$s   .BBBc           	         |                      d          \  }}t                      5 }t          j        ||t	                                 d d d            n# 1 swxY w Y   |                     |                                d           |                     |                                t          j        t          j
                            ||                               |                     |                                d           |                     |                                d           |                     |                                d           d S )Nzimport bad-syntax
zline 1	Tracebackzimport bad-syntaxSyntaxErrorrv   r   r   r_   rb   assertRegexgetvaluereescaper   r   r:   r0   rs   rm   err_outs       r   !test_addpackage_import_bad_syntaxz6HelperFunctionsTests.test_addpackage_import_bad_syntax   sb   --(=>> 	4'OGVSUU333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4))++X666))++Ibgll7F3344	6 	6 	6
 	))++[999))++-ABBB))++];;;;;   #AAAc           	      f   |                      d          \  }}t                      5 }t          j        ||t	                                 d d d            n# 1 swxY w Y   |                     |                                d           |                     |                                t          j        t          j
                            ||                               |                     |                                d           |                     |                                d           d S )Nzrandompath
import nosuchmodule
zline 2rx   ModuleNotFoundErrorrz   r   s       r   test_addpackage_import_bad_execz4HelperFunctionsTests.test_addpackage_import_bad_exec   s@   --(KLL 	4'OGVSUU333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4))++X666))++Ibgll7F3344	6 	6 	6 	))++[999))++-BCCCCCr   c                     |                      d          \  }}t          j        ||t                                }|                     |t                                 d S )Nz

  

)rv   r   r_   rb   r<   )r0   rs   rm   known_pathss       r   test_addpackage_empty_linesz0HelperFunctionsTests.test_addpackage_empty_lines   sN    --55ogvsuu==cee,,,,,r    c           	         |                      d          \  }}t                      5 }|                     t          j        ||t                                           d d d            n# 1 swxY w Y   d | _        |                     |                                d           t          j
        D ]-}t          |t                    r|                     d|           .d S )Nzabc def
 zabc def)rv   r   rS   r   r_   rb   maxDiffr<   r|   r   r   
isinstancestrassertNotIn)r0   rs   rm   r   r   s        r   #test_addpackage_import_bad_pth_filez8HelperFunctionsTests.test_addpackage_import_bad_pth_file   s   --77 	F'T_WfceeDDEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F))++R000H 	5 	5D$$$ 5  t444	5 	5s   6A))A-0A-c                 H   t                      }|                    d           	 |                                 t          j        |j        t                                 |                     |           |                                 d S # |                                 w xY wrY   )r\   r]   r^   r   r   r`   rb   rW   rU   s     r   test_addsitedirz$HelperFunctionsTests.test_addsitedir   s     99d###	OOOH-suu555)))Hs   AB B!c                    t          d          }|                    d           	 |                                 t          j        |j        t                                 |                     t          j        |j	                  d         t          j                   |                     |j        t          j                   |                                 d S # |                                 w xY w)Nz.dotfileTrZ   r   )r\   r]   r^   r   r   r`   rb   r   r;   rR   r   r   rK   rU   s     r   test_addsitedir_dotfilez,HelperFunctionsTests.test_addsitedir_dotfile   s    :&&d###	OOOH-suu555T]8+ABB1EsxPPPMM(+SX666Hs   BC C/chflagsztest needs os.chflags()c                 l   t                      }|                    d           	 |                                 t          j        |j                  }t          j        |j        |j        t          j        z             t          j
        |j        t                                 |                     t          j        |j                  d         t           j                   |                     |j        t           j                   |                                 d S # |                                 w xY w)NTrZ   r   )r\   r]   r^   r   stat	file_pathr   st_flags	UF_HIDDENr   r   r`   rb   r   r;   rR   r   r   rK   )r0   rV   sts      r   test_addsitedir_hidden_flagsz1HelperFunctionsTests.test_addsitedir_hidden_flags   s    99d###	OO+,,BJx)2;+GHHHOH-suu555T]8+ABB1EsxPPPMM(+SX666Hs   C!D D3win32ztest needs Windowsc                    t                      }|                    d           	 |                                 t          j        dd|j        g           t          j        |j        t                                 | 
                    t          j        |j                  d         t          j                   |                     |j        t          j                   |                                 d S # |                                 w xY w)NTrZ   attribz+Hr   )r\   r]   r^   
subprocess
check_callr   r   r   r`   rb   r   r;   rR   r   r   rK   rU   s     r   %test_addsitedir_hidden_file_attributez:HelperFunctionsTests.test_addsitedir_hidden_file_attribute   s     99d###	OO!8T83E"FGGGOH-suu555T]8+ABB1EsxPPPMM(+SX666Hs   B8C4 4D
c                 v    |                      t          j                    t          j                               d S r   )r<   r   _getuserbaser+   r/   s    r   test__getuserbasez&HelperFunctionsTests.test__getuserbase   s0    *,,i.D.F.FGGGGGr    zneed user sitec                 4   t           j        dk    rt           j        rd}nt          j        dz   }|                     t          j                            t          j	        t          j
                                        t          j        d|                     d S )Ndarwinosx_framework_user_userpurelib)r   platform
_frameworkr   namer<   r   normpathr   	_get_pathr   r+   get_path)r0   schemes     r   test_get_pathz"HelperFunctionsTests.test_get_path   s    <8###)FFWw&F))$.9J9L9L*M*MNN"+Iv>>	@ 	@ 	@ 	@ 	@r    z<requires access to PEP 370 user-site (site.ENABLE_USER_SITE)c                 N   t           j                            t          j                  }|                     |t          j                   t           j                                        }t          j
        t          j        dd|z  g|          }|                     |d           t           j                                        }t          j
        t          j        ddd|z  g|          }|t          j                    d         k    r|                     |d           n|                     |dd           t           j                                        }d|d	<   t          j
        t          j        dd|z  g|          }|t          j                    d         k    r|                     |d           n|                     |dd
           t           j                                        }d|d<   t          j
        t          j        ddg|          }|                     |dd           d S )N-cz$import sys; sys.exit(%r in sys.path)envrF   z-sr   z%User site still added to path with -s1PYTHONNOUSERSITEz3User 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   r   r   r   r   rK   r   environr   r   call
executabler<   getsitepackages)r0   usersiter   rcs       r   test_s_optionz"HelperFunctionsTests.test_s_option   s!   
 7##DN33h)))joo_cnd2X=?   	Qjoo_cndD2X=?   t+--a000R####R$KLLLjoo"%_cnd2X=?   t+--a000R####RMO O O joo &_cndKM   	Q=	? 	? 	? 	? 	?r    c                    d t           _        t          j                    }|                     t           j        |           d t           _        dd l}d |_        t                      5 }d|d<   |                     t          j                                        d          t          j                               d d d            d S # 1 swxY w Y   d S )Nr   xoxor   )	r   r&   getuserbaser<   r+   r,   r   
assertTrue
startswith)r0   	user_baser+   r   s       r   test_getuserbasez%HelperFunctionsTests.test_getuserbase&  s   $&&	 	333 !%	 "" 	0g(.G$%OOD,..99&AA ,..0 0 0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   %ACC
Cc                 d   d t           _        d t           _        t          j                    }|                     t           j        |           |                     |                    t           j                  |           |                     t           j        t          j                               d S r   )r   r   r&   getusersitepackagesr<   r   r   r   )r0   	user_sites     r   test_getusersitepackagesz-HelperFunctionsTests.test_getusersitepackages8  s    ,..	 	333	,,T^<<iHHH)9););<<<<<r    c                    dgt           _        t          j                    }t          j        dk    r	t
          j        dk    r|                     t          |          d           t          j	        
                    dt
          j        dt
          j        d d         z  d          }|                     |d         |           n#|                     t          |          d           t          j	        
                    dddt
          j        d d         z  d          }|                     |d	         |           d S |                     t          |          d           |                     |d         d           t          j	        
                    ddd          }|                     t          j	                            |d                   t          j	                            |                     d S )
Nr   /lib   zpython%d.%dzsite-packagesr   rF   )r   r)   r   r   sepr   
platlibdirr<   lenr   r:   version_infor>   )r0   dirswanteds      r   test_getsitepackagesz)HelperFunctionsTests.test_getsitepackagesC  s   #%%6S==~&&  TA...fcn&3c6Frr6J&J&57 7   a&1111  TA...W\\&%"/#2B2A22F"F"13 3F T"Xv..... SYY***T!Wf---W\\&%AAFRW--d1g66W--f557 7 7 7 7r    c                    d t           _        d t           _        t                      5 }t	          j        dd           5  |d= |d= t          j                    }|                     |                    dt          j
        z             |           t          j                    }|                     |                    |          |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t	          j        dd          5 }t          j                            t           d	          5 }t          j        t           d
d          5  t                      }t          j        |           |                    |           |                                 |                     |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nzos.path.expanduserc                     | S r   r   )r   s    r   rn   z=HelperFunctionsTests.test_no_home_directory.<locals>.<lambda>e  s    4 r    r   APPDATA~zos.path.isdirF)return_valuer   r   T)r   r   r&   r   r
   patchr   r   r   r   r   r   objectr   	swap_attrrb   addusersitepackagesassert_called_once_withassert_not_calledrS   )r0   r   r   r   
mock_isdirmock_addsitedirr   s          r   test_no_home_directoryz+HelperFunctionsTests.test_no_home_directory\  s#   
  "" 	HgZ,.?.?@@	H 	H ()	"(**IOOI00rv>>%' ' ' 022IOOI00;;YGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H Ze<<< 	*
Zt\22	*6Et%7>>	* 	* %%K$[111..y999--///[)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   C-BC
C-C	C-C	C--C14C1&G,4GA!F=1G=GGGGG,G	G,G	G,,G03G0c                    d}d|dz   fdfD ]\  }}t          j        dt          j        |                    5  t          j        dt          j                              5  t          j        |           |                     t          j	        
                                |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nzbla-bla-blaT
)Fr   z	sys.flags)verbosez
sys.stderr)r
   r   MockioStringIOr   _tracer<   r   stderrr|   )r0   messager   outs       r   
test_tracezHelperFunctionsTests.test_trace~  sH   !7T>2K? 	= 	=LGSK7)C)C)CDD = =J|R[]];;= =G$$$  !4!4!6!6<<<= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =	= 	=s6   'C
 AB3'C
3B77C
:B7;C

C	C	N)'__name__
__module____qualname____doc__r1   r6   rC   rN   rW   rc   r   rv   r   r   r   r   r   r   r   
skipUnlesshasattrr   r   r   r   r   requires_subprocessr   r   HAS_USER_SITEr   r   r   r   r   r   r   r   r   r   r    r   r#   r#   @   s        5 5 5
9 
9 
9B B BH H H@ @ @   *-v % % % %< < <
D 
D 
D- - -	5 	5 	5  	 	 	 XY//1JKK  LK X02FGG W ""
 
 #" HG
H H H X(899@ @ :9@ X. 1> ? ? W ""%? %? #"? ?%?N X(8990 0 :90" X(899= = :9=7 7 72 X(899* * :9*B= = = = =r    r#   c                   0    e Zd ZdZedddfdZd Zd
dZd	S )r\   z/Helper class for handling testing of .pth filestime__testdir____badc                    |dz   | _         t          j                            d          | _        t          j                            | j        | j                   | _        || _        || _        || _	        t          j                            | j        | j                  | _
        t          j                            | j        | j	                  | _        dS )zInitialize instance variablesrf   r   N)ra   r   r   r=   r`   r:   r   rP   good_dirnamebad_dirnamerR   rT   )r0   filename_baserP   r   r   s        r   __init__zPthFile.__init__  s     &.++dmT]CC (&W\\$-9JKKGLL8HIIr    c                    t          | j        d          }	 t          d|           t          d|           t          d| j        z  |           t          | j        |           t          | j        |           |                                 n# |                                 w xY wt          j        | j	                   dS )ao  Create 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.

        rg   z#import @bad module namefiler   z	import %sN)
ro   r   printrP   r   r   closer   mkdirrR   )r0   FILEs     r   r^   zPthFile.create  s     DNC((	,48888$T""""+-D9999$#$////$"....JJLLLLDJJLLLL
#$$$$$s   A'B B)Fc                 B   t           j                            | j                  rt          j        | j                   |rCt
          j                            | j                  | _	        | j	        rt
          j        | j        = n | j	        r| j	        t
          j        | j        <   t           j                            | j
                  rt          j        | j
                   t           j                            | j                  rt          j        | j                   dS dS )zMake 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)r   r   rG   r   rl   r   rQ   getrP   imported_modulerR   rmdirrT   )r0   r[   s     r   r]   zPthFile.cleanup  s     7>>$.)) 	&Idn%%% 	B#&;??4=#A#AD # /K.# B-1-ADM*7>>$,-- 	)HT'(((7>>$+,, 	(HT&'''''	( 	(r    N)F)r   r   r   r   r   r   r^   r]   r   r    r   r\   r\     s_        99%+f!.G
J 
J 
J 
J% % %,( ( ( ( ( (r    r\   c                   *   e Zd ZdZd Zd Zd Zd Z ej	        d          d             Z
d Zd	 Zd
 Zd Z ej         eej        d          d          ej                            d          ej        j        d                                     ZdS )ImportSideEffectTestsz(Test side-effects from importing 'site'.c                 8    t           j        dd         | _        dS )zMake a copy of sys.pathN)r   r   r%   r/   s    r   r1   zImportSideEffectTests.setUp  s    r    c                 2    | j         t          j        dd<   dS r3   )r%   r   r   r/   s    r   r6   zImportSideEffectTests.tearDown  s    mr    c                     dt           j        d         _        t          j                     |                     t           j        d         j                   dS )zTest for __cached__ is None.

        Regarding to PEP 3147, __cached__ can be None.

        See also: https://bugs.python.org/issue30167
        Ntest)r   rQ   
__cached__r   	abs_pathsassertIsNoner/   s    r   test_abs_paths_cached_Nonez0ImportSideEffectTests.test_abs_paths_cached_None  sE     *.F&#+f-899999r    c                     t          j                     t                      }t          j        D ]-}|                     ||           |                    |           .d S r   )r   removeduppathsrb   r   r   r   add)r0   
seen_pathsr   s      r   test_no_duplicate_pathsz-ImportSideEffectTests.test_no_duplicate_paths  sb     	UU
H 	! 	!DT:...NN4    	! 	!r    ztest not implementedc                     d S r   r   r/   s    r   test_add_build_dirz(ImportSideEffectTests.test_add_build_dir  s	    
 	r    c                     |                      t          t          d                     |                      t          t          d                     d S )Nquitexitr   r   builtinsr/   s    r   test_setting_quitz'ImportSideEffectTests.test_setting_quit  s@    &11222&1122222r    c                     |                      t          t          d                     |                      t          t          d                     |                      t          t          d                     d S )N	copyrightcreditslicenser   r/   s    r   test_setting_copyrightz,ImportSideEffectTests.test_setting_copyright  s\    +66777)44555)4455555r    c                 V    |                      t          t          d                     d S )Nhelpr   r/   s    r   test_setting_helpz'ImportSideEffectTests.test_setting_help  s$    &1122222r    c                 |    dt           j        vr-	 dd l}|                     d           d S # t          $ r Y d S w xY wd S )Nsitecustomizer   z(sitecustomize not imported automatically)r   rQ   r,  failImportError)r0   r,  s     r   test_sitecustomize_executedz1ImportSideEffectTests.test_sitecustomize_executed  sh    #+--F$$$$ 		DEEEEE     .-s   + 
99HTTPSHandlerz$need SSL support to download licensenetworkc                 P   t           j                                        d         }t          j                            |d          }|                     t          j        j                   	 t          j	        |          5  t          j        
                    |          5 }|                                }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   n(# t          j        j        $ r}|j        }Y d }~nd }~ww xY w|                     |dd|z              d S )NrF   HEAD)method   zCan't find )msg)r&  _Printer__dataspliturllibrequestRequestrp   
urlcleanupr   transient_interneturlopengetcodeerror	HTTPErrorcoder<   )r0   urlreqdatarB  es         r   test_license_exists_at_urlz0ImportSideEffectTests.test_license_exists_at_url  s    $**,,Q/n$$S$881222	1#66 * *^++C00 *D<<>>D* * * * * * * * * * * * * * ** * * * * * * * * * * * * * * |% 	 	 	6DDDDDD	s(;<<<<<s`   +C# ? CC 4C C	CC	CC# CC# CC# #D7DDN)r   r   r   r   r1   r6   r  r  r   skipr  r"  r'  r*  r/  r   r   r9  r:  r  r   requires_resourcesystem_must_validate_certrG  r   r    r   r  r    s-       22$ $ $$ $ $	: 	: 	:! ! ! X])**  +*3 3 3
6 6 63 3 3F F F X@@?A A	\##I..	\+= = ,+ /.A A= = =r    r  c                       e Zd Z ej                    d             Z ej                    d             Z ej                    d             Z ej                    d             ZdS )StartupImportTestsc           	         t          j        t          j        dddddgt           j        dd          }|                                d	         }|                     |j        d	t          |                     t          j
        |          }|D ]p}t          j        t          j                            t          j        |          d
                    }|r(|                     dt#          |           d|            qt          j        t          j        ddddddgt           j        t           j        dd          }|                                \  }}|                     |j        d	||f           t          j
        |          }|                     d|           h d}|                     |                    |          |           |                     d||           |                     d||           h d                    t          j                  }	|                     |                    |	          |           d S )N-Xutf8-Ir   z!import sys; print(repr(sys.path))rh   surrogateescape)stdoutrj   errorsr   z*.pthzfound z .pth files in: z-vz#import sys; print(set(sys.modules)))rR  r   rj   rS  r   >   
re._parserre._compilerre._constantsr}   _srelocalecopyreg>
   heapqtypeskeywordreprlibweakrefoperator	functools	itertoolscollections_collections)r   Popenr   r   PIPEcommunicater<   
returncodereprastliteral_evalglobr   r   r:   r~   skipTestr   rK   rS   intersectionr   
differencebuiltin_module_names)
r0   popenrR  isolated_pathsr   	pth_filesr   rQ   re_modscollection_modss
             r   test_startup_importsz'StartupImportTests.test_startup_imports  sH     #.$"&(K"M(2*1(9	; ; ;
 ""$$Q')1d6ll;;;)&11
 # 	O 	OD	"',,t{4/@/@'"J"JKKI OMs9~~MMtMMNNN  #.$d"&(M"O(2(2*1(9; ; ; **,,)1vv.>???"6**fg&&& POO--g66??? 	7F333 	GV444   'Js'?@@ 	 	--o>>GGGGGr    c                     t          j        t          j        ddg                                          }|                     |d           d S )Nr   9import sys; sys.exit(hasattr(sys, "__interactivehook__"))z''__interactivehook__' not added by siter   rd  r   r   waitr   r0   rs     r   test_startup_interactivehookz/StartupImportTests.test_startup_interactivehookF  sL    cndGI J JJN$&& 	
DEEEEEr    c                     t          j        t          j        dddg                                          }|                     |d           d S )NrP  r   rw  z,'__interactivehook__' added in isolated mode)r   rd  r   r   ry  rS   rz  s     r   %test_startup_interactivehook_isolatedz8StartupImportTests.test_startup_interactivehook_isolatedL  sR     cndDGI J JJN$&& 	
JKKKKKr    c                     t          j        t          j        dddg                                          }|                     |d           d S )NrP  r   zYimport site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))z6'__interactivehook__' not added by enablerlcompleter()rx  rz  s     r   .test_startup_interactivehook_isolated_explicitzAStartupImportTests.test_startup_interactivehook_isolated_explicitS  sS     cndDgi j jjnjnjpjp 	
STTTTTr    N)	r   r   r   r   r   ru  r|  r~  r  r   r    r   rL  rL    s         W ""0H 0H #"0Hd !W ""F F #"F
 !W ""L L #"L !W ""U U #"U U Ur    rL  c                      e Zd Zej        dk    rddZnddZd ZdedefdZ	 e
j                    d	             Z e
j                    d
             Z e
j                    d             Z e
j                    d             ZdS )_pthFileTestsr   Tc           
         dd l }t          j                    }|                     t          j        |           t          j                            |t          j        	                    t          j                  d                   }|                    t          j                  }t          j                            |t          j        	                    |          d                   }t          j        t          j        |           t          j        ||           t!          j        t          j                            t          j        	                    |          d         d                    D ]X}t          j        |t          j                            |t          j        	                    |          d                              Y|r)t          j                            |          d         dz   }	n(t          j                            |          d         dz   }	t%          |	dd          5 }
|D ]}t'          ||
           	 d d d            n# 1 swxY w Y   |S )	Nr   rF   zvcruntime*.dll._pthrg   rO  ri   r  )_winapitempfilemkdtemprp   r   rmtreer   r   r:   r8  r   r   GetModuleFileName	dllhandleshutilr   rk  splitextro   r  )r0   linesexe_pthr  temp_direxe_filedll_src_filedll_filefn	_pth_fileflines               r   _create_underpth_exez"_pthFileTests._create_underpth_exe]  s   NNN'))HOOI,h777w||HbgmmCN.K.KA.NOOH"44S]CCLw||HbgmmL.I.I!.LMMHK111Kh///iRW]]<-H-H-KM] ^ ^__ N NBXrw}}R7H7H7K L LMMMM DG,,X66q9GC		G,,X66q9GC	iv666 (!! ( (D$Q'''''(( ( ( ( ( ( ( ( ( ( ( ( ( ( ( Os   .IIIc                    |st          j        d          t          j                    }|                     t
          j        |           t          j        	                    |t          j        
                    t          j                  d                   }t          j        t          j        |           |dz   }t          |d          5 }|D ]}t          ||           	 d d d            n# 1 swxY w Y   |S )Nz1library ._pth file not supported on this platformrF   r  rg   r  )r   r   r  r  rp   r   r  r   r   r:   r8  r   r   symlinkro   r  )r0   r  r  r  r  r  r  r  s           r   r  z"_pthFileTests._create_underpth_exeq  s    ]'([\\\'))HOOI,h777w||HbgmmCN.K.KA.NOOHJs~x000 7*Ii%% (! ( (D$Q'''''(( ( ( ( ( ( ( ( ( ( ( ( ( ( ( Os   C//C36C3c                     g }|D ]c}|r|d         dk    rt           j                            t           j                            ||                    }|                    |           d|S )Nr   #)r   r   r=   r:   append)r0   
sys_prefixr  r%   r  abs_paths         r   "_calc_sys_path_for_underpth_nositez0_pthFileTests._calc_sys_path_for_underpth_nosite~  sj     	& 	&D 47c>>wrw||J'E'EFFHOOH%%%%r    libpathimport_sitec                p   dg}t                              d                    }t          dd|z            }|dk    r|                     d|dd           |                    fd	t          |          D                        |                    d
dg           |r|                    d           |S )Nfake-path-namerh   r5  i0u  r   z Python stdlib path is too long (,z bytes)c              3      K   | ]}V  d S r   r   )rH   _r  s     r   	<genexpr>z/_pthFileTests._get_pth_lines.<locals>.<genexpr>  s#      ==Q======r    r   z	# commentzimport site)r   encodeminrl  extendranger  )r0   r  r  	pth_linesencoded_libpath_lengthrepetitionss    `    r   _get_pth_linesz_pthFileTests._get_pth_lines  s    %&	 "%W^^G%<%<!=!=#u(>>??!MMT3ITTTTV V V====%*<*<======"k*+++ 	,]+++r    c                    ddgt           j        dd}|                     |          }|                     t          j                            |          |          }t          j        |ddddgd	d
          }|                                	                    d          }| 
                    |d           |                     ||d           d S )Nz#.z# ..rd   z..rN  rO  r   Cimport sys; print("\n".join(sys.path) if sys.flags.no_site else "")rh   rQ  )rj   rS  r   sys.flags.no_site was Falsesys.path is incorrect)r   r   r  r  r   dirnamer   check_outputrstripr8  r   r<   )r0   r  r  r%   outputactual_sys_paths         r   test_underpth_basicz!_pthFileTests.test_underpth_basic  s    68CH8c848	,,Y77::GOOH%%  ((D&$R*
$57 7 7 !--////55)FGGG#	
 	
 	
 	
 	
r    c                    t           j        j        }t          j                            t          j                  }|                     |d          }| 	                    |          }| 
                    t          j                            |          |          }t          j                                        }d|d<   d                    |t          j        t          j        d                    |d<   t!          j        |ddg|d	d
          }|                                                    d          }|                     |d           |                     ||d           d S )NFr  from-env
PYTHONPATHz{}{}{}PATHr   r  rh   rQ  )r   rj   rS  r   r  r  )r  r   
STDLIB_DIRr   r   r  r   r   r  r  r  r   r   formatpathsepgetenvr   r  r  r8  r   r<   )	r0   r  
exe_prefixr  r  r%   r   r  r  s	            r   test_underpth_nosite_filez'_pthFileTests.test_underpth_nosite_file  sB   ,)W__S^44
''U'CC	,,Y77::GOOH%%  joo&Looj"*bi>O>OPPF((DR*
W->@ @ @ !--////55)FGGG#	
 	
 	
 	
 	
r    c                    t           j        j        }t          j                            t          j                  }|                     | 	                    |d                    }t          j                            |          }t          j
                                        }d|d<   d                    |t          j        d                    |d<   t          j        |ddt          j                            |d	          d
|d
t          j                            |d          dg|          }|                     |d           d S )NTr  r  r  {};{}r  r   /import sys; sys.exit(not sys.flags.no_site and r   in sys.path and L not in sys.path and all("\r" not in p and "\n" not in p for p in sys.path))r   r  r  r   r  r   r   r  r   r   r  r  r   r   r  r  r   r   r:   r   r0   r  r  r  r  r   r   s          r   test_underpth_filez _pthFileTests.test_underpth_file  s   ,)W__S^44
,,T::< <W__X..
joo&LnnZ61B1BCCF_h Z)9::::Z4444    	344444r    c                    t           j        j        }t          j                            t          j                  }|                     | 	                    |d          d          }t          j                            |          }t          j
                                        }d|d<   d                    |t          j        d                    |d<   t          j        |d	d
t          j                            |d          d|dt          j                            |d          dg|          }|                     |d           d S )NTr  F)r  r  r  r  r  r   r  r  r  r  r   r  r  r  s          r   test_underpth_dll_filez$_pthFileTests.test_underpth_dll_file  s(   ,)W__S^44
,,T::E - K KW__X..
joo&LnnZ61B1BCCF_h Z)9::::Z4444    	344444r    N)T)r   r   r   r   r   r  r  r   boolr  r   r   r  r  r  r  r   r    r   r  r  Z  s       
|w	 	 	 	 	(	 	 	 	  c 4      !W ""
 
 #"
$ !W ""
 
 #"
. !W ""5 5 #"5& !W ""5 5 #"5 5 5r    r  __main__)0r   r   test.supportr  r   r   r   r   test.support.os_helperr   r   r	   ri  r!  	encodingsrk  r   r   r}   r  r   r   r   r+   r  urllib.errorr9  urllib.requestr
   r   flagsno_siter   r   r   r   r   r   r!   TestCaser#   r   r\   r  rL  r  r   mainr   r    r   <module>r     s               " " " " " " & & & & & & ( ( ( ( ( ( J J J J J J J J J J 



       				 				 				       



                         
 9 :
(
8
9
99  t+= = =  D= D= D= D= D=8, D= D= D=N
5( 5( 5( 5( 5(f 5( 5( 5(nP= P= P= P= P=H- P= P= P=fGU GU GU GU GU* GU GU GURN5 N5 N5 N5 N5H% N5 N5 N5b zHMOOOOO r    