HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/test_import/__pycache__/__init__.cpython-310.pyc
o

�i��@sPddlZddlZddlZddlZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZmZmZmZddlmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&ddlm'Z'dd	lm(Z(dd
l)m*Z*ddl+m,Z,e�-ej.d�Z/d
d�Z0ej1d+dd��Z2Gdd�dej3�Z4e/Gdd�dej3��Z5Gdd�dej3�Z6Gdd�dej3�Z7Gdd�dej3�Z8Gdd�dej3�Z9Gdd�dej3�Z:Gd d!�d!ej3�Z;eGd"d#�d#ej3��Z<eGd$d%�d%ej3��Z=Gd&d'�d'ej3�Z>Gd(d)�d)ej3�Z?e@d*k�r&e�A�dSdS),�N)�_get_sourcefile)�mock)�	os_helper)�	is_jython�	swap_attr�	swap_item�cpython_only)�forget�make_legacy_pyc�unlink�unload�
DirsOnSysPath)�TESTFN�rmtree�
temp_umask�TESTFN_UNENCODABLE�temp_dir)�
script_helper)�threading_helper)�uncache)�
ModuleTypez*test meaningful only when writing bytecodecCs6|d|d|d|dfD]}t|�qtd�dS)N�.py�.pyc�.pyw�	$py.class�__pycache__)rr)�name�f�r�6/usr/local/lib/python3.10/test/test_import/__init__.py�remove_files%s�
r �c
cs��|pd}t��[}t�|||�}tj�|d�}z'tj�d|�||fVtj�|�W|dur5|tj|<n&|tjvr>tj|=n|durI|tj|<w|tjvrRtj|=wWd�dSWd�dS1sfwYdS)N�spamr)	rr�make_script�sys�modules�pop�path�insert�remove)r�source�tempdirr'Z
old_modulerrr�_ready_to_import.s.�

��

�
��	"�r,c@s$eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdAdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zed&d'��Zd(d)�Zd*d+�Zed,d-��Zd.d/�Ze	d0d1��Zd2d3�Zd4d5�Zd6d7�Ze	d8d9��Z d:d;�Z!e"�#e$j%d<kd=�d>d?��Z&d@S)B�ImportTestscCstt�t��dS�N)r r�	importlib�invalidate_caches��selfrrr�setUpE�zImportTests.setUpcCstt�dSr.)rrr1rrr�tearDownI�zImportTests.tearDowncC�8|�t��
ddl}Wd�dS1swYdS�Nr)�assertRaises�ModuleNotFoundError�(something_that_should_not_exist_anywhere�r2r;rrr�&test_import_raises_ModuleNotFoundErrorLs
"�z2ImportTests.test_import_raises_ModuleNotFoundErrorcC�<|�t��ddlm}Wd�dS1swYdS)Nr)�blah)r9r:r;r?)r2r?rrr�:test_from_import_missing_module_raises_ModuleNotFoundErrorP�"�zFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorcCr>)Nr)r;)r9�ImportErrorr/r;r<rrr�0test_from_import_missing_attr_raises_ImportErrorTrAz<ImportTests.test_from_import_missing_attr_raises_ImportErrorcCsn|�t��}ddlm}Wd�n1swY|�|jjd�|�|jjtj�|�	t
|j�d�dS)Nr��i_dont_exist�osz7cannot import name 'i_dont_exist' from 'os' \(.*os.py\))r9rBrFrE�assertEqual�	exceptionrr'�__file__�assertRegex�str�r2�cmrErrr�/test_from_import_missing_attr_has_name_and_pathXs�z;ImportTests.test_from_import_missing_attr_has_name_and_pathcCsvddl}|�t��}ddlm}Wd�n1swY|�|jjd�|�|jj|j�|�	t
|j�d�dS)NrrD�	_testcapizCcannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\))rOr9rBrErGrHrr'rIrJrK)r2rOrMrErrr�2test_from_import_missing_attr_has_name_and_so_path_s�z>ImportTests.test_from_import_missing_attr_has_name_and_so_pathcCsX|�t��}ddlm}Wd�n1swY|�|jjd�|�|jj�dS)NrrD�_warning)	r9rBrQrErGrHrZassertIsNoner'rLrrr�&test_from_import_missing_attr_has_namehs
�z2ImportTests.test_from_import_missing_attr_has_namecCsZ|�t��}ddlm}Wd�n1swY|�|jjddh�|�|j�dS)NrrD�	posixpath�ntpath)r9rBZos.pathrE�assertInrHr�assertIsNotNonerLrrr�/test_from_import_missing_attr_path_is_canonicalos
�z;ImportTests.test_from_import_missing_attr_path_is_canonicalc	Cs�ddl}t��S\}}t|ddd��
}|�d�Wd�n1s!wYi}|�t|�|��d���td|�d�|�Wd�n1sHwY|�d	|�Wd�n1s]wYt��T\}}t|ddd��
}|�d
�Wd�n1swYi}|�t|�|��d���td|�d�|�Wd�n1s�wY|�d	|�Wd�dS1s�wYdS)Nr�w�utf-8��encodingz__all__ = [b'invalid_type']z\.__all__ must be strzfrom z	 import *sinvalid_typez%globals()[b'invalid_type'] = object()z\.__dict__ must be str)	�rer,�open�write�assertRaisesRegex�	TypeError�escape�exec�assertNotIn)r2r\rr'r�globalsrrr�"test_from_import_star_invalid_typeus2����	���"�z.ImportTests.test_from_import_star_invalid_typecCr7r8)r9rB�RAnDoM)r2rfrrr�test_case_sensitivity�s
"�z!ImportTests.test_case_sensitivitycCsddlm}dS)Nr)�double_const)�testrh)r2rhrrr�test_double_const�szImportTests.test_double_constcsj�fdd�}tj�dtj�z!|d�tj�d�r"dD]
}||�qWtjd=dSWtjd=dStjd=w)Nc
sLt|}trtd}ntd}t|ddd��(}td|d|d�t�d	�}t�d	�}td
||d�td||d�Wd�n1sAwYttjvrOtjt=t�	�zEzt
t�}Wntyu}z��d||f�WYd}~nd}~ww��
|j|d
|���
|j|d
|�Wtt�t|�t|�dStt�t|�t|�w)NrrrXrYrZz)# This tests Python's ability to import azfile.��filei�za =zb =zimport from %s failed: %sz'module loaded (%s) but contents invalid)rrr]�print�random�	randranger$r%r/r0�
__import__rB�failrG�a�br	r)�extr*Zpycrrrrs�mod�errr1rr�test_with_extension�sF
�

�
��
�
��
z4ImportTests.test_import.<locals>.test_with_extensionrr�win)z.PYz.Pyz.pYrz.PYWz.pYw)r$r'r(rF�curdir�platform�
startswith)r2rwrtrr1r�test_import�s"
��zImportTests.test_import�longlistcCsL|d}t|ddd��}|�d�td�D]}|�d�q|�d�Wd�n1s,wYzt�|�Wt|�nt|�wtj�d	�t	�
�i}z3t|�td
|d|�Wtjd=t|d�t|d
�|�
�ztj|=WdSty�YdSwtjd=t|d�t|d
�|�
�ztj|=Wwty�Yww)NrrXrYrZzd = [
i�z"",
�]r!zimport ����c�o)r]r^�range�
py_compile�compilerr$r'�appendr/r0r
rb�clearr%�KeyError)r2�module�filenamer�i�	namespacerrr�test_module_with_large_stack�sD
����z(ImportTests.test_module_with_large_stackcCs�td}t|ddd��}td|d�Wd�n1swYtj�dtj�t�	�ttj
vr6tj
t=z!dD]}|�tt
t�|�ttj
d	|�q9Wtjd=tt�dStjd=tt�w)
NrrXrYrZza = 1/0rkr)���z'damaged module in sys.modules on %i try)rr]rmr$r'r(rFryr/r0r%r9�ZeroDivisionErrorrprcr )r2r*rr�rrr�test_failing_import_sticks�s&�

���
z&ImportTests.test_failing_import_stickscCsTddl}ddl}|�|||j�|�t|jd��ddlm}|�||j|j�dS)NrrI)ri�test.support�assertIs�__name__�
assertTrue�hasattr�support)r2�xri�yrrr�test_import_name_binding�sz$ImportTests.test_import_name_bindingcCs�z
d}Wddlmm}n
ddlmm}wd}|dkr/ddlmm}|d7}|dkstd�D]}ddlmm}q3dS)N.r�
r�r�)Ztest.support.script_helperr�rr�)r2r�r�rrr�test_issue31286s(��zImportTests.test_issue31286cCsNttjd}t|ddd��
}|�d�Wd�n1swYtj�dtj�znt	t�}|�
ttj�|�|j
dd�|�|jd	d�tt�t|ddd��
}|�d
�Wd�n1sbwY|�ttj|�tj�t�}|�|d�|�|j
dd�|�|jd	d�Wtjd=tt�tt�dStjd=tt�tt�w)
N�pyrXrYrZz
a = 1
b=2
rr�z!module has wrong attribute valuesr�za = 10
b=20//0
z$expected module to be in sys.modulesr�)rrF�extsepr]r^r$r'r(ryrprUr%rGrrrsr r9r�r/�reload�getrVr)r2r*rrurrr�test_failing_reloads2���
zImportTests.test_failing_reloadcCstd}t|ddd��
}|�d�Wd�n1swYtj�dtj�zGtt�}|�	|j
�d��t�|�tj
t=t|�t��tt�}tj�|j
�\}}|�|d�Wtjd=tt�ttj
vrntj
t=dSdStjd=tt�ttj
vr�tj
t=w)NrrXrYrZztest = None
rr)rr]r^r$r'r(rFryrpr�rI�endswithr)r%r
r/r0�splitextrGr )r2r*rru�basertrrr�test_file_to_source?s0�

��

zImportTests.test_file_to_sourcecCs~tj�t�}t��}z|�|�Wnty"|�d�	|��Ynw|�
t��
}t|�Wd�dS1s8wYdS)Nzpath is not encodable to {})
rFr'�abspathrr$�getfilesystemencoding�encode�UnicodeEncodeError�skipTest�formatr9rBrp)r2r'r[r�rrr�test_import_by_filenameWs�
"�z#ImportTests.test_import_by_filenamecCs"t�dtt�d��}t�|�dS)Nr!z�            import sys
            class C:
               def __del__(self):
                  import importlib
            sys.argv.insert(0, C())
            )rr#r�textwrap�dedent�assert_python_ok)r2Ztestfnrrr�!test_import_in_del_does_not_crashasz-ImportTests.test_import_in_del_does_not_crashc
Cstj�dtj�zutd}tj�|�}t	|ddd��}Wd�n1s%wYzt�
|d�Wn7ty@|�d�Yn*t
yi}z|jttdd�ttd	d�fvrW�|�d
�|��WYd}~nd}~wwtt�t�|�Wtjd=tt�dStjd=tt�w)NrrrXrYrZ)���r�z-cannot set modification time to large integerZ	EOVERFLOW�EINVALz2cannot set modification time to large integer ({}))r$r'r(rFryrr/�util�cache_from_sourcer]�utime�
OverflowErrorr��OSError�errno�getattrr�rp�statr )r2r*Zcompiledr�errr�test_timestamp_overflowls2�
����
z#ImportTests.test_timestamp_overflowcCs4z
tddgd�WdSty|�d�YdSw)N�httpr?)�fromlistzfromlist must allow bogus names)rprBrqr1rrr�test_bogus_fromlist�s
�zImportTests.test_bogus_fromlistcCs.ddg}tj|�}|��\}}|�d|�dS)N�-cz&del __builtins__.__import__; import ossImportError)rZspawn_python�communicaterU)r2�args�popen�stdout�stderrrrr�test_delete_builtins_import�s
z'ImportTests.test_delete_builtins_importcC�>|�td��ddlm}Wd�dS1swYdS)Nz^No module named 'bogus'r)�foo)r_rB�bogusr�)r2r�rrr�/test_from_import_message_for_nonexistent_module��"�z;ImportTests.test_from_import_message_for_nonexistent_modulecCr�)Nz^cannot import name 'bogus'r)r�)r_rBr\r�)r2r�rrr�,test_from_import_message_for_existing_module�r�z8ImportTests.test_from_import_message_for_existing_modulecCsvGdd�d�}d}|�t|�|�tj|<|�t��}ddlm}Wd�n1s+wY|�t	|j
�d�dS)Nc@�eZdZdd�ZdS)zIImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeErrorcSst�r.)�AttributeError)r2�_rrr�__getattr__�szUImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeError.__getattr__N)r��
__module__�__qualname__r�rrrr�AlwaysAttributeError��r��test_from_import_AttributeErrorr��does_not_existzScannot import name 'does_not_exist' from '<unknown module name>' (unknown location))�
addCleanuprr$r%r9rBr�r�rGrKrH)r2r��module_namerMr�rrrr��s��z+ImportTests.test_from_import_AttributeErrorc	Cs�ttdd��D|�t��ddlm}Wd�n1swY|�t��tjWd�n1s5wYWd�dSWd�dS1sMwYdS)Nr�rr�)rrFr9rBr�r�)r2r�rrr�test_issue31492�s���"�zImportTests.test_issue31492csdd��tj�dtj�tj�t�d��zid����fdd��td�D]S}t�	���fdd	�td
�D�}z,t
�|�j��
t
�d�Wd�n1sLwYWtj�dd�tj�dd�ntj�dd�tj�dd�w�durv��q#Wtjd=dStjd=w)
NcSs*|dkr|jjdkrt�d�dSdSdS)N�call�has_deadlockg�������?)�f_code�co_name�time�sleep)�frame�event�argrrr�delay_has_deadlock�s�z8ImportTests.test_concurrency.<locals>.delay_has_deadlockr�datac
sVt������zddl}Wnty#}z|�WYd}~nd}~wwt�d�dSr8)r$�settrace�wait�package�
BaseException)r�r�)r�r��excrr�run�s
��z)ImportTests.test_concurrency.<locals>.runr�csg|]}tj�d��qS))�target)�	threading�Thread)�.0r�)r�rr�
<listcomp>�sz0ImportTests.test_concurrency.<locals>.<listcomp>r�r�zpackage.submodule)r$r'r(rF�join�dirnamerIr�r��EventrZ
start_threads�setr�r�r%r&)r2r��threadsr)r�r�r�r�r�test_concurrency�s, 
�����zImportTests.test_concurrency�win32�Windows-specificc
Cs�ddlm}|tj�}tj�d�j}tj	�
tj	�|�d�d|vr"dnd��}t
����}tj	�
|d�}t�|�tj	�
|tj	�tj��}t�tj|�t�||�t�tj	�
t�tj�d��D]}t�||�q^t�||�d}	d	d
�tjD�}	|dtj	�tj�|	d<tj|d
d�
dd�tj	�|��ddg�gtj|	tj	�|�d�t�||�tj|d
dgtj|	tj	�|�d�Wd�dS1s�wYdS)Nr)�GetModuleFileNameZ_sqlite3z
sqlite3{}.dllZ_dr!ZDLLszvcruntime*.dllcSsi|]
}|��tj|�qSr)�upperrF�environ)r��krrr�
<dictcomp>�sz:ImportTests.test_dll_dependency_import.<locals>.<dictcomp>�;Z
PYTHONPATHz-Scz	import oszp = os.add_dll_directory({!r})zimport _sqlite3zp.close)r��env�cwd)�_winapir�r$Z	dllhandler/r��	find_spec�originrFr'r�r�r�rr�mkdir�basename�
executable�shutil�copy�globra�prefixr�rI�
subprocess�
check_call�STDOUT)
r2r�ZdllnameZpydnameZdepname�tmpZtmp2Zpyexerr�rrr�test_dll_dependency_import�sP

�

 
���
�

�"�z&ImportTests.test_dll_dependency_importN)r})'r�r�r�r3r5r=r@rCrNrrPrRrWrergrjr|r�r�r�r�r��skip_if_dont_write_bytecoder�r�r�r�r�r�r�r�r�r�r��unittest�
skipUnlessr$rzrrrrrr-CsJ

,(&




"r-c@sbeZdZe�ejdkd�dd��Ze�ejdkd�dd��Ze�ejdkd�dd��Z	d	d
�Z
dS)�FilePermissionTests�posix�%test meaningful only on posix systemsc	Cs�d}t|��7t��$\}}tj�|�}t|�}tj�|�s"|�	d�t�
|�}Wd�n1s1wYWd�n1s@wY|�tt
�
|j��td|@��dS)N��4__import__ did not result in creation of a .pyc filei�)rr,r/r�r�rprFr'�existsrqr�rG�oct�S_IMODE�st_mode)r2�maskrr'�cached_pathr��	stat_inforrr�test_creation_modes
��
�z&FilePermissionTests.test_creation_modec	Cs�d}td��=t��*\}}tj�|�}t�||�t|�tj�	|�s(|�
d�t�|�}Wd�n1s7wYWd�n1sFwY|�t
t�|j��t
|��dS)N�rr�rr,r/r�r�rF�chmodrpr'rrqr�rGrrr)r2�moderr'rrrrr�test_cached_mode_issue_2051s
�� 	z/FilePermissionTests.test_cached_mode_issue_2051c	Cs�d}td��=t��*\}}tj�|�}t�||�t|�tj�	|�s(|�
d�t�|�}Wd�n1s7wYWd�n1sFwY|dB}|�t
t�|j��t
|��dS)N�rr�r!)r2r#rr'rrZexpectedrrr�test_cached_readonly,s
��	 z(FilePermissionTests.test_cached_readonlyc	Cs`t���\}}t|ddd��
}|�d�Wd�n1swYt�|�}t�||j|jdf�t�|d�t	|�}|�
|jd�t�|d�t|ddd��
}|�d	�Wd�n1sawYt|�t
��t	|�}|�
|jd
�t|�t|�t
��|d}t�t
j�|�|�t	|�}|�
|jd
�Wd�dS1s�wYdS)NrXrYrZzx = 'original'
i�r%Zoriginalr zx = 'rewritten'
Z	rewrittenr�)r,r]r^rFr�r��st_atime�st_mtimer"rprGr�rr/r0r�renamer�r�)r2rr'r�s�mZ
bytecode_onlyrrr�test_pyc_always_writable<s2�
�"�z,FilePermissionTests.test_pyc_always_writableN)r�r�r�rrrFrrr$r'r-rrrrrs�
�
�
rc@s|eZdZdZdZej�e�Z	ej�
e	e�ejdZe
j�e�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�ZdS)�PycRewritingTestsZunlikely_module_namez�
import sys
code_filename = sys._getframe().f_code.co_filename
module_filename = __file__
constant = 1
def func():
    pass
func_filename = func.__code__.co_filename
r�cCs�tjdd�|_tj�|jd�|_t�|j	�t
|jddd��}|�|j
�Wd�n1s0wYtj�d|j	�t��dS)NrXrYrZr)r$r'�sys_pathr%r&r��orig_modulerFr�dir_namer]�	file_namer^�
module_sourcer(r/r0)r2rrrrr3ns�zPycRewritingTests.setUpcCsV|jtjdd�<|jdur|jtj|j<nt|j�t|j�t|j	�t
|j�dSr.)r/r$r'r0r%r�rrr2�
compiled_namerr1r1rrrr5ws



zPycRewritingTests.tearDowncCs t�}t|j||�tj|jSr.)rdrpr�r$r%)r2�nsrrr�
import_module�szPycRewritingTests.import_modulecCs~|��}|�|j|j�|�|j|j�|�|j|j�tj|j=|��}|�|j|j�|�|j|j�|�|j|j�dSr.)	r6rG�module_filenamer2�
code_filename�
func_filenamer$r%r��r2rurrr�test_basics�s
zPycRewritingTests.test_basicscCsLtj|jdd�|��}|�|j|j�|�|j|j�|�|j|j�dS�Nzanother_module.py)�dfile)r�r�r2r6rGr7r8r9r:rrr�test_incorrect_code_name�s
z*PycRewritingTests.test_incorrect_code_namecCshd}tj|j|d�t�|j�t|j�}t��|��}|�	|j
|�|�	|j|�|�	|j|�dSr<)
r�r�r2rFr)r
r/r0r6rGr7r8r9)r2r��pyc_filerurrr�test_module_without_source�s
z,PycRewritingTests.test_module_without_sourcecCs�t�|j�t|jd��}|�d�}t�|�}Wd�n1s!wYt|j	�}t
jj}|�
d�}|||<|jt|�d�}t|jd��}|�|�t�||�Wd�n1s\wY|��}|�|jj|j�dS)N�rb�r�)�	co_consts�wb)r�r�r2r]r4�read�marshal�load�listrCr/r6�__code__�index�replace�tupler^�dumprGZconstant�co_filename)r2r�header�codeZ	constantsZforeign_code�posrurrr�test_foreign_code�s 
�


�z#PycRewritingTests.test_foreign_codeN)r�r�r�r�r3rFr'r�rr1r�r�r2r/r�r�r4r3r5r6r;r>r@rRrrrrr.[s		
r.c@sFeZdZdZeZdd�Zdd�Zdd�Ze	�
ejdkd	�d
d��Z
dS)
�
PathsTests)riutestäöüßutestéèu
test°³²cCs t�|j�tjdd�|_dSr.)rFrr'r$�syspathr1rrrr3�szPathsTests.setUpcCst|j�|jtjdd�<dSr.)rr'rTr$r1rrrr5�s
zPathsTests.tearDowncCsxttj�|jd�ddd��
}|�d�Wd�n1swYtj�|jd�td�}|�|j	d�t
d�dS)Nztest_trailing_slash.pyrXrYrZz testdata = 'test_trailing_slash'�/�test_trailing_slash)r]rFr'r�r^r$r�rprG�testdatar)r2rrurrrrV�s��zPathsTests.test_trailing_slashr�r�c	
Cs\ttj�|jd�d��
}|�d�Wd�n1swYt��tj�|j�}ddl}|�	�}|d}d||f}||dd�7}zt�
|�Wn tyl}z|jtj
tjtjfvrg|�d|f��d}~wwtj�d|�ztd�}Wnty�}z|�d	||f�WYd}~nd}~ww|�|jd�|�|j�|�|j�td�dS)
Nztest_unc_path.pyrXztestdata = 'test_unc_path'rz\\%s\%s$r�z%cannot access administrative share %rZ
test_unc_pathz,could not import 'test_unc_path' from %r: %r)r]rFr'r�r^r/r0r��socket�gethostname�listdirr�r��EPERMZEACCES�ENOENTr�r$r(rprBrqrGrWr�rIr{r)	r2rr'rXZhn�driveZuncr�rurrr�
test_UNC_path�s<������zPathsTests.test_UNC_pathN)r�r�r�ZSAMPLESrr'r3r5rVrrr$rzr^rrrrrS�s
rSc@sHeZdZdd�ZeZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�RelativeImportTestscCstd�dS)Nztest.relimport)rr1rrrr5�r6zRelativeImportTests.tearDowncCs ddlm}|�t|d��dS)Nr�)�	relimportr_)r!r`r�r�)r2r`rrr�test_relimport_star�sz'RelativeImportTests.test_relimport_starcs|�fdd�}tddd��|�tddd��|�tddd��|�t|�tddd��|�t|�tt�d��|�t|�dS)	Ncstd��dS)Nzfrom . import relimport)rbr�r5rr�check_relative�sz:RelativeImportTests.test_issue3221.<locals>.check_relativeriztest.notarealmodule)�__package__r�znotarealpkg.notarealmoduler�)rd)�dictr9r:�objectr`)r2rcrrbr�test_issue3221�sz"RelativeImportTests.test_issue3221cCst�dddd�dS)Nz-W�ignorer�zfoo = 1; from . import foo)rZassert_python_failurer1rrr�)test_parentless_import_shadowed_by_globals
�z=RelativeImportTests.test_parentless_import_shadowed_by_globalcCsF|�t��ddlm}|�d�Wd�dS1swYdS)Nr�)�sepz>explicit relative import triggered an implicit absolute import)r9rBrFrjrq)r2rjrrr�#test_absolute_import_without_futures"�z7RelativeImportTests.test_absolute_import_without_futurec
Cs�tj�tj�t�dd�}tdd��Lt|��/|�t��ddl	}Wd�n1s+wY|�
dtj�|�
dtj�Wd�n1sHwYWd�dSWd�dS1s`wYdS)Nr��package2�
submodule1�
submodule2r)
rFr'r�r�rIrr
r9rBrmrcr$r%)r2r'rmrrr�test_import_from_non_package s
�P�z0RelativeImportTests.test_import_from_non_packagec	Cs�tddd��6ttj�tj�t�d���ddl}|jj	Wd�n1s'wYWd�dSWd�dS1s?wYdS)Nrlzpackage2.submodule1zpackage2.submodule2r�r)
rr
rFr'r�r�rIZpackage2.submodule1rmrn)r2rlrrr�!test_import_from_unloaded_package(s�
P�z5RelativeImportTests.test_import_from_unloaded_packageN)r�r�r�r5r3rargrirkrorprrrrr_�s	r_c@r�)�OverridingImportBuiltinTestscCs�ddl}dd�}|�|�|�ttddd���|�|�d�Wd�n1s)wYtt�ddd���|�|�|�Wd�dS1sJwYdS)	NrcSsddl}|Sr8�rFrrrrrr�4sz?OverridingImportBuiltinTests.test_override_builtin.<locals>.foorpcW�dS�N�r�r�rrr�<lambda>9�zDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>rucWrsrtrrvrrrrw?rx)rFrGr�builtinsrrd)r2rFr�rrr�test_override_builtin0s�"�z2OverridingImportBuiltinTests.test_override_builtinN)r�r�r�rzrrrrrq/r�rqc@s�eZdZdd�Zdd�Zdd�Zedd��Ze�	e
jd	kd
�e�e
e
d�o*e
��dkd
�edd����Zedd��Zedd��Zdd�Zedd��Zedd��Zdd�Zdd�ZdS)�PycacheTestscCstt�td�t|j�dS)Nr)r	rrrr*r1rrr�_cleanFszPycacheTests._cleancCsjtd|_|��t|jddd��}td|d�Wd�n1s"wYtj�dtj	�t
��dS)NrrXrYrZz/# This is a test file written by test_import.pyrkr)rr*r|r]rmr$r'r(rFryr/r0)r2�fprrrr3Ks
�zPycacheTests.setUpcCs,tjdtjksJd��tjd=|��dS)NrzUnexpected sys.path[0])r$r'rFryr|r1rrrr5SszPycacheTests.tearDowncCsZ|�tj�d��tt�|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)Nrz*bytecode file {!r} for {!r} does not exist)�assertFalserFr'rrprr�r/r�r�r*r��r2Zpyc_pathrrr�test_import_pyc_pathXs�z!PycacheTests.test_import_pyc_pathrr�geteuidrz=due to varying filesystem permission semantics (issue #11956)cCsptd��tt�Wd�n1swY|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)N�rz"bytecode file {!r} for {!r} exists)
rrprr�rFr'rr/r�r�r*r~r�rrrr�test_unwritable_directorybs

��z&PycacheTests.test_unwritable_directorycCsVtt�tj�|j�}|�tj�	|��t�
|j�tt�t��|�
ttt�dSr.)rprr/r�r�r*r�rFr'rr)r	r0r9rB)r2r?rrr�test_missing_sourcersz PycacheTests.test_missing_sourcec
Cs|tt�t|j�}t�|j�tt�t��tt�}z|�	|j
tj�t�
�tjtj�|���Wt�|�dSt�|�wr.)rprr
r*rFr)rr/r0rGrIr'r��getcwdry�relpath�r2r?r,rrr�test_missing_source_legacy~s
�z'PycacheTests.test_missing_source_legacycCs<tt�}tj�td�}|�|jtj�	t�
�tj|��dS)Nr)rprr/r�r�rG�
__cached__rFr'r�r�ry)r2r,r?rrr�test___cached__�s$zPycacheTests.test___cached__c
Csbtt�t|j�}t�|j�tt�t��tt�}|�	|j
tj�t�
�tjtj�|���dSr.)rprr
r*rFr)rr/r0rGr�r'r�r�ryr�r�rrr�test___cached___legacy_pyc�s
�z'PycacheTests.test___cached___legacy_pyccCs
dd�}t�d�|�|�ttj�dd�d��Wd�n1s#wYttj�dd�d��Wd�n1s=wYt��td�}tj	�
tj�dd��}|�|jtj�t�
�tj|��tj	�
tj�dd��}|�tjdjtj�t�
�tj|��dS)NcS�td�td�td�dS�N�pep3147�pep3147.foo�rrrrrr�cleanup��z5PycacheTests.test_package___cached__.<locals>.cleanupr��__init__.pyrD�foo.pyr�)rFrr�r]r'r�r/r0rpr�r�rGr�r�ryr$r%�r2r�r,Zinit_pycZfoo_pycrrr�test_package___cached__�s&

��� �z$PycacheTests.test_package___cached__cCs*dd�}t�d�|�|�ttj�dd�d��Wd�n1s#wYttj�dd�d��Wd�n1s=wYt��td�}t	d�t	d�t��td�}tj
�tj�dd��}|�|j
tj�t��tj|��tj
�tj�dd��}|�tjdj
tj�t��tj|��dS)NcSr�r�r�rrrrr��r�z>PycacheTests.test_package___cached___from_pyc.<locals>.cleanupr�r�rDr�r�)rFrr�r]r'r�r/r0rprr�r�rGr�r�ryr$r%r�rrr� test_package___cached___from_pyc�s.

��� �z-PycacheTests.test_package___cached___from_pyccCsftt�tt�t|jddd��}td|d�Wd�n1s!wYtt�}|�|jd�dS)NrrrYrZzx = 5rkru)rprrr]r*rmrGr�)r2r}r,rrr�test_recompute_pyc_same_second�s�z+PycacheTests.test_recompute_pyc_same_secondN)r�r�r�r|r3r5rr�rrrFr�skipIfr�r�r�r�r�r�r�r�r�r�rrrrr{Cs2
	��



r{c@sVeZdZdZedZdd�Zdd�Ze�e	e
d�pe
��dkd	�ej
d
d���ZdS)
�TestSymbolicallyLinkedPackage�samplez-taggedcCs�t�|j�t�|j�tjdd�|_t�|j�|�	tj|j�tj�
|jd�}t�|�tj�|�s7J�tj
|j|jdd�|�	tj|j�t��|�tj�|j�d�tj�tj�
|jd��sfJ�dS)Nr�T)�target_is_directory)rr�tagged�package_namer$r'�
orig_sys_pathrFrr�r�Zcreate_empty_filer�symlinkrr/r0rG�isdir�isfile)r2Z	init_filerrrr3�s
 z#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd�<dSr.)r�r$r'r1rrrr5�sz&TestSymbolicallyLinkedPackage.tearDown�getwindowsversion)�rzWindows Vista or later requiredcCsNdgtjdd�<tj�|j�sJ�tj�tj�|jd��sJ�t�|j�dS)N�.r�)r$r'rFrr�r�r/r6r1rrr�test_symlinked_dir_importablesz;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)r�r�r�r�r�r3r5rrr�r$r�rZskip_unless_symlinkr�rrrrr��s
�r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportlibBootstrapTestscCstjd}|�|�dS)N�_frozen_importlib)r$r%r�r:rrr�test_frozen_importlibs
z-ImportlibBootstrapTests.test_frozen_importlibcC�Xddlm}tjd}|�||�|�|jd�|�|jd�|�|j	�
d�|j	�dS)Nr)�
_bootstrapr�zimportlib._bootstrapr/z
_bootstrap.py)r/r�r$r%r�rGr�rdr�rIr�)r2r�rurrr�"test_frozen_importlib_is_bootstrap�
z:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapcCr�)Nr)�_bootstrap_external�_frozen_importlib_externalzimportlib._bootstrap_externalr/z_bootstrap_external.py)r/r�r$r%r�rGr�rdr�rIr�)r2r�rurrr�4test_frozen_importlib_external_is_bootstrap_external"r�zLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalcCs*ddlm}tjd}|�|j|j�dS)Nr)�	machineryr�)r/r�r$r%r��
ModuleSpec)r2r�rurrr�test_there_can_be_only_one*s
z2ImportlibBootstrapTests.test_there_can_be_only_oneN)r�r�r�r�r�r�r�rrrrr�s
r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�GetSourcefileTestsz�Test importlib._bootstrap_external._get_sourcefile() as used by the C API.

    Because of the peculiarities of the need of this function, the tests are
    knowingly whitebox tests.

    cCsVt�d��}d|_td}td}|�t|�|�Wd�dS1s$wYdS)N�*importlib._bootstrap_external._path_isfileTrr�rZpatchZreturn_valuerrGr)r2�_path_isfiler'�expectrrr�test_get_sourcefile=s"�z&GetSourcefileTests.test_get_sourcefilecCsNt�d��}d|_td}|�t|�|�Wd�dS1s wYdS)Nr�Frr�)r2r�r'rrr�test_get_sourcefile_no_sourceFs
"�z0GetSourcefileTests.test_get_sourcefile_no_sourcecCstd}|�t|�|�dS)Nz.bad_ext)rrGr)r2r'rrr�test_get_sourcefile_bad_extNsz.GetSourcefileTests.test_get_sourcefile_bad_extN)r�r�r��__doc__r�r�r�rrrrr�3s
	r�c@s�eZdZdd�Zdd�Zd$dd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��Ze�ed �d!d"��Zd#S)%�ImportTracebackTestscCs,t�t�tjdd�|_tj�dt�dSr8)rFrrr$r'�old_pathr(r1rrrr3Ws
zImportTracebackTests.setUpcCs|jtjdd�<tt�dSr.)r�r$r'rrr1rrrr5\szImportTracebackTests.tearDownrcCsbtj�t||�}t|ddd��
}|�|�Wd�n1s wY|�t|�t�	�|S)NrXrYrZ)
rFr'r�rr]r^r�rr/r0)r2ru�contentsrtZfnamerrrr�
create_module`s�z"ImportTracebackTests.create_modulecCstg}|r|jj}|j}|r||dkr|�|�|j}|s|�t|�t|�|�t||�D]
\}}|�||�q-dS)Nr)	�tb_framer�rNr��tb_nextrG�len�ziprU)r2�tb�filesZ
deduped_filesrP�fn�patrrr�assert_tracebackhs
��z%ImportTracebackTests.assert_tracebackc
CsTzddl}Wnty}z	|j}WYd}~n
d}~ww|�d�|�|tg�dS)Nr�#ImportError should have been raised)�nonexistent_xyzzyrB�
__traceback__rqr�rI)r2r�r�r�rrr�test_nonexistent_modulets��
z,ImportTracebackTests.test_nonexistent_modulec
C�b|�dd�zddl}Wnty!}z	|j}WYd}~n
d}~ww|�d�|�|tdg�dS)Nr�zimport nonexistent_xyzzyrr�r�)r�r�rBr�rqr�rI�r2r�r�r�rrr�test_nonexistent_module_nested~���
z3ImportTracebackTests.test_nonexistent_module_nestedc
Cr�)Nr��1/0r�)ZeroDivisionError should have been raisedr��r�r�r�r�rqr�rIr�rrr�test_exec_failure�r�z&ImportTracebackTests.test_exec_failurec
Csp|�dd�|�dd�zddl}Wnty'}z	|j}WYd}~n
d}~ww|�d�|�|tddg�dS)	Nr�z
import bar�barr�rr�r��bar.pyr�r�rrr�test_exec_failure_nested�s��
z-ImportTracebackTests.test_exec_failure_nestedc
Cs`|�dd�zddl}Wnty!}z	|j}WYd}~n
d}~ww|�d�|�|tg�dS)Nr�zinvalid syntax is invalidrz#SyntaxError should have been raised)r�r��SyntaxErrorr�rqr�rIr�rrr�test_syntax_error�s��
z&ImportTracebackTests.test_syntax_errorcCs�d}|�t|�tj�t|�}t�|�tj�|d�}t|ddd��
}|�|�Wd�n1s2wYtj�|d�}t|ddd��
}|�|�Wd�n1sUwYt	�
�||fS)N�_parent_foor�rXrYrZr�)r�rrFr'r�rrr]r^r/r0)r2�parent�childZpkg_nameZpkg_path�	init_pathr�bar_pathrrr�_setup_broken_package�s
��z*ImportTracebackTests._setup_broken_packagec
Csf|�dd�\}}zddl}Wnty#}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr!r�rr��r�Z_parent_foo.barr�r�rqr�rI�r2r�r�r�r�r�rrr�test_broken_submodule����
z*ImportTracebackTests.test_broken_submodulec
Csj|�dd�\}}zddlm}Wnty%}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr!r�r�r�r��r�r�r�r�r�rqr�rI�r2r�r�r�r�r�rrr�test_broken_from����
z%ImportTracebackTests.test_broken_fromc
Csf|�dd�\}}zddl}Wnty#}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr�r!rr�r�r�rrr�test_broken_parent�r�z'ImportTracebackTests.test_broken_parentc
Csj|�dd�\}}zddlm}Wnty%}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr�r!rr�r�r�r�rrr�test_broken_parent_from�r�z,ImportTracebackTests.test_broken_parent_fromc
Cs�|�dd�tjd}dt|j�vr|jj}nd}zBdd�}||j_zddl}Wnty=}z	|j}WYd}~n
d}~ww|�	d�|�
|td	tg�W|durV|j`dS||j_dS|durd|j`w||j_w)
Nr�r!r��load_modulecWsdddS)Nr�rr)r�rrr�exec_module�r6z9ImportTracebackTests.test_import_bug.<locals>.exec_modulerr�z<frozen importlib)r�r$r%�vars�SourceLoaderr�r�r�r�rqr�rI)r2r/Zold_exec_moduler�r�r�r�rrr�test_import_bug�s,

��

�z$ImportTracebackTests.test_import_bugzneed TESTFN_UNENCODABLEcCs>t�dtd�}|�t|�|dd�}tjdd|dd�dS)Nr!�pass���r�zmod = __import__(%a)F)Z
__isolated)rr#rr�rr�)r2Zpynamerrrr�test_unencodable_filename�s
�z.ImportTracebackTests.test_unencodable_filenameN)r)r�r�r�r3r5r�r�r�r�r�r�r�r�r�r�r�r�rr�rrrr�rrrrr�Us&










r�c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the
    test.cCs*ttj���D]}|�d�rtj|=qdS)zSMake sure no modules pre-exist in sys.modules which are being used to
        test.z&test.test_import.data.circular_importsN)rHr$r%�keysr{)r2�keyrrrr5
s

��zCircularImportTests.tearDowncC�.zddl}WdSty|�d�YdSw)Nrz/circular import through relative imports failed)Z,test.test_import.data.circular_imports.basicrBrq�r2rirrr�test_direct�
�zCircularImportTests.test_directcCr�)Nrz@relative import in module contributing to circular import failed)Z/test.test_import.data.circular_imports.indirectrBrqr�rrr�
test_indirectr�z!CircularImportTests.test_indirectcCr�)Nrz-circular import involving a subpackage failed)Z1test.test_import.data.circular_imports.subpackagerBrqr�rrr�test_subpackager�z#CircularImportTests.test_subpackagecCs`zddlmmmm}Wnty|�d�Ynwddlm}|�	|j|j�dS)Nrz9circular import with rebinding of module attribute failed)r�)
Z0test.test_import.data.circular_imports.rebindingr|r�Zcircular_imports�	rebindingrBrqZ-test.test_import.data.circular_imports.subpkgr�r�)r2r�r�rrr�test_rebinding$s"�z"CircularImportTests.test_rebindingcCr�)Nrz9circular import with binding a submodule to a name failed)Z.test.test_import.data.circular_imports.bindingrBrqr�rrr�test_binding,r�z CircularImportTests.test_bindingcCsddl}ddl}dSr8)Z*test.test_import.data.circular_imports.use�-test.test_import.data.circular_imports.sourcer�rrr�test_crossreference12r4z(CircularImportTests.test_crossreference1cCsp|�t��}ddl}Wd�n1swYt|j�}|�d|�|�d|�|�d|�|�d|�dS)Nrz-test.test_import.data.circular_imports.sourcer"zpartially initialized modulezcircular import)r9r�rrKrHrU)r2rMri�errmsgrrr�test_crossreference26s
�
z(CircularImportTests.test_crossreference2cCsH|�t��}ddl}Wd�n1swY|�dt|j��dS)Nrz�cannot import name 'b' from partially initialized module 'test.test_import.data.circular_imports.from_cycle1' (most likely due to a circular import))r9rBZ2test.test_import.data.circular_imports.from_cycle1rUrKrH)r2rMrirrr�test_circular_from_import?s
��z-CircularImportTests.test_circular_from_importcCs�|�td�|�td�ddlmmm}|�t��ddlm}Wd�n1s.wY|�	t
|�t�|�t
|�t�|�
t��d|_Wd�dS1sWwYdS)Nz test.test_import.data.unwritablez"test.test_import.data.unwritable.xrrv�*)r�rZ test.test_import.data.unwritabler|r��
unwritableZassertWarns�
ImportWarningr�ZassertNotEqual�typerrGr9r�)r2rr�rrr�test_unwritable_moduleIs�"�z*CircularImportTests.test_unwritable_moduleN)r�r�r�r�r5r�r�r�r�r�rrrr	rrrrr�s	
r��__main__)Nr!)Bry�
contextlibr�r	�importlib.utilr/Zimportlib._bootstrap_externalrrFrFr�rnrr�rr$r�r�r�rrr�rrrrrZtest.support.import_helperr	r
rrr
Ztest.support.os_helperrrrrrrrZtest.test_importlib.utilr�typesrr��dont_write_bytecoderr �contextmanagerr,ZTestCaser-rr.rSr_rqr{r�r�r�r�r�r��mainrrrr�<module>sr�	GSY6E". !1
R