Your IP : 216.73.216.147


Current Path : /opt/alt/python310/lib64/python3.10/test/test_importlib/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/test_importlib/__pycache__/util.cpython-310.opt-1.pyc

o

0�i�H�@s�ddlZddlZddlZddlZddlZddlZddlmZmZmZddl	m
Z
ddlZddlZddl
Z
ddlZ
ddlmZmZddlmZddlmZddlmZddlZddlZddlZddlZdd	lmZdd
lmZe��Zde_ de_!dej"vr�de_ dej"vr�de_!e��a#dt#_$dt#_%dt#_&dt#_'d
t#_(dd�Z)e)�dd�Z*dFdd�Z+dFdd�Z,dFdd�Z-dZ.ej/dvr�e0�1�Z2e2e0kr�e0�3�Z2e
j$�4e2�s�dZ.e*d�dZ5e6ej7�e6e5j7�d�Z7dd�Z8dGd d!�Z9d"d#�Z:ej;d$d%��Z<ej;dGdd&�d'd(��Z=ej;d)d*��Z>Gd+d,�d,�Z?Gd-d.�d.e?�Z@Gd/d0�d0e?�ZAd1d2�ZBd3d4�ZCej;d5d6��ZDej;d7d8��ZEd9d:�ZFGd;d<�d<�ZGdHd>d?�ZHGd@dA�dAejI�ZJGdBdC�dC�ZKGdDdE�dEeK�ZLdS)I�N)�	machinery�util�invalidate_caches)�ResourceReader)�Path�PurePath)�support)�
import_helper)�	os_helper�)�data01)�	zipdata01�errno�	importlibZ	_testcapicCs`tjD]*}tjD]$}tj|}tj�||�}tj�|�r,|t_|t_	|t_
|t_dSqqdS�N)�sys�pathr�EXTENSION_SUFFIXES�
EXTENSIONS�name�os�join�exists�ext�filename�	file_path)rrrr�r�?/opt/alt/python310/lib64/python3.10/test/test_importlib/util.py�_extension_details)s


���rcCs4d|vrdnd}t�|�}tj||dd�}||d�S)zAImport a module from importlib both w/ and w/o _frozen_importlib.�.)rr)�_frozen_importlib�_frozen_importlib_external)�freshZblocked��Frozen�Source)r	Zimport_fresh_module)Zmodule_namer"�frozen�sourcerrr�import_importlib9s
�
r(c
Ks�|durtj}n	t|t�s||}d�||j�}||f}t�||�}|j|_|j|_	||_
|��D]\}}||}	t|||	�q1|S)Nz{}_{})
�unittestZTestCase�
isinstance�type�format�__name__�types�	new_class�
__module__Z_NAMEZ_KIND�items�setattr)
�cls�kind�base�kwargsr�basesZspecialized�attr�values�valuerrr�specialize_classBs
r;cKs0t|d|fi|��}t|d|fi|��}||fS)Nr$r%)r;)r3r5r6r&r'rrr�split_frozenUsr<cKst||fi|��Sr)r<)Z
test_classr5r6rrr�	test_both[sr=T)Zwin32�cygwinFr%r#cCst�td�|�S)zRClass decorator that nullifies tests requiring a case-insensitive
    file system.z&requires a case-insensitive filesystem)r)�skipIf�CASE_INSENSITIVE_FS)�testrrr�case_insensitive_testsns
��rB�cCsZtj�||d�}t|ddd��
}|�|�Wd�n1s wYd�||�|fS)N�.py�w�utf-8��encodingz{}.{})rrr�open�writer,)�parentrZpkg_dir�contentrZsubfilerrr�	submoduleus
�rMcCsBt|d��}|�d�t�|�Wd�S1swYdS)znReads a pyc file and returns the unmarshalled code object within.

    No header validation is performed.
    �rb�N)rI�seek�marshal�load)Zpyc_pathZpyc_frrr�get_code_from_pyc|s
$�rScgs��|D]}|dvrtd�|���ztj|=WqtyYqwzdVW|D]}ztj|=Wq'ty8Yq'wdS|D]}ztj|=Wq=tyNYq=ww)z�Uncache a module from sys.modules.

    A basic sanity check is performed to prevent uncaching modules that either
    cannot/shouldn't be uncached.

    )rrQZimpzcannot uncache {0}N)�
ValueErrorr,r�modules�KeyError)�namesrrrr�uncache�s4�������rX)�pkgc#s<��fdd�tjD�}t�d���}t�g|�R��ct�|��Nt�tj	�
|��}|r9tj	�
|d�}t���n
|d}|durCd}|durct|ddd��
}|�
|�Wd�n1s^wY|VWd�n1spwYWd�n1swYWd�dSWd�dS1s�wYdS)	Ncs"g|]
}|�d�d�kr|�qS)rr)�	partition)�.0�n�rrr�
<listcomp>�s"ztemp_module.<locals>.<listcomp>z__init__.pyrDrCrErFrG)rrUr
Ztemp_cwdrXr	Z
DirsOnSysPathrrrr�mkdirrIrJ)rrLrYZ	conflicts�cwd�location�modpathZmodfilerr]r�temp_module�s0������"�rccks��i}zPdgfdgfdgfdiffD]\}}tt|�||<||vr)||}||=n|}tt||�qt|�r?td�|�����dVW|��D]
\}}tt||�qGdS|��D]
\}}tt||�qXw)a,Context manager to manage the various importers and stored state in the
    sys module.

    The 'modules' attribute is not supported as the interpreter state stores a
    pointer to the dict that the interpreter uses internally;
    reassigning to sys.modules does not have the desired effect.

    �	meta_pathr�
path_hooks�path_importer_cachezunrecognized arguments: {0}N)�getattrrr2�lenrTr,�keysr1)r6Z	originalsr8�defaultZ	new_valuer:rrr�import_state�s.�
����rkc@s6eZdZdZid�dd�Zdd�Zdd�Zd	d
�ZdS)�
_ImporterMockz0Base class to help with creating importer mocks.)�module_codecGs�i|_i|_|D]R}|�d�s|}n	|dtd��}d|vr"d}n||kr/|�dd�d}n|}t�|�}||_d|_||_	||_
||krJdg|_||j|<||vrZ|||j|<qdS)N�	.__init__rrrz<mock __file__>z<mock __path__>)rUrm�endswithrh�rsplitr.�
ModuleType�
__loader__�__file__�__package__r8�__path__)�selfrmrWr�import_name�package�modulerrr�__init__�s.


��z_ImporterMock.__init__cCs
|j|Sr�rU)rvrrrr�__getitem__�s
z_ImporterMock.__getitem__cCst|j���|_|j��|Sr)rXrUri�_uncache�	__enter__�rvrrrr~�s
z_ImporterMock.__enter__cGs|j�ddd�dSr)r}�__exit__)rv�exc_inforrrr��sz_ImporterMock.__exit__N)r-r0�__qualname__�__doc__rzr|r~r�rrrrrl�srlc@s"eZdZdZddd�Zdd�ZdS)�mock_modulesz!Importer mock using PEP 302 APIs.NcCs||jvrdS|Srr{)rv�fullnamerrrr�find_modules
zmock_modules.find_modulecCs\||jvrt�|j|tj|<||jvr)z|j|�Wnty(tj|=�w|j|Sr)rU�ImportErrorrrm�	Exception)rvr�rrr�load_module
s

�
zmock_modules.load_moduler)r-r0r�r�r�r�rrrrr�s
r�c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�	mock_specz!Importer mock using PEP 451 APIs.NcCsDz|j|}Wn
tyYdSwtj||j|t|dd�d�}|S)Nru)�loader�submodule_search_locations)rUrVr�spec_from_file_locationrsrg)rvr�rrKry�specrrr�	find_specs�
�zmock_spec.find_speccCs|j|jvrt�|j|jSr)rrUr�)rvr�rrr�
create_module&szmock_spec.create_modulecCs,z|j|jj�WdStyYdSwr)rm�__spec__rrV�rvryrrr�exec_module+s
�zmock_spec.exec_module)NN)r-r0r�r�r�r�r�rrrrr�s


r�cs.tjr
t�d���St����fdd��}|S)ztDecorator to protect sys.dont_write_bytecode from mutation and to skip
    tests that require it to be set to False.zrelies on writing bytecodecs0tj}dt_z
�|i|��}W|t_|S|t_w)NF)r�dont_write_bytecode)�argsr6ZoriginalZ	to_return��fxnrr�wrapper7s�z&writes_bytecode_files.<locals>.wrapper)rr�r)�skip�	functools�wraps)r�r�rr�r�writes_bytecode_files2s
r�c
CsNzt�tj�|��WdSty&}z|jtjkr�WYd}~dSd}~ww)z�Ensure that the __pycache__ directory for PEP 3147 pyc file exists.

    :param bytecode_path: File system path to PEP 3147 pyc file.
    N)rr_r�dirname�OSErrorrZEEXIST)�
bytecode_path�errorrrr�ensure_bytecode_pathCs���r�ccs*�tj}|t_z	dVW|t_dS|t_w)z&Adjust and restore sys.pycache_prefix.N)r�pycache_prefix)�prefixZ_orig_prefixrrr�temporary_pycache_prefixOs�r�cgs��d}g}i}d}d}z�t��}||d<t�}|D]{}|�d�s#|}	n	|dtd��}	|�|	�|	tjvr:tj|	=|�d�}
|}|
dd�D]}t	j
�||�}t	j
�|�s`t	�
|�|�|�qGt	j
�||
dd�}t|d	d
d��}
|
�|�|��Wd�n1s�wY|�|�|||<qt|�}|��t|gd�}|��|VW|dur�|�ddd�|dur�|�ddd�t�|�dS|dur�|�ddd�|dur�|�ddd�t�|�w)
aRTemporarily create each named module with an attribute (named 'attr')
    that contains the name passed into the context manager that caused the
    creation of the module.

    All files are created in a temporary directory returned by
    tempfile.mkdtemp(). This directory is inserted at the beginning of
    sys.path. When the context manager exits all created files (source and
    bytecode) are explicitly deleted.

    No magic is performed when creating packages! This means that if you create
    a module within a package you must also create the package's __init__ as
    well.

    zattr = {0!r}Nz.rootrzrnr���rDrErFrG�r)�tempfileZmkdtemp�setrorh�addrrU�splitrrrrr_�appendrIrJr,rXr~rkr�r
