Your IP : 216.73.216.85


Current Path : /opt/alt/python37/lib64/python3.7/test/test_importlib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/test/test_importlib/__pycache__/util.cpython-37.pyc

B

� f$G�@s�ddlZddlZddlZddlZddlZddlZddlmZmZmZddl	m
Z
ddlZddlZddl
Z
ddlZ
ddlmZmZddlmZddlZddlZddlZddlZddlmZddlmZe��Zde_de_d	ejkr�d	e_d
ejkr�d
e_e��a dt _!dt _"dt _#dt _$dt _%dd
�Z&e&�dd�Z'dBdd�Z(dCdd�Z)dDdd�Z*dZ+ej,dk�r�e-�.�Z/e/e-k�r|e-�0�Z/e
j!�1e/��s�dZ+e'd
�dZ2e3ej4�e3e2j4�d�Z4dd�Z5dEdd�Z6d d!�Z7ej8d"d#��Z9ej8dFdd$�d%d&��Z:ej8d'd(��Z;Gd)d*�d*�Z<Gd+d,�d,e<�Z=Gd-d.�d.e<�Z>d/d0�Z?d1d2�Z@ej8d3d4��ZAd5d6�ZBGd7d8�d8�ZCdGd:d;�ZDGd<d=�d=ejE�ZFGd>d?�d?�ZGGd@dA�dAeG�ZHdS)H�N)�	machinery�util�invalidate_caches)�ResourceReader)�Path�PurePath)�support�)�data01)�	zipdata01�errno�	importlibZ	_testcapicCsdx^tjD]T}xNtjD]D}tj|}tj�||�}tj�|�r|t_|t_	|t_
|t_dSqWqWdS)N)�sys�pathr�EXTENSION_SUFFIXES�
EXTENSIONS�name�os�join�exists�ext�filename�	file_path)rrrr�r�=/opt/alt/python37/lib64/python3.7/test/test_importlib/util.py�_extension_details's
rcCs4d|krdnd}t�|�}tj||dd�}||d�S)zAImport a module from importlib both w/ and w/o _frozen_importlib.�.)r
r)�_frozen_importlib�_frozen_importlib_external)�freshZblocked)�Frozen�Source)rZimport_fresh_module)Zmodule_namer�frozen�sourcerrr�import_importlib7s

r$c
Ks�|dkrtj}nt|t�s"||}d�||j�}||f}t�||�}|j|_|j|_	||_
x(|��D]\}}||}	t|||	�qdW|S)Nz{}_{})
�unittestZTestCase�
isinstance�type�format�__name__�types�	new_class�
__module__Z_NAMEZ_KIND�items�setattr)
�clsZkind�base�kwargsr�basesZspecialized�attr�values�valuerrr�specialize_class@s
r6cKs(t|d|f|�}t|d|f|�}||fS)Nr r!)r6)r/r0r1r"r#rrr�split_frozenSsr7cKst||f|�S)N)r7)Z
test_classr0r1rrr�	test_bothYsr8T)Zwin32�cygwinFr!)r 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_testslsr=�c	CsBtj�||d�}t|d��}|�|�WdQRXd�||�|fS)Nz.py�wz{}.{})rrr�open�writer()�parentrZpkg_dir�contentrZsubfilerrr�	submodulessrDc	Cs*t|d��}|�d�t�|�SQRXdS)znReads a pyc file and returns the unmarshalled code object within.

    No header validation is performed.
    �rb�N)r@�seek�marshal�load)Zpyc_pathZpyc_frrr�_get_code_from_pyczs
rJcgs�xD|D]<}|dkr td�|���ytj|=Wqtk
r@YqXqWz
dVWdx.|D]&}ytj|=WqXtk
r|YqXXqXWXdS)z�Uncache a module from sys.modules.

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

    )rrHZimpzcannot uncache {0}N)�
ValueErrorr(r�modules�KeyError)�namesrrrr�uncache�s



rO)�pkgc#s��fdd�tjD�}t�d���}t�f|����t�|��zt�tj�	|��}|rntj�	|d�}t�
��n|d}|dkr�d}|dk	r�t|d��}|�|�WdQRX|VWdQRXWdQRXWdQRXdS)Ncs"g|]}|�d�d�kr|�qS)rr)�	partition)�.0�n)rrr�
<listcomp>�sztemp_module.<locals>.<listcomp>z__init__.pyz.pyr>r?)
rrLrZtemp_cwdrOZ
DirsOnSysPathrrrr�mkdirr@rA)rrCrPZ	conflicts�cwd�locationZmodpathZmodfiler)rr�temp_module�s rXcks�i}z�x^dgfdgfdgfdiffD]>\}}tt|�||<||krR||}||=n|}tt||�q$Wt|�r�td�|�����dVWdx |��D]\}}tt||�q�WXdS)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)�getattrrr.�lenrKr(�keysr-)r1Z	originalsr3�defaultZ	new_valuer5rrr�import_state�s"

r`c@s6eZdZdZid�dd�Zdd�Zdd�Zd	d
�ZdS)�
_ImporterMockz0Base class to help with creating importer mocks.)�module_codecGs�i|_i|_x�|D]�}|�d�s&|}n|dtd��}d|krFd}n||kr`|�dd�d}n|}t�|�}||_d|_||_	||_
||kr�dg|_||j|<||kr|||j|<qWdS)Nz	.__init__rr	rz<mock __file__>z<mock __path__>)rLrb�endswithr]�rsplitr*�
ModuleType�
__loader__�__file__�__package__r3�__path__)�selfrbrNr�import_name�package�modulerrr�__init__�s*



z_ImporterMock.__init__cCs
|j|S)N)rL)rjrrrr�__getitem__�sz_ImporterMock.__getitem__cCst|j���|_|j��|S)N)rOrLr^�_uncache�	__enter__)rjrrrrq�s
z_ImporterMock.__enter__cGs|j�ddd�dS)N)rp�__exit__)rj�exc_inforrrrr�sz_ImporterMock.__exit__N)r)r,�__qualname__�__doc__rnrorqrrrrrrra�s
rac@s"eZdZdZddd�Zdd�ZdS)�mock_modulesz!Importer mock using PEP 302 APIs.NcCs||jkrdS|SdS)N)rL)rj�fullnamerrrr�find_modules
zmock_modules.find_modulecCsh||jkrt�nT|j|tj|<||jkrZy|j|�Wntk
rXtj|=�YnX|j|SdS)N)rL�ImportErrorrrb�	Exception)rjrwrrr�load_modules

zmock_modules.load_module)N)r)r,rtrurxr{rrrrrv�s
rvc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�	mock_specz!Importer mock using PEP 451 APIs.NcCsDy|j|}Wntk
r"dSXtj||j|t|dd�d�}|S)Nri)�loader�submodule_search_locations)rLrMr�spec_from_file_locationrgr\)rjrwrrBrm�specrrr�	find_specszmock_spec.find_speccCs|j|jkrt�|j|jS)N)rrLry)rjr�rrr�
create_module$szmock_spec.create_modulecCs.y|j|jj�Wntk
r(YnXdS)N)rb�__spec__rrM)rjrmrrr�exec_module)szmock_spec.exec_module)NN)r)r,rtrur�r�r�rrrrr|s

r|cs(tjrdd�St����fdd��}|S)ztDecorator to protect sys.dont_write_bytecode from mutation and to skip
    tests that require it to be set to False.c_sdS)Nr)�argsr1rrr�<lambda>4�z'writes_bytecode_files.<locals>.<lambda>cs(tj}dt_z�||�}Wd|t_X|S)NF)r�dont_write_bytecode)r�r1ZoriginalZ	to_return)�fxnrr�wrapper5sz&writes_bytecode_files.<locals>.wrapper)rr��	functools�wraps)r�r�r)r�r�writes_bytecode_files0s	r�c
CsLyt�tj�|��Wn0tk
rF}z|jtjkr6�Wdd}~XYnXdS)z�Ensure that the __pycache__ directory for PEP 3147 pyc file exists.

    :param bytecode_path: File system path to PEP 3147 pyc file.
    N)rrUr�dirname�OSErrorrZEEXIST)�
bytecode_path�errorrrr�ensure_bytecode_pathAs
r�cgs�d}g}i}d}d}�z0t��}||d<t�}x�|D]�}|�d�sH|}	n|dtd��}	|�|	�|	tjkrvtj|	=|�d�}
|}xB|
dd�D]2}t	j
�||�}t	j
�|�s�t	�
|�|�|�q�Wt	j
�||
dd�}t|d	��}
|
�|�|��WdQRX|�|�|||<q4Wt|�}|��t|gd
�}|��|VWd|dk	�r`|�ddd�|dk	�rx|�ddd�t�|�XdS)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.rootrnz	.__init__r���z.pyr?)r)�tempfileZmkdtemp�setrcr]�addrrL�splitrrrrrU�appendr@rAr(rOrqr`rrrZrmtree)rNr#Z
created_paths�mappingZ
state_managerZuncache_managerZtemp_dirZimport_namesrrkZ
name_partsrZ	directory�filerrr�create_modulesMsL









r�cs��fdd�}|S)zA mock sys.path_hooks entry.cs|�krt��S)N)ry)�entry)�entries�importerrr�hook�szmock_path_hook.<locals>.hookr)r�r�r�r)r�r�r�mock_path_hook�sr�c@seZdZdd�ZdS)�CASEOKTestBasecs,d}t�fdd�|D��|kr(��d�dS)N)sPYTHONCASEOK�PYTHONCASEOKc3s|]}|�jjjjkVqdS)N)r
�_bootstrap_external�_os�environ)rR�x)rjrr�	<genexpr>�sz4CASEOKTestBase.caseok_env_changed.<locals>.<genexpr>z/os.environ changes not reflected in _os.environ)�anyZskipTest)rjZshould_existZ
possibilitiesr)rjr�caseok_env_changed�sz!CASEOKTestBase.caseok_env_changedN)r)r,rtr�rrrrr��sr�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|S)Nr)rjrlrrr�get_resource_reader�sz2create_package.<locals>.Reader.get_resource_readercs||_t�t�r��n�SdS)N)�_pathr&rz)rjr)r�rr�
open_resource�s
z,create_package.<locals>.Reader.open_resourcecs||_t�t�r��n�SdS)N)r�r&rz)rj�path_)rrr�
resource_path�s
z,create_package.<locals>.Reader.resource_pathcsL||_t�t�r��x2�D]*}|�d�}t|�dkr|d|krdSqWdS)N�/r	rTF)r�r&rzr�r])rjr�r��parts)�contentsrrr�is_resource�s


z*create_package.<locals>.Reader.is_resourcec3s&t�t�r��x�D]
}|VqWdS)N)r&rz)rjr�)r�rrrr��s

z'create_package.<locals>.Reader.contentsN)r)r,rtr�r�r�r�r�r)r�r�rrr�Reader�s

r�Ztestingpackagezdoes-not-exist)�origin�
is_package)rr*rer�
ModuleSpecr�rf)	r�rr�r�r�rrmr}r�r)r�r�rr�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�dS)N)�NotImplementedError)rjrlrrrr�execute�szCommonResourceTests.executecCs|�tjd�dS)Nz
utf-8.file)r�r
r))rjrrr�test_package_name�sz%CommonResourceTests.test_package_namecCs|�td�dS)Nz
utf-8.file)r�r
)rjrrr�test_package_object�sz'CommonResourceTests.test_package_objectcCsd}|�t|�dS)Nz
utf-8.file)r�r
)rjrrrr�test_string_path�sz$CommonResourceTests.test_string_path)��zrequires os.PathLike supportcCstd�}|�t|�dS)Nz
utf-8.file)rr�r
)rjrrrr�test_pathlib_path�sz%CommonResourceTests.test_pathlib_pathc	Cs8tt�}|jd}|�t��|�t|�WdQRXdS)Nz
utf-8.file)rrgrB�assertRaisesrKr�r
)rjr�	full_pathrrr�test_absolute_path�s
z&CommonResourceTests.test_absolute_pathc	Cs&|�t��|�td�WdQRXdS)Nz../data01/utf-8.file)r�rKr�r
)rjrrr�test_relative_path�sz&CommonResourceTests.test_relative_pathcCstjtj=|�tjd�dS)Nz
utf-8.file)rrLr
r)r�)rjrrr�$test_importing_module_as_side_effect�s
z8CommonResourceTests.test_importing_module_as_side_effectc	Cs&|�t��|�td�WdQRXdS)Nz
utf-8.file)r��	TypeErrorr�r))rjrrr�test_non_package_by_name�sz,CommonResourceTests.test_non_package_by_namec	Cs0|�t��tjd}|�|d�WdQRXdS)Nztest.test_importlib.utilz
utf-8.file)r�r�rrLr�)rjrmrrr�test_non_package_by_package�s
z/CommonResourceTests.test_non_package_by_package)r�zNo ResourceReader in Python 2cCs8t�d�}t|t�d�}|�|d�|�|jjd�dS)Ns
Hello, world!)r�rz
utf-8.file)�io�BytesIOr��FileNotFoundErrorr��assertEqualrfr�)rj�
bytes_datarlrrr�test_resource_opener�s
z(CommonResourceTests.test_resource_openercCs:t�d�}t}t||d�}|�|d�|�|jjd�dS)Ns
Hello, world!)r�rz
utf-8.file)r�r�rgr�r�r�rfr�)rjr�rrlrrr�test_resource_paths

z&CommonResourceTests.test_resource_pathc	Cs6tt�t�d�}|�t��|�|d�WdQRXdS)N)r�rz
utf-8.file)r�r�r�r�)rjrlrrr�test_useless_loaders
z'CommonResourceTests.test_useless_loaderN)r)r,rt�abc�abstractmethodr�r�r�r�r%r:r�version_infor�r�r�r�r�r�r�r�r�rrrrr��sr�c@s0eZdZdZedd��Zedd��Zdd�ZdS)�ZipSetupBaseNcCs>t|jj�}|j}t|d�|_tj�|j�t	�
d�|_dS)Nzziptestdata.zipZziptestdata)r�
ZIP_MODULErgrB�str�	_zip_pathrrr�r
�
import_module�data)r/Z	data_pathZdata_dirrrr�
setUpClasss
zZipSetupBase.setUpClasscCs~ytj�|j�Wntk
r&YnXytj|j=tj|jj=Wnt	k
rVYnXy|`|`Wnt
k
rxYnXdS)N)rr�remover�rKr[rLr�r)rM�AttributeError)r/rrr�
tearDownClass s
zZipSetupBase.tearDownClasscCst��}|jtjf|��dS)N)rZ
modules_setupZ
addCleanupZmodules_cleanup)rjrLrrr�setUp3szZipSetupBase.setUp)r)r,rtr��classmethodr�r�r�rrrrr�sr�c@seZdZeZdS)�ZipSetupN)r)r,rtrr�rrrrr�8sr�)N)N)N)r>)r>)Tr)Ir��builtins�
contextlibrr�r
rrrZ
importlib.abcrr�rHrZos.pathZpathlibrrr<rr%rr�r*r>r
r�SimpleNamespaceZBUILTINSZ	good_nameZbad_name�builtin_module_namesrrrrrrrr$r6r7r8r;�platformrg�upperZchanged_name�lowerrZsource_importlib�staticmethod�
__import__r=rDrJ�contextmanagerrOrXr`rarvr|r�r�r�r�r�r��ABCr�r�r�rrrr�<module>s�


	





):		
2J#