Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/test_importlib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/test_importlib/__pycache__/util.cpython-38.pyc
U

?��g-H�@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'dDdd�Z(dEdd�Z)dFdd�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�Z5dGdd�Z6d d!�Z7ej8d"d#��Z9ej8dHdd$�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��ZAej8d5d6��ZBd7d8�ZCGd9d:�d:�ZDdId<d=�ZEGd>d?�d?ejF�ZGGd@dA�dA�ZHGdBdC�dCeH�ZIdS)J�N)�	machinery�util�invalidate_caches)�ResourceReader)�Path�PurePath)�support�)�data01)�	zipdata01�errno�	importlibZ	_testcapicCs`tjD]T}tjD]H}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�7/opt/cppython/lib/python3.8/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)�module_namer �frozen�sourcerrr�import_importlib7s
�r'c
Ks�|dkrtj}nt|t�s"||}d�||j�}||f}t�||�}|j|_|j|_	||_
|��D]\}}||}	t|||	�qb|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_class@s
r:cKs(t|d|f|�}t|d|f|�}||fS)Nr"r#)r:)r2r4r5r%r&rrr�split_frozenSsr;cKst||f|�Sr)r;)Z
test_classr4r5rrr�	test_bothYsr<T)�win32�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_testsls
��rB�c	CsBtj�||d�}t|d��}|�|�W5QRXd�||�|fS)N�.py�wz{}.{})rrr�open�writer+)�parentrZpkg_dir�contentrZsubfilerrr�	submodulessrJc
Cs6t|d��"}|�d�t�|�W5QR�SQRXdS)znReads a pyc file and returns the unmarshalled code object within.

    No header validation is performed.
    �rb�N)rF�seek�marshal�load)Zpyc_pathZpyc_frrr�_get_code_from_pyczs
rPcgs�|D]<}|dkrtd�|���ztj|=Wqtk
r>YqXqz
dVW5|D]&}ztj|=WqRtk
rvYqRXqRXdS)z�Uncache a module from sys.modules.

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

    )rrNZimpzcannot uncache {0}N)�
ValueErrorr+r�modules�KeyError)�namesrrrr�uncache�s �
rU)�pkgc#s��fdd�tjD�}t�d���}t�f|����t�|��zt�tj�	|��}|rntj�	|d�}t�
��n|d}|dkr�d}|dk	r�t|d��}|�|�W5QRX|VW5QRXW5QRXW5QRXdS)Ncs"g|]}|�d�d�kr|�qS)rr)�	partition)�.0�n�rrr�
<listcomp>�sztemp_module.<locals>.<listcomp>z__init__.pyrDrCrE)
rrRrZtemp_cwdrUZ
DirsOnSysPathrrrr�mkdirrFrG)rrIrV�	conflicts�cwd�location�modpathZmodfilerrZr�temp_module�s racks�i}z�dgfdgfdgfdiffD]>\}}tt|�||<||krP||}||=n|}tt||�q"t|�r|td�|�����dVW5|��D]\}}tt||�q�XdS)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)r0r1r�getattr�lenrQr+�keys)r5Z	originalsr7r9�defaultZ	new_valuerrr�import_state�s&
��
ric@s6eZdZdZid�dd�Zdd�Zdd�Zd	d
�ZdS)�
_ImporterMockz0Base class to help with creating importer mocks.)�module_codecGs�i|_i|_|D]�}|�d�s$|}n|dtd��}d|krDd}n||kr^|�dd�d}n|}t�|�}||_d|_||_	||_
||kr�dg|_||j|<||kr|||j|<qdS)N�	.__init__rr	rz<mock __file__>z<mock __path__>)rRrk�endswithrf�rsplitr-�
ModuleType�
__loader__�__file__�__package__r7�__path__)�selfrkrTr�import_name�package�modulerrr�__init__�s*


z_ImporterMock.__init__cCs
|j|Sr�rR)rtrrrr�__getitem__�sz_ImporterMock.__getitem__cCst|j���|_|j��|Sr)rUrRrg�_uncache�	__enter__�rtrrrr|�s
z_ImporterMock.__enter__cGs|j�ddd�dSr)r{�__exit__)rt�exc_inforrrr~�sz_ImporterMock.__exit__N)r,r/�__qualname__�__doc__rxrzr|r~rrrrrj�s
rjc@s"eZdZdZddd�Zdd�ZdS)�mock_modulesz!Importer mock using PEP 302 APIs.NcCs||jkrdS|SdSrry)rt�fullnamerrrr�find_modules
zmock_modules.find_modulecCsh||jkrt�nT|j|tj|<||jkrZz|j|�Wntk
rXtj|=�YnX|j|SdSr)rR�ImportErrorrrk�	Exception)rtr�rrr�load_modules

zmock_modules.load_module)N)r,r/r�r�r�r�rrrrr��s
r�c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�	mock_specz!Importer mock using PEP 451 APIs.NcCsFz|j|}Wntk
r$YdSXtj||j|t|dd�d�}|S)Nrs)�loader�submodule_search_locations)rRrSr�spec_from_file_locationrqre)rtr�rrHrw�specrrr�	find_specs
�zmock_spec.find_speccCs|j|jkrt�|j|jSr)rrRr�)rtr�rrr�
create_module$szmock_spec.create_modulecCs.z|j|jj�Wntk
r(YnXdSr)rk�__spec__rrS�rtrwrrr�exec_module)szmock_spec.exec_module)NN)r,r/r�r�r�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_sdSrr)�argsr5rrr�<lambda>4�z'writes_bytecode_files.<locals>.<lambda>cs(tj}dt_z�||�}W5|t_X|S)NF)r�dont_write_bytecode)r�r5ZoriginalZ	to_return��fxnrr�wrapper5sz&writes_bytecode_files.<locals>.wrapper)rr��	functools�wraps)r�r�rr�r�writes_bytecode_files0s
r�c
CsLzt�tj�|��Wn0tk
rF}z|jtjkr6�W5d}~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)rr\r�dirname�OSErrorr�EEXIST)�
bytecode_path�errorrrr�ensure_bytecode_pathAs
r�ccs$tj}|t_z
dVW5|t_XdS)z&Adjust and restore sys.pycache_prefix.N)r�pycache_prefix)�prefixZ_orig_prefixrrr�temporary_pycache_prefixMs

r�cgs�d}g}i}d}d}�z(t��}||d<t�}|D]�}|�d�sF|}	n|dtd��}	|�|	�|	t	j
krtt	j
|	=|�d�}
|}|
dd�D]2}tj
�||�}tj
�|�s�t�|�|�|�q�tj
�||
dd�}t|d	��}
|
�|�|��W5QRX|�|�|||<q2t|�}|��t|gd
�}|��|VW5|dk	�rX|�ddd�|dk	�rp|�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.rootrxrlr���rDrE�r)r~r�rmtree�tempfile�mkdtemp�setrmrf�addrrR�splitrrrrr\�appendrFrGr+rUr|ri)rTr&Z
created_paths�mappingZ
state_managerZuncache_managerZtemp_dirZimport_namesrruZ
name_partsrZ	directory�filerrr�create_modulesXsL









r�cs��fdd�}|S)zA mock sys.path_hooks entry.cs|�krt��Sr)r�)�entry��entries�importerrr�hook�szmock_path_hook.<locals>.hookr)r�r�r�rr�r�mock_path_hook�sr�c@seZdZdd�ZdS)�CASEOKTestBasecs,d}t�fdd�|D��|kr(��d�dS)N)sPYTHONCASEOK�PYTHONCASEOKc3s|]}|�jjjjkVqdSr)r
�_bootstrap_external�_os�environ)rX�xr}rr�	<genexpr>�s�z4CASEOKTestBase.caseok_env_changed.<locals>.<genexpr>z/os.environ changes not reflected in _os.environ)�anyZskipTest)rtZshould_existZ
possibilitiesrr}r�caseok_env_changed�s��z!CASEOKTestBase.caseok_env_changedN)r,r/r�r�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|Srr�rtrvrrr�get_resource_reader�sz2create_package.<locals>.Reader.get_resource_readercs||_t�t�r��n�SdSr��_pathr)r��rtr)r�rr�
open_resource�s
z,create_package.<locals>.Reader.open_resourcecs||_t�t�r��n�SdSrr�)rt�path_r�rr�
resource_path�s
z,create_package.<locals>.Reader.resource_pathcsJ||_t�t�r���D],}|�d�}t|�dkr|d|krdSqdS)N�/r	rTF)r�r)r�r�rf)rtr�r��parts��contentsrrr�is_resource�s

z*create_package.<locals>.Reader.is_resourcec3s"t�t�r���D]
}|VqdSr)r)r�)rtr�r�rrr��s
z'create_package.<locals>.Reader.contentsN)r,r/r�r�r�r�r�r�r�r�r�rrr�Reader�s

r�Ztestingpackagezdoes-not-exist)�origin�
is_package)rr-ror�
ModuleSpecr�rp)	r�rr�r�r�rrwr�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�dSr)�NotImplementedError)rtrvrrrr�execute�szCommonResourceTests.executecCs|�tjd�dS�N�
utf-8.file)r�r
r,r}rrr�test_package_name�sz%CommonResourceTests.test_package_namecCs|�td�dSr��r�r
r}rrr�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_pathc	Cs8tt�}|jd}|�t��|�t|�W5QRXdSr�)rrqrH�assertRaisesrQr�r
)rtr�	full_pathrrr�test_absolute_path�s
z&CommonResourceTests.test_absolute_pathc	Cs&|�t��|�td�W5QRXdS)Nz../data01/utf-8.file)r�rQr�r
r}rrr�test_relative_path�sz&CommonResourceTests.test_relative_pathcCstjtj=|�tjd�dSr�)rrRr
r,r�r}rrr�$test_importing_module_as_side_effect�s
z8CommonResourceTests.test_importing_module_as_side_effectc	Cs&|�t��|�td�W5QRXdSr�)r��	TypeErrorr�r,r}rrr�test_non_package_by_name�sz,CommonResourceTests.test_non_package_by_namec	Cs0|�t��tjd}|�|d�W5QRXdS)Nztest.test_importlib.utilr�)r�r�rrRr�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��assertEqualrpr�)rt�
bytes_datarvrrr�test_resource_opener
s
z(CommonResourceTests.test_resource_openercCs:t�d�}t}t||d�}|�|d�|�|jjd�dSr�)r�r�rqr�r�r�rpr�)rtr�rrvrrr�test_resource_paths

z&CommonResourceTests.test_resource_pathc	Cs6tt�t�d�}|�t��|�|d�W5QRXdS)Nr�r�)r�r�r�r�r�rrr�test_useless_loaders
�z'CommonResourceTests.test_useless_loaderN)r,r/r��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_MODULErqrH�str�	_zip_pathrrr�r
�
import_module�data)r2Z	data_pathZdata_dirrrr�
setUpClass#s
zZipSetupBase.setUpClasscCs~ztj�|j�Wntk
r&YnXztj|j=tj|jj=Wnt	k
rVYnXz|`|`Wnt
k
rxYnXdSr)rr�remover�rQrdrRr�r,rS�AttributeError)r2rrr�
tearDownClass+s
zZipSetupBase.tearDownClasscCst��}|jtjf|��dSr)rZ
modules_setupZ
addCleanupZmodules_cleanup)rtrRrrr�setUp>szZipSetupBase.setUp)r,r/r�r��classmethodr�r�r�rrrrr� s

r�c@seZdZeZdS)�ZipSetupN)r,r/r�rr�rrrrrCsr)N)N)N)rC)rC)Tr)Jr��builtins�
contextlibrr�r
rrr�
importlib.abcrr�rNrZos.path�pathlibrrrArr(rr�r-rCr
r�SimpleNamespaceZBUILTINSZ	good_nameZbad_name�builtin_module_namesrrrrrrrr'r:r;r<r@�platformrq�upperZchanged_name�lowerrZsource_importlib�staticmethod�
__import__rBrJrP�contextmanagerrUrarirjr�r�r�r�r�r�r�r�r��ABCr�r�rrrrr�<module>s�


	



�



)


9		
2J#

F1le Man4ger