Zrmtree)rWr'Z
created_paths�mappingZ
state_managerZuncache_managerZtemp_dirZimport_namesrrwZ
name_partsrZ	directory�filerrr�create_modulesZs\�





��

�r�cs��fdd�}|S)zA mock sys.path_hooks entry.cs|�vrt��Sr)r�)�entry��entries�importerrr�hook�szmock_path_hook.<locals>.hookr)r�r�r�rr�r�mock_path_hook�sr�c@seZdZdd�ZdS)�CASEOKTestBasecs0d}t�fdd�|D��|kr��d�dSdS)N)sPYTHONCASEOK�PYTHONCASEOKc3s �|]}|�jjjjvVqdSr)r�_bootstrap_external�_os�environ)r[�xrrr�	<genexpr>�s��z4CASEOKTestBase.caseok_env_changed.<locals>.<genexpr>z/os.environ changes not reflected in _os.environ)�anyZskipTest)rvZshould_existZ
possibilitiesrrr�caseok_env_changed�s���z!CASEOKTestBase.caseok_env_changedN)r-r0r�r�rrrrr��sr�rc	sNG���fdd�dt�}d}t�|�}|�}tj||d|d�}||_||_|S)NcsHeZdZdd�Z�fdd�Z�fdd�Z��fdd�Z��fd	d
�ZdS)zcreate_package.<locals>.ReadercSs|Srr�rvrxrrr�get_resource_reader�sz2create_package.<locals>.Reader.get_resource_readerc�||_t�t�r
���Sr��_pathr*r��rvr)r�rr�
open_resource��
z,create_package.<locals>.Reader.open_resourcecr�rr�)rv�path_r�rr�
resource_path�r�z,create_package.<locals>.Reader.resource_pathcsJ||_t�t�r
���D]}|�d�}t|�dkr"|d|kr"dSqdS)N�/rrTF)r�r*r�r�rh)rvr�r��parts��contentsrrr�is_resource�s

�z*create_package.<locals>.Reader.is_resourcec3s$�t�t�r���D]}|Vq
dSr)r*r�)rvr�r�rrr��s�
�z'create_package.<locals>.Reader.contentsN)r-r0r�r�r�r�r�r�r�r�r�rrr�Reader�s
r�Ztestingpackagezdoes-not-exist)�origin�
is_package)rr.rqr�
ModuleSpecr�rr)	r�rr�r�r�rryr�r�rr�r�create_package�s#
�r�c@s�eZdZejdd��Zdd�Zdd�Zdd�Ze	�
ejd	kd
�dd��Z
d
d�Zdd�Zdd�Zdd�Zdd�Ze	�
ejdkd�dd��Ze	�
ejdkd�dd��Zdd�ZdS) �CommonResourceTestscCst�r)�NotImplementedError)rvrxrrrr�execute�szCommonResourceTests.executecCs|�tjd�dS�N�
utf-8.file)r�rr-rrrr�test_package_name�sz%CommonResourceTests.test_package_namecCs|�td�dSr��r�rrrrr�test_package_object�sz'CommonResourceTests.test_package_objectcCsd}|�t|�dSr�r�r�rrr�test_string_path�sz$CommonResourceTests.test_string_path)��zrequires os.PathLike supportcCstd�}|�t|�dSr�)rr�rr�rrr�test_pathlib_path�sz%CommonResourceTests.test_pathlib_pathcCsNtt�}|jd}|�t��|�t|�Wd�dS1s wYdSr�)rrsrK�assertRaisesrTr�r)rvr�	full_pathrrr�test_absolute_path�s

"�z&CommonResourceTests.test_absolute_pathcC�<|�t��|�td�Wd�dS1swYdS)Nz../data01/utf-8.file)r�rTr�rrrrr�test_relative_path��"�z&CommonResourceTests.test_relative_pathcCstjtj=|�tjd�dSr�)rrUrr-r�rrrr�$test_importing_module_as_side_effect�s
z8CommonResourceTests.test_importing_module_as_side_effectcCr�r�)r��	TypeErrorr�r-rrrr�test_non_package_by_namer�z,CommonResourceTests.test_non_package_by_namecCsF|�t��tjd}|�|d�Wd�dS1swYdS)Nztest.test_importlib.utilr�)r�r�rrUr�r�rrr�test_non_package_by_packages
"�z/CommonResourceTests.test_non_package_by_package)r�zNo ResourceReader in Python 2cCs8t�d�}t|t�d�}|�|d�|�|jjd�dS�Ns
Hello, world!�r�rr�)�io�BytesIOr��FileNotFoundErrorr��assertEqualrrr�)rv�
bytes_datarxrrr�test_resource_openers
z(CommonResourceTests.test_resource_openercCs:t�d�}t}t||d�}|�|d�|�|jjd�dSr�)r�r�rsr�r�r�rrr�)rvr�rrxrrr�test_resource_paths

z&CommonResourceTests.test_resource_pathcCsLtt�t�d�}|�t��|�|d�Wd�dS1swYdS)Nr�r�)r�r�r�r�r�rrr�test_useless_loaders�"�z'CommonResourceTests.test_useless_loaderN)r-r0r��abc�abstractmethodr�r�r�r�r)r?r�version_infor�r�r�r�r�r�r�r�r�rrrrr��s$



r�c@s0eZdZdZedd��Zedd��Zdd�ZdS)�ZipSetupBaseNcCs>t|jj�}|j}t|d�|_tj�|j�t	�
d�|_dS)Nzziptestdata.zipZziptestdata)r�
ZIP_MODULErsrK�str�	_zip_pathrrr�r�
import_module�data)r3Z	data_pathZdata_dirrrr�
setUpClass%s
zZipSetupBase.setUpClasscCsxz	tj�|j�Wn	tyYnwz
tj|j=tj|jj=Wn	t	y)Ynwz|`|`WdSt
y;YdSwr)rr�remover�rTrfrUr�r-rV�AttributeError)r3rrr�
tearDownClass-s"�
�
�zZipSetupBase.tearDownClasscCs t��}|jtjg|�R�dSr)r	Z
modules_setupZ
addCleanupZmodules_cleanup)rvrUrrr�setUp@szZipSetupBase.setUp)r-r0r�r��classmethodr�r�rrrrrr�"s

r�c@seZdZeZdS)�ZipSetupN)r-r0r�r
r�rrrrrEsrr)rC)Tr)Mr��builtins�
contextlibrr�rrrrZ
importlib.abcrr�rQrZos.pathZpathlibrrrArZtest.supportr	r
r)rr�r.rCrr
�SimpleNamespaceZBUILTINSZ	good_nameZbad_name�builtin_module_namesrrrrrrrr(r;r<r=r@�platformrs�upperZchanged_name�lowerrZsource_importlib�staticmethod�
__import__rBrMrS�contextmanagerrXrcrkrlr�r�r�r�r�r�r�r�r��ABCr�r�rrrrr�<module>s�



	


�



)


9	
	2J#