HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/test/__pycache__/test_pkgutil.cpython-36.pyc
3


 \E�@s�ddlmZmZmZmZddlZddlZddlZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZGdd�dej�ZGdd�dej�ZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�Zdd�Zedkr�e�dS)�)�run_unittest�unload�check_warnings�CleanImportN)�spec_from_file_locationc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�PkgutilTestscCs.tj�|_|jtj|j�tjjd|j�dS)Nr)	�tempfile�mkdtemp�dirname�
addCleanup�shutil�rmtree�sys�path�insert)�self�r�$/usr/lib64/python3.6/test_pkgutil.py�setUps
zPkgutilTests.setUpcCstjd=dS)Nr)rr)rrrr�tearDownszPkgutilTests.tearDowncCs�d}d}tjj|j|�}tj|�ttjj|d�d�}|j�ttjj|d�d�}|j|�|j�tjtjj|d��ttjj|dd�d�}|j|�|j�tj	|d�}|j
||�tj	|d�}|j
||�tj|=dS)N�test_getdata_filesyss%Hello, world!
Second line
Third linez__init__.py�wbzres.txt�subzsub/res.txt)
�osr�joinr
�mkdir�open�close�write�pkgutil�get_data�assertEqualr�modules)r�pkg�
RESOURCE_DATAZpackage_dir�f�res1�res2rrrrs$


z!PkgutilTests.test_getdata_filesysc
Cs�d}d}d}tjj|j|�}tj|d�}|j|dd�|j|d|�|j|d|�|j�tjj	d	|�t
j|d
�}|j||�t
j|d�}|j||�g}x.t
j
|g�D]}	|j|	t
j�|j|	j�q�W|j|dg�tjd	=tj|=dS)Nztest_getdata_zipfile.zip�test_getdata_zipfiles%Hello, world!
Second line
Third line�wz/__init__.py�z/res.txtz/sub/res.txtrzres.txtzsub/res.txt)rrrr
�zipfile�ZipFile�writestrrrrrr r!Ziter_modules�assertIsInstanceZ
ModuleInfo�append�namer")
r�zipr#r$�zip_file�zr&r'�namesZ
moduleinforrrr(:s*z!PkgutilTests.test_getdata_zipfilecCsVd}tjj|j|�}tj|d�|jtj|�x"tj|jgd�D]}|j	d�q@WdS)NZunreadable_packager)rzunexpected package found)
rrrr
rr�rmdirr�
walk_packagesZfail)rZpackage_name�d�trrr�test_unreadable_dir_on_syspath]sz+PkgutilTests.test_unreadable_dir_on_syspathc	Cstd}tjj|j|�}tj|�ttjj|d�d�}|j�tjtjj|d��ttjj|dd�d�}|j�ttjj|dd�d�}|j�d}tjj|j|�}tj|�ttjj|d�d�}|j�tjtjj|d��ttjj|dd�d�}|j�ttjj|dd�d�}|j�dddddd	g}d
d�tj|jg�D�}|j	||�x&|D]}|j
d��rb�qNtj|=�qNWdS)
N�test_walkpackages_filesysz__init__.pyrrzmod.pyzsub.test_walkpackages_filesysz!sub.test_walkpackages_filesys.modztest_walkpackages_filesys.subz!test_walkpackages_filesys.sub.modcSsg|]}|d�qS)�r)�.0�errr�
<listcomp>�sz:PkgutilTests.test_walkpackages_filesys.<locals>.<listcomp>�mod)
rrrr
rrrrr6r!�endswithrr")	r�pkg1Zpkg1_dirr%�pkg2Zpkg2_dir�expected�actualr#rrrr:hs@


z&PkgutilTests.test_walkpackages_filesysc	Cs d}d}d}tjj|j|�}tj|d�}|j|dd�|j|d|dd�|j|d|dd�|j|dd�|j|d|dd�|j|d|dd�|j�tjj	d	|�dd
dddd
g}dd�t
j|g�D�}|j||�tjd	=x"|D]}|j
d��rq�tj|=q�WdS)zBTests the same as test_walkpackages_filesys, only with a zip file.ztest_walkpackages_zipfile.zip�test_walkpackages_zipfilerr)z/__init__.pyr*�/z/mod.pyrzsub.test_walkpackages_zipfilez!sub.test_walkpackages_zipfile.modztest_walkpackages_zipfile.subz!test_walkpackages_zipfile.sub.modcSsg|]}|d�qS)r;r)r<r=rrrr>�sz:PkgutilTests.test_walkpackages_zipfile.<locals>.<listcomp>r?N)rrrr
r+r,r-rrrrr6r!r@r")	rr1rArBr2r3rCrDr#rrrrE�s4
z&PkgutilTests.test_walkpackages_zipfileN)
�__name__�
__module__�__qualname__rrrr(r9r:rErrrrrs#(rc@sLeZdZGdd�de�ZGdd�de�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�PkgutilPEP302Testsc@s$eZdZdd�Zdd�Zdd�ZdS)zPkgutilPEP302Tests.MyTestLoadercCsdS)Nr)r�specrrr�
create_module�sz-PkgutilPEP302Tests.MyTestLoader.create_modulecCs|jjdd�d|jd<dS)N�loadsrr;)�__dict__�get)rr?rrr�exec_module�sz+PkgutilPEP302Tests.MyTestLoader.exec_modulecCsdS)Nz
Hello, world!r)rrrrrr �sz(PkgutilPEP302Tests.MyTestLoader.get_dataN)rGrHrIrLrPr rrrr�MyTestLoader�srQc@seZdZddd�ZdS)z!PkgutilPEP302Tests.MyTestImporterNcCs tj�}t|d|jj|gd�S)Nz<%s>)�loader�submodule_search_locations)rJrQr�	__class__rG)r�fullnamer�targetrRrrr�	find_spec�s

z+PkgutilPEP302Tests.MyTestImporter.find_spec)NN)rGrHrIrWrrrr�MyTestImporter�srXcCstjjd|j��dS)Nr)r�	meta_pathrrX)rrrrr�szPkgutilPEP302Tests.setUpcCstjd=dS)Nr)rrY)rrrrr�szPkgutilPEP302Tests.tearDowncCs |jtjdd�d�tjd=dS)N�foo�dummyz
Hello, world!)r!rr rr")rrrr�test_getdata_pep302�sz&PkgutilPEP302Tests.test_getdata_pep302cCsDddl}|j|jd�|jtjdd�d�|j|jd�tjd=dS)Nrr;rZr[z
Hello, world!)rZr!rMrr rr")rrZrrr�test_alreadyloaded�s
z%PkgutilPEP302Tests.test_alreadyloadedN)
rGrHrI�objectrQrXrrr\r]rrrrrJ�srJc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ExtendPathTestsc	Cs\tj�}tjjd|�tjj||�}tj|�ttjj|d�d��}|j	d�WdQRX|S)Nrz__init__.pyr)zKfrom pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
)
rr	rrrrrrrr)r�pkgnamer
Zpkgdir�flrrr�create_init�s
zExtendPathTests.create_initcCs@tjj|||d�}t|d��}tdj|�|d�WdQRXdS)Nz.pyr)zvalue={})�file)rrrr�print�format)rr
r`Zsubmodule_name�valueZmodule_namerarrr�create_submodule�sz ExtendPathTests.create_submodulecCs�d}|j|�}|j|�}|j||dd�|j||dd�ddl}ddl}|j|jjd�|j|jjd�|jt|j	�tt
jj||�t
jj||�g��t
j|�t
j|�tjd=tjd=tjd=tjd=tjd=dS)NrZ�barr�bazr;zfoo.barzfoo.baz)rbrg�foo.bar�foo.bazr!rhrfri�sorted�__path__rrrrr
rr")rr`�	dirname_0�	dirname_1rZrrr�test_simple�s&



zExtendPathTests.test_simplec
 Cs�tj}tj}d}d}|j|�}tjj||�}dj||�}tj	j
|d�tj	j
|d�z�|j|||d�tj
|�t||��}||�}	x||D]t}
tj|
|�}|j}y
|j}Wntk
r�YnX|j|
tjj�|j|
|	�|j|tjj�|jtj|
|��q�W|jt��t|d��WdQRX|jt��t|d��WdQRXWdtj|�tjd=ytj	d=tj	d=Wntk
�r�YnXXdS)N�spamZeggsz{}.{}rzinvalid.modulez.spamz	spam.eggs)r�iter_importers�get_importerrbrrrrerr"�poprg�	importlib�
import_module�list�	_get_specrR�AttributeErrorr.�	machinery�
FileFinderr!�SourceFileLoader�assertIsNoneZassertRaises�ImportErrorrr
�KeyError)
rrrrsr`�modnamer
ZpathitemrUZ	importersZexpected_importer�finderrKrRrrr�test_iter_importerssJ





z#ExtendPathTests.test_iter_importerscCs�d}|j|�}|j|�}|j||dd�tjtjj||d��|j||dd�ddl}ddl}|j|j	j
d�|j|jj
d�|jt|j
�ttjj||�tjj||�g��tj|�tj|�tjd=tjd=tjd=tjd=tjd=dS)	NrZrhrz__init__.pyrir;zfoo.barzfoo.baz)rbrgr�unlinkrrrjrkr!rhrfrirlrmrr
rr")rr`rnrorZrrr�test_mixed_namespace@s(



z$ExtendPathTests.test_mixed_namespaceN)rGrHrIrbrgrpr�r�rrrrr_�s
0r_c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�NestedNamespacePackageTestcCstj�|_tjdd�|_dS)N)rr	�basedirrr�old_path)rrrrras
z NestedNamespacePackageTest.setUpcCs |jtjdd�<tj|j�dS)N)r�rrrr
r�)rrrrresz#NestedNamespacePackageTest.tearDownc	Csl|jdd�\}}tjj|j|jdtjj��}tj|dd�ttjj||d�d��}|j	|�WdQRXdS)N�.r;T)�exist_okz.pyr))
�rsplitrrrr��replace�sep�makedirsrr)rr0�contents�base�final�	base_pathr%rrrrLis
z(NestedNamespacePackageTest.create_modulecCsd}|jd|�|jd|�|jd|�|jd|�|jdd�|jdd	�tjjd
tjj|jd��tjjd
tjj|jd��d
dl}|jt	d
�|j
t|j�d�d
dl
}|jt	d�|j
t|jj�d�d
dlm}d
dlm}|j
|d�|j
|d�dS)NzBimport pkgutil; __path__ = pkgutil.extend_path(__path__, __name__)za.pkg.__init__zb.pkg.__init__za.pkg.subpkg.__init__zb.pkg.subpkg.__init__za.pkg.subpkg.czc = 1zb.pkg.subpkg.dzd = 2r�a�br#�z
pkg.subpkg)�c)r7r;)rLrrrrrr�r#rrr!�lenrmZ
pkg.subpkgZsubpkgZpkg.subpkg.cr�Zpkg.subpkg.dr7)rZpkgutil_boilerplater#r�r7rrr�test_nestedps&z&NestedNamespacePackageTest.test_nestedN)rGrHrIrrrLr�rrrrr�_sr�c@s|eZdZdd�Zdd�Zdd�Zdd�Zejed	kd
�dd��Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�ImportlibMigrationTestscCstdtf�S)Nz5This emulation is deprecated, use 'importlib' instead)r�DeprecationWarning)rrrr�check_deprecated�sz(ImportlibMigrationTests.check_deprecatedc	Cs"|j��tjd�WdQRXdS)Nr*)r�rZImpImporter)rrrr�test_importer_deprecated�s
z0ImportlibMigrationTests.test_importer_deprecatedcCs(|j��tjdddd�WdQRXdS)Nr*)r�rZ	ImpLoader)rrrr�test_loader_deprecated�s
z.ImportlibMigrationTests.test_loader_deprecatedc
CsXt��H}|jtjd��|jtjd��|jtjd��|jt|j�d�WdQRXdS)Nrrztest.supportr)r�assertIsNotNoner�
get_loaderr!r��warnings)rr)rrr� test_get_loader_avoids_emulation�s
z8ImportlibMigrationTests.test_get_loader_avoids_emulation�__main__znot compatible with __main__cCsJt}bz8t��(}|jtjt��|jt|j�d�WdQRXWd|aXdS)Nr)	�
__loader__rr�rr�rGr!r�r�)rZthis_loaderr)rrr�0test_get_loader_handles_missing_loader_attribute�s zHImportlibMigrationTests.test_get_loader_handles_missing_loader_attributec
CsJd}tt�|�}|`t|��|tj|<tj|�}WdQRX|j|�dS)Nrq)�typer�__spec__rr"rr�r})rr0r?rRrrr�.test_get_loader_handles_missing_spec_attribute�s

zFImportlibMigrationTests.test_get_loader_handles_missing_spec_attributec
CsLd}tt�|�}d|_t|��|tj|<tj|�}WdQRX|j|�dS)Nrq)r�rr�rr"rr�r})rr0r?rRrrr�+test_get_loader_handles_spec_attribute_none�s

zCImportlibMigrationTests.test_get_loader_handles_spec_attribute_nonecCs6d}dtj|<ztj|�}Wdtj|=X|j|�dS)Nz
totally bogus)rr"rr�r})rr0rRrrr�#test_get_loader_None_in_sys_modules�s

z;ImportlibMigrationTests.test_get_loader_None_in_sys_modulescCsd}tj|�}|j|�dS)Nz
totally bogus)r�find_loaderr})rr0rRrrr�test_find_loader_missing_module�s
z7ImportlibMigrationTests.test_find_loader_missing_modulec
CsXt��H}|jtjd��|jtjd��|jtjd��|jt|j�d�WdQRXdS)Nrrztest.supportr)rr�rr�r!r�r�)rr)rrr�!test_find_loader_avoids_emulation�s
z9ImportlibMigrationTests.test_find_loader_avoids_emulationc
Cs8t��(}|jtjd��|jt|j�d�WdQRXdS)Nz*??r)rr}rrsr!r�r�)rr)rrr�"test_get_importer_avoids_emulation�sz:ImportlibMigrationTests.test_get_importer_avoids_emulationc
Cs:t��*}xtj�D]}qW|jt|j�d�WdQRXdS)Nr)rrrrr!r�r�)rr)Zimporterrrr�$test_iter_importers_avoids_emulation�sz<ImportlibMigrationTests.test_iter_importers_avoids_emulationN)rGrHrIr�r�r�r��unittestZskipIfr�r�r�r�r�r�r�r�rrrrr��s			r�cCs6tttttt�ddl}ddl}|jj	�|j
�dS)Nr)rrrJr_r�r��	zipimportru�_zip_directory_cache�clear�invalidate_caches)r�rurrr�	test_main�s
r�r�)Ztest.supportrrrrr�rru�importlib.utilrrrZos.pathrrr+ZTestCaserrJr_r�r�r�rGrrrr�<module>s&#-})X