Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_pkgutil.cpython-39.pyc

a

��g�Z�@s�ddlmZddlmZmZmZddlZddlZddlZddl	m
Z
ddlZddlZddl
ZddlZddlZddlZGdd�dej�ZGdd�dej�ZGd	d
�d
ej�ZGdd�dej�ZGd
d�dej�Zdd�Zedkr�e��dS)�)�Path)�unload�check_warnings�CleanImportN)�spec_from_file_locationc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�PkgutilTestscCs.t��|_|�tj|j�tj�d|j�dS�Nr)	�tempfile�mkdtemp�dirname�
addCleanup�shutil�rmtree�sys�path�insert��self�r�-/usr/local/lib/python3.9/test/test_pkgutil.py�setUps
zPkgutilTests.setUpcCstjd=dSr)rrrrrr�tearDownszPkgutilTests.tearDowncCs�d}d}tj�|j|�}t�|�ttj�|d�d�}|��ttj�|d�d�}|�|�|��t�tj�|d��ttj�|dd�d�}|�|�|��t�	|d�}|�
||�t�	|d�}|�
||�tj|=dS)N�test_getdata_filesys�%Hello, world!
Second line
Third line�__init__.py�wb�res.txt�sub�sub/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}tj�|j|�}t�|d�}|�|dd�|�|d|�|�|d|�|��tj�	d	|�t
�|d
�}|�||�t
�|d�}|�||�g}t
�
|g�D]}	|�|	t
j�|�|	j�q�|�|dg�tjd	=tj|=dS)N�test_getdata_zipfile.zip�test_getdata_zipfiler�w�/__init__.py��/res.txtz/sub/res.txtrrr)rrr r�zipfile�ZipFile�writestrr#rrr%r&r'�iter_modules�assertIsInstance�
ModuleInfo�append�namer()
r�zipr)r*�zip_file�zr,r-�names�
moduleinforrrr/;s*z!PkgutilTests.test_getdata_zipfilec

Cs0d}d}d}tj�|j|�}t�|d�}|�|dd�|�|d|�|��tj�	d|�ztt
�|d	�}|�||�g}t
�
t|�g�D]}|�|t
j�|�|j�q�|�||g�Wtjd=tj�|d�ntjd=tj�|d�0d
}	|�t|	��tt
�
d��Wd�n1�s"0YdS)Nr.r/rr0r1r2r3rrz9path must be None or list of paths to look for modules inZinvalid_path)rrr rr4r5r6r#rrr%r&r'r7rr8r9r:r;r(�popZassertRaisesRegex�
ValueError�list)
rr<r)r*r=r>�resr?r@Zexpected_msgrrr�test_issue44061_iter_modules^s0�z)PkgutilTests.test_issue44061_iter_modulescCsRd}tj�|j|�}t�|d�|�tj|�tj|jgd�D]}|�	d�q>dS)NZunreadable_packager)rzunexpected package found)
rrr rr!r�rmdirr%�
walk_packages�fail)rZpackage_name�d�trrr�test_unreadable_dir_on_syspath�sz+PkgutilTests.test_unreadable_dir_on_syspathc	Cshd}tj�|j|�}t�|�ttj�|d�d�}|��t�tj�|d��ttj�|dd�d�}|��ttj�|dd�d�}|��d}tj�|j|�}t�|�ttj�|d�d�}|��t�tj�|d��ttj�|dd�d�}|��ttj�|dd�d�}|��gd�}dd�t�|jg�D�}|�	||�|D]}|�
d	��rX�qDtj|=�qDdS)
N�test_walkpackages_filesysrrrzmod.py)rzsub.test_walkpackages_filesysz!sub.test_walkpackages_filesys.modrLztest_walkpackages_filesys.subz!test_walkpackages_filesys.sub.modcSsg|]}|d�qS��r��.0�errr�
<listcomp>��z:PkgutilTests.test_walkpackages_filesys.<locals>.<listcomp>�mod)
rrr rr!r"r#r%rGr'�endswithrr()	r�pkg1Zpkg1_dirr+�pkg2Zpkg2_dir�expected�actualr)rrrrL�s6

z&PkgutilTests.test_walkpackages_filesysc	Csd}d}d}tj�|j|�}t�|d�}|�|dd�|�|d|dd�|�|d|dd�|�|dd�|�|d|dd�|�|d|dd�|��tj�	d	|�gd
�}dd�t
�|g�D�}|�||�tjd	=|D]}|�
d
��rq�tj|=q�dS)zBTests the same as test_walkpackages_filesys, only with a zip file.ztest_walkpackages_zipfile.zip�test_walkpackages_zipfilerr0r1r2�/z/mod.pyr)rzsub.test_walkpackages_zipfilez!sub.test_walkpackages_zipfile.modrZztest_walkpackages_zipfile.subz!test_walkpackages_zipfile.sub.modcSsg|]}|d�qSrMrrOrrrrR�rSz:PkgutilTests.test_walkpackages_zipfile.<locals>.<listcomp>rTN)rrr rr4r5r6r#rrr%rGr'rUr()	rr<rVrWr=r>rXrYr)rrrrZ�s*z&PkgutilTests.test_walkpackages_zipfilecCs�d}|�ttf��tt�|��Wd�n1s60Yd}|�ttf��tt�|��Wd�n1sv0YdS)NZtest_dirstest_dir)�assertRaises�	TypeErrorrBrCr%rG)r�	str_inputZbytes_inputrrr�2test_walk_packages_raises_on_string_or_bytes_input�s,z?PkgutilTests.test_walk_packages_raises_on_string_or_bytes_inputc
Cs�ddl}ddl}dtfdtjfdtjjfd|fd|fd|jfd|jfd	|jjfd
|jjfd|jjjfd|jjjfd
tfdtfdtj	fdtj	fdt
fdt
fdtjff}dtfdtfdtfdtfdtfdtfdtfdt
fdtfdt
fdt
fdtfdtfd tfd!t
fd"tfd#tff}d$}|D]�}tj�|j|�}ztj|dd%�Wnt�yVY�qYn0tj�|d&�}t|d'��"}|�d�|��Wd�n1�s�0Yt��t�|�}|||ff7}t|�dk�r||dd(�t
ff7}�q|d)tff7}|D]N\}	}
|j|	d*��&t�|	�}|�||
�Wd�n1�s@0Y�q�|D]n\}	}|j|	d*��F|�|��t�|	�Wd�n1�s�0YWd�n1�s�0Y�qRdS)+Nrrzos.pathzos.path:pathsep�loggingzlogging:zlogging.handlerszlogging.handlers:zlogging.handlers:SysLogHandlerzlogging.handlers.SysLogHandlerz(logging.handlers:SysLogHandler.LOG_ALERTz(logging.handlers.SysLogHandler.LOG_ALERTzbuiltins.intzbuiltins:intzbuiltins.int.from_byteszbuiltins:int.from_byteszbuiltins.ZeroDivisionErrorzbuiltins:ZeroDivisionErrorzos:pathrNg@Tr2z?abczabc/foo�foozos.foozos.foo:zos.pth:pathsepzlogging.handlers:NoSuchHandlerz,logging.handlers:SysLogHandler.NO_SUCH_VALUEz,logging.handlers.SysLogHandler.NO_SUCH_VALUE�ZeroDivisionErrorzos.path.9abcZ9abc)	u	वमस�é�Èu안녕하세요uさよならuありがとうuХорошоuспасибоu现代汉语常用字表��exist_okrr0���u०वमस)�s)r`Zlogging.handlersrr�pathsep�handlersZ
SysLogHandlerZ	LOG_ALERT�int�
from_bytesrbr]rB�ImportError�AttributeErrorr r�makedirs�UnicodeEncodeErrorr"r$�flush�	importlib�invalidate_caches�
import_module�lenZsubTestr%�resolve_namer'r\)
rr`Z
success_casesZ
failure_casesZ
unicode_wordsZuwrIr+rTrhrX�o�excrrr�test_name_resolution�s�


����	
(

0z!PkgutilTests.test_name_resolutionN)
�__name__�
__module__�__qualname__rrrr/rErKrLrZr_ryrrrrrs#'(#
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_moduleDsz-PkgutilPEP302Tests.MyTestLoader.create_modulecCs|j�dd�d|jd<dS)N�loadsrrN)�__dict__�get)rrTrrr�exec_moduleGsz+PkgutilPEP302Tests.MyTestLoader.exec_modulecCsdS)N�
Hello, world!r)rrrrrr&Ksz(PkgutilPEP302Tests.MyTestLoader.get_dataN)rzr{r|r�r�r&rrrr�MyTestLoaderCsr�c@seZdZddd�ZdS)z!PkgutilPEP302Tests.MyTestImporterNcCs t��}t|d|jj|gd�S)Nz<%s>)�loader�submodule_search_locations)r}r�r�	__class__rz)r�fullnamer�targetr�rrr�	find_specOs
�z+PkgutilPEP302Tests.MyTestImporter.find_spec)NN)rzr{r|r�rrrr�MyTestImporterNsr�cCstj�d|���dSr)r�	meta_pathrr�rrrrrVszPkgutilPEP302Tests.setUpcCstjd=dSr)rr�rrrrrYszPkgutilPEP302Tests.tearDowncCs |�t�dd�d�tjd=dS)Nra�dummyr�)r'r%r&rr(rrrr�test_getdata_pep302\sz&PkgutilPEP302Tests.test_getdata_pep302cCsDddl}|�|jd�|�t�dd�d�|�|jd�tjd=dS)NrrNrar�r�)rar'r�r%r&rr()rrarrr�test_alreadyloadedas
z%PkgutilPEP302Tests.test_alreadyloadedN)
rzr{r|�objectr�r�rrr�r�rrrrr}Asr}c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ExtendPathTestscCspt��}tj�d|�tj�||�}t�|�ttj�|d�d��}|�	d�Wd�n1sb0Y|S)Nrrr0zKfrom pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
)
r	r
rrrrr r!r"r$)r�pkgnamerZpkgdir�flrrr�create_initos
(zExtendPathTests.create_initcCsTtj�|||d�}t|d��"}td�|�|d�Wd�n1sF0YdS)N�.pyr0zvalue={})�file)rrr r"�print�format)rrr�Zsubmodule_name�value�module_namer�rrr�create_submodulezsz ExtendPathTests.create_submodulec	Cs�d}|�|�}|�|�}|�||dd�|�||dd�ddl}ddl}|�|jjd�|�|jjd�|�t|j	�tt
j�||�t
j�||�g��t
�|�t
�|�tjd=tjd=tjd=tjd=tjd=dS)Nra�barr�bazrN�foo.bar�foo.baz)r�r��foo.bar�foo.bazr'r�r�r��sorted�__path__rrr r
rrr(�rr�Z	dirname_0Z	dirname_1rarrr�test_simples*

��

zExtendPathTests.test_simplec
Cs�tj}tj}d}d}|�|�}tj�||�}d�||�}tj	�
|d�tj	�
|d��zV|�|||d�t�
|�t||��}||�}	|D]r}
t�|
|�}|j}z
|j}Wnty�Yn0|�|
tjj�|�|
|	�|�|tjj�|�t�|
|��q�|�t��t|d��Wd�n1�s,0Y|�t��t|d��Wd�n1�sd0YWt�|�tjd=ztj	d=tj	d=Wnt�y�Yn0n>t�|�tjd=ztj	d=tj	d=Wnt�y�Yn00dS)N�spamZeggsz{}.{}rzinvalid.modulez.spamz	spam.eggs)r%�iter_importers�get_importerr�rrr r�rr(rAr�rrrtrC�	_get_specr�rnr8�	machinery�
FileFinderr'�SourceFileLoader�assertIsNoner\rmr
r�KeyError)
rr�r�r��modnamerZpathitemr�Z	importersZexpected_importer�finderrr�rrr�test_iter_importers�sZ


�,.
�
z#ExtendPathTests.test_iter_importersc	Cs�d}|�|�}|�|�}|�||dd�t�tj�||d��|�||dd�ddl}ddl}|�|j	j
d�|�|jj
d�|�t|j
�ttj�||�tj�||�g��t�|�t�|�tjd=tjd=tjd=tjd=tjd=dS)	Nrar�rrr�rNr�r�)r�r�r�unlinkrr r�r�r'r�r�r�r�r�r
rrr(r�rrr�test_mixed_namespace�s,

��

z$ExtendPathTests.test_mixed_namespaceN)rzr{r|r�r�r�r�r�rrrrr�ns
0r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�NestedNamespacePackageTestcCst��|_tjdd�|_dSr~)r	r
�basedirrr�old_pathrrrrr�s
z NestedNamespacePackageTest.setUpcCs |jtjdd�<t�|j�dSr~)r�rrr
rr�rrrrr�sz#NestedNamespacePackageTest.tearDowncCs�|�dd�\}}tj�|j|�dtjj��}tj|dd�ttj�||d�d��}|�	|�Wd�n1sr0YdS)N�.rNTrer�r0)
�rsplitrrr r��replace�sepror"r$)rr;�contents�base�final�	base_pathr+rrrr��s
z(NestedNamespacePackageTest.create_modulecCsd}|�d|�|�d|�|�d|�|�d|�|�dd�|�dd	�tj�d
tj�|jd��tj�d
tj�|jd��d
dl}|�t	d
�|�
t|j�d�d
dl
}|�t	d�|�
t|jj�d�d
dlm}d
dlm}|�
|d�|�
|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)rIrN)r�rrrrr r�r)rrr'rur�Z
pkg.subpkgZsubpkgZpkg.subpkg.cr�Zpkg.subpkg.drI)rZpkgutil_boilerplater)r�rIrrr�test_nested�s(�z&NestedNamespacePackageTest.test_nestedN)rzr{r|rrr�r�rrrrr��sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Ze�ed	kd
�dd��Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�ImportlibMigrationTestscCstdtf�S)Nz5This emulation is deprecated, use 'importlib' instead)r�DeprecationWarningrrrr�check_deprecateds
��z(ImportlibMigrationTests.check_deprecatedcCs6|���t�d�Wd�n1s(0YdS�Nr2)r�r%ZImpImporterrrrr�test_importer_deprecateds
z0ImportlibMigrationTests.test_importer_deprecatedcCs<|��� t�dddd�Wd�n1s.0YdSr�)r�r%Z	ImpLoaderrrrr�test_loader_deprecated"s
z.ImportlibMigrationTests.test_loader_deprecatedcCslt��R}|�t�d��|�t�d��|�t�d��|�t|j�d�Wd�n1s^0YdS�Nrrztest.supportr)r�assertIsNotNoner%�
get_loaderr'ru�warnings�rr0rrr� test_get_loader_avoids_emulation&s
z8ImportlibMigrationTests.test_get_loader_avoids_emulation�__main__znot compatible with __main__cCsbt}bzPt��2}|�t�t��|�t|j�d�Wd�n1sF0YW|an|a0dSr)	�
__loader__rr�r%r�rzr'rur�)rZthis_loaderr0rrr�0test_get_loader_handles_missing_loader_attribute-s2zHImportlibMigrationTests.test_get_loader_handles_missing_loader_attributecCs^d}tt�|�}|`t|��$|tj|<t�|�}Wd�n1sF0Y|�|�dS�Nr���typer�__spec__rr(r%r�r��rr;rTr�rrr�.test_get_loader_handles_missing_spec_attribute9s

(zFImportlibMigrationTests.test_get_loader_handles_missing_spec_attributecCs`d}tt�|�}d|_t|��$|tj|<t�|�}Wd�n1sH0Y|�|�dSr�r�r�rrr�+test_get_loader_handles_spec_attribute_noneBs

(zCImportlibMigrationTests.test_get_loader_handles_spec_attribute_nonecCs>d}dtj|<zt�|�}Wtj|=n
tj|=0|�|�dS�Nz
totally bogus)rr(r%r�r��rr;r�rrr�#test_get_loader_None_in_sys_modulesKs
z;ImportlibMigrationTests.test_get_loader_None_in_sys_modulescCsd}t�|�}|�|�dSr�)r%�find_loaderr�r�rrr�test_find_loader_missing_moduleTs
z7ImportlibMigrationTests.test_find_loader_missing_modulecCslt��R}|�t�d��|�t�d��|�t�d��|�t|j�d�Wd�n1s^0YdSr�)rr�r%r�r'rur�r�rrr�!test_find_loader_avoids_emulationYs
z9ImportlibMigrationTests.test_find_loader_avoids_emulationcCsLt��2}|�t�d��|�t|j�d�Wd�n1s>0YdS)Nz*??r)rr�r%r�r'rur�r�rrr�"test_get_importer_avoids_emulation`sz:ImportlibMigrationTests.test_get_importer_avoids_emulationcCs4zt�td��Wnty.|�d�Yn0dS)Nz/homez3Unexpected AttributeError when calling get_importer)r%r�rrnrHrrrr�test_issue44061fsz'ImportlibMigrationTests.test_issue44061cCsJt��0}t��D]}q|�t|j�d�Wd�n1s<0YdSr)rr%r�r'rur�)rr0Zimporterrrr�$test_iter_importers_avoids_emulationlsz<ImportlibMigrationTests.test_iter_importers_avoids_emulationN)rzr{r|r�r�r�r��unittestZskipIfr�r�r�r�r�r�r�r�r�rrrrr�s
			r�cCs&ddl}ddl}|j��|��dSr)�	zipimportrr�_zip_directory_cache�clearrs)r�rrrrr�tearDownModulers
r�r�)�pathlibrZtest.supportrrrr�rrr�importlib.utilrr%rZos.pathr	r
r4ZTestCaserr}r�r�r�r�rz�mainrrrr�<module>s*/-})^

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists