
    <ero                     *   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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    %/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                      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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.setUpC   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.tearDownL   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_makepathX   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>g   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_pathinfoe   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_testsm   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_addpackaget   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   rk   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rt   r   r   r^   ra   assertRegexgetvaluereescaper   r   r:   r0   rq   rk   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 2rv   ModuleNotFoundErrorrx   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

  

)rt   r   r^   ra   r<   )r0   rq   rk   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)rt   r   rS   r   r^   ra   maxDiffr<   rz   r   r   
isinstancestrassertNotIn)r0   rq   rk   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_   ra   rW   rU   s     r   test_addsitedirz$HelperFunctionsTests.test_addsitedir   s     99d###	OOOH-suu555)))Hs   AB B!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   
subprocess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_getusersitepackages  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_getsitepackages  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   rl   z=HelperFunctionsTests.test_no_home_directory.<locals>.<lambda>=  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_attrra   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_directory4  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   stderrrz   )r0   messager   outs       r   
test_tracezHelperFunctionsTests.test_traceV  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   rb   r   rt   r   r   r   r   r   r   r   
skipUnlessHAS_USER_SITEr   r   r   r   requires_subprocessr   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  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 variablesre   r   N)r`   r   r   r=   r_   r:   	file_pathrP   good_dirnamebad_dirnamerR   rT   )r0   filename_baserP   r   r   s        r   __init__zPthFile.__init__b  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.

        rf   z#import @bad module namefiler   z	import %sN)
rm   r   printrP   r   r   closer   mkdirrR   )r0   FILEs     r   r]   zPthFile.createn  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   rj   r   rQ   getrP   imported_modulerR   rmdirrT   )r0   rZ   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                            d          ej        j         ej         eej        d          d          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   removeduppathsra   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   hasattr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networkHTTPSHandlerz$need SSL support to download licensec                 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Requestrn   
urlcleanupr   transient_interneturlopengetcodeerror	HTTPErrorcoder<   )r0   urlreqdatar2  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   requires_resourcesystem_must_validate_certr   r  r)  r*  r7  r   r    r   r   r     s-       22$ $ $$ $ $	: 	: 	:! ! ! X])**  +*3 3 3
6 6 63 3 3F F F 
\##I..	\+X@@?A A= =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 )Nz-Xutf8-Ir   z!import sys; print(repr(sys.path))rg   surrogateescape)stdoutrh   errorsr   z*.pthzfound z .pth files in: z-vz#import sys; print(set(sys.modules)))rA  r   rh   rB  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   popenrA  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   rS  r   r   waitr   r0   rs     r   test_startup_interactivehookz/StartupImportTests.test_startup_interactivehook  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 )Nr?  r   rf  z,'__interactivehook__' added in isolated mode)r   rS  r   r   rh  rS   ri  s     r   %test_startup_interactivehook_isolatedz8StartupImportTests.test_startup_interactivehook_isolated$  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 )Nr?  r   zYimport site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))z6'__interactivehook__' not added by enablerlcompleter()rg  ri  s     r   .test_startup_interactivehook_isolated_explicitzAStartupImportTests.test_startup_interactivehook_isolated_explicit+  sS     cndDgi j jjnjnjpjp 	
STTTTTr    N)	r   r   r   r   r   rd  rk  rm  ro  r   r    r   r<  r<    s         W ""0H 0H #"0Hd !W ""F F #"F
 !W ""L L #"L !W ""U U #"U U Ur    r<  c                       e Zd Zej        dk    rddZnddZd Z ej                    d             Z	 ej                    d             Z
 ej                    d             Z ej                    d	             Zd
S )_pthFileTestswin32Tc           
         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          5 }
|D ]}t'          ||
           	 d d d            n# 1 swxY w Y   |S )Nr   rF   zvcruntime*.dll._pthrf   r   )_winapitempfilemkdtemprn   r   rmtreer   r   r:   r(  r   r   GetModuleFileName	dllhandleshutilr   rZ  splitextrm   r   )r0   linesexe_pthru  temp_direxe_filedll_src_filedll_filefn	_pth_fileflines               r   _create_underpth_exez"_pthFileTests._create_underpth_exe5  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%% (! ( (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   rt  rf   r   )r   r   rv  rw  rn   r   rx  r   r   r:   r(  r   r   symlinkrm   r   )r0   r}  r~  r  r  r  r  r  s           r   r  z"_pthFileTests._create_underpth_exeI  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_nositeV  sj     	& 	&D 47c>>wrw||J'E'EFFHOOH%%%%r    c                    t           j        j        }t          j                            t          j                  }ddgt          j        dd}|                     |          }| 	                    t          j                            |          |          }t          j        |ddgdd	          }|                                                    d
          }|                     |d           |                     ||d           d S )Nz#.z# ..rc   z..r   Cimport sys; print("\n".join(sys.path) if sys.flags.no_site else "")rg   r@  )rh   rB  r   sys.flags.no_site was Falsesys.path is incorrect)r   r   
STDLIB_DIRr   r   dirnamer   r   r  r  r   check_outputrstripr(  r   r<   )r0   libpath
exe_prefix	pth_linesr  r%   outputactual_sys_paths           r   test_underpth_basicz!_pthFileTests.test_underpth_basic_  s    ,)W__S^44
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gfdt          d          D             d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 )Nfake-path-namec                     g | ]}S r   r   rH   _r  s     r   rI   z;_pthFileTests.test_underpth_nosite_file.<locals>.<listcomp>z      ***!g***r    r%  r   	# commentfrom-env
PYTHONPATHz{}{}{}PATHr   r  rg   r@  )r   rh   rB  r   r  r  )r   r   r  r   r   r  r   r   ranger  r  r   r   formatpathsepgetenvr   r  r  r(  r   r<   )	r0   r  r  r  r%   r   r  r  r  s	           @r   test_underpth_nosite_filez'_pthFileTests.test_underpth_nosite_filet  sm   ,)W__S^44

****uSzz***
 
 	
	 ,,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gfdt          d          D             d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 )Nr  c                     g | ]}S r   r   r  s     r   rI   z4_pthFileTests.test_underpth_file.<locals>.<listcomp>  r  r    r%  r   r  import siter  r  {};{}r  r   /import sys; sys.exit(not sys.flags.no_site and  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  sT   ,)W__S^44
,,.
****uSzz***.
 .
 	.

 .
   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gfdt          d          D             dd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 )Nr  c                     g | ]}S r   r   r  s     r   rI   z8_pthFileTests.test_underpth_dll_file.<locals>.<listcomp>  r  r    r%  r   r  r  F)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
,,.
****uSzz***.
 .
 	.

 .
  -   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   r   r  r  r  r  r   r    r   rq  rq  2  s        
|w	 	 	 	 	(	 	 	 	   !W ""
 
 #"
( !W ""
 
 #"
8 !W ""5 5 #"50 !W ""5 5 #"5 5 5r    rq  __main__)/r   r   test.supportr   r   r   r   r   test.support.os_helperr   r   r	   rX  r  	encodingsrZ  r   r   r{   r{  r   r   r+   rv  urllib.errorr)  urllib.requestr
   r   flagsno_siter   r   r   r   r   r   r!   TestCaser#   r   r[   r   r<  rq  r   mainr   r    r   <module>r     s               " " " " " " & & & & & & ( ( ( ( ( ( J J J J J J J J J J 



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



                         
 9 :
(
8
9
99  t+= = =  ]= ]= ]= ]= ]=8, ]= ]= ]=@	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O5 O5 O5 O5 O5H% O5 O5 O5d zHMOOOOO r    