Your IP : 216.73.216.60


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_zipimport.cpython-38.opt-2.pyc

U

i�fu�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZddlZddlZddlZddlZddlZddlmZmZmZzddlZWnek
r�dZYnXdZeedd�ZdZd	d
�Zdd�Z e��Z!eee!e"e��Z#d
Z$dZ%dZ&ej'�(d�Z)ej'�(d�Z*ej+�,e$d�Z-dZ.Gdd�dej/�Z0Gdd�de0�Z1e
j2Gdd�de1��Z3Gdd�dej/�Z4dd�Z5e6dk�r�e5�dS)�N)�support)�ZipFile�ZipInfo�
ZIP_STORED�ZIP_DEFLATED)�
extract_tb�
extract_stack�print_tbzHdef get_name():
    return __name__
def get_file():
    return __file__
�<???>�execz def do_raise(): raise TypeError
cCsdt�|�}t|�td�kr<|dkr,t|�}ntdt|��}tjjt�ddt|�|d@�|}|S)Ngi���l����z<iiirl��)	�marshal�dumps�type�int�	importlib�util�MAGIC_NUMBER�struct�pack)�co�mtime�size�data�pyc�r�8/opt/alt/python38/lib64/python3.8/test/test_zipimport.py�make_pyc#s

��rcCs|�tjd�S)N�.)�replace�os�sep)�pathrrr�module_path_to_dotted_name/sr"Z
ziptestmoduleZziptestpackageZziptestpackage2Z	junk95142z
junk95142.zip�.py�.pycc@seZdZdd�Zdd�ZdS)�ImportHooksBaseTestCasecCsHtjdd�|_tjdd�|_tjdd�|_tj��t��|_dS�N)	�sysr!�	meta_path�
path_hooks�path_importer_cache�clearrZ
modules_setup�modules_before��selfrrr�setUpBs

zImportHooksBaseTestCase.setUpcCsJ|jtjdd�<|jtjdd�<|jtjdd�<tj��tj|j�dSr&)	r!r'r(r)r*r+rZmodules_cleanupr,r-rrr�tearDownIs

z ImportHooksBaseTestCase.tearDownN)�__name__�
__module__�__qualname__r/r0rrrrr%@sr%c@sxeZdZeZdd�Zefdd�Zefdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zej�dd�dd��Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%d;d<�Z&d=d>�Z'd?d@�Z(dAdB�Z)dCdD�Z*dEdF�Z+dGdH�Z,e�-e.j/dIkdJ�dKdL��Z0dMdN�Z1dOdP�Z2dQdR�Z3dSdT�Z4dIS)U�UncompressedZipImportTestCasecCs t��tj��t�|�dSr&)�	linecache�
clearcache�	zipimport�_zip_directory_cacher+r%r/r-rrrr/Us
z#UncompressedZipImportTestCase.setUpc	
Cs�|�tj|�|��D]�\}\}}tj�||�}|dtjkrVtj�|�s�t�	|�qtj�
|�}tj�|�sxt�	|�t|d��}|�|�W5QRXqdS)N����wb)
�
addCleanuprZrmtree�itemsrr!�joinr �isdir�makedirs�dirname�open�write)	r.�filesZdirName�namerrr!Zdname�fprrr�makeTree\s
z&UncompressedZipImportTestCase.makeTreec	Ks�|�tj|�t|d��Z}|��D]0\}\}}t|t�|��}|j|_	|�
||�q"|�dd�}	|	dk	rn|	|_W5QRX|�dd�}
|
dk	r�t
|d��}|��}W5QRXt
|d��}|�|
�|�|�W5QRXdS)N�w�comment�stuff�rbr:)r;r�unlinkrr<r�time�	localtime�compression�
compress_type�writestr�getrHrA�readrB)r.rCZzipName�kw�zrDrr�zinforHrI�frrr�makeZipms 
z%UncompressedZipImportTestCase.makeZipcOst|j|f|�tj�dt�t�d�|��}|�d�}|dk	rF||�|rp|�	�}|�
|tjjtf|��|�dS)Nrr�call)rWr'r!�insert�TEMP_ZIPr�
import_moduler=rQZget_file�assertEqualr)r.Zexpected_extrC�modulesrS�modrX�filerrr�doTest�s
��z$UncompressedZipImportTestCase.doTestcCs�dtjkr|�d�dtjkr&tjd=dttfi}z|�d|d�Wn(tk
rl|jt	krh|�
d�YnX|jtkr�|�
d�dS)N�zlibzzlib is a builtin modulezzlib.pyr#z&expected test to not raise ImportErrorz"expected test to raise ImportError)r'�builtin_module_namesZskipTestr]�NOW�test_srcr`�ImportErrorrNr�failr�r.rCrrr�
testAFakeZlib�s




z+UncompressedZipImportTestCase.testAFakeZlibcCs"tdttfi}|�d|t�dS�Nr#��TESTMODrcrdr`rgrrr�testPy�sz$UncompressedZipImportTestCase.testPycCs"ttttfi}|�t|t�dSr&)rk�pyc_extrc�test_pycr`rgrrr�testPyc�sz%UncompressedZipImportTestCase.testPyccCs.tdttfttttfi}|�t|t�dSri)rkrcrdrmrnr`rgrrr�testBoth�s
�z&UncompressedZipImportTestCase.testBothcsjd}tj�|�}tj�t|dd�|d�}tdtdftdtd|fi}�fd	d
�}�jd|t|d�dS)N�
state = 'old'�???rFr#�
state = 'new'r$�cs��|jd�dS)N�old�r\�state�r^r-rr�check�szFUncompressedZipImportTestCase.testUncheckedHashBasedPyc.<locals>.check�rX�	rr�source_hash�_bootstrap_external�_code_to_hash_pyc�compilerkrcr`�r.�sourcer|�bytecoderCryrr-r�testUncheckedHashBasedPyc�s
�
�z7UncompressedZipImportTestCase.testUncheckedHashBasedPycz_imp.check_hash_based_pycs�alwayscsjd}tj�|�}tj�t|dd�|d�}tdtdftdtd|fi}�fd	d
�}�jd|t|d�dS)NrqrrrFr#rsr$rtcs��|jd�dS)N�newrvrxr-rrry�szOUncompressedZipImportTestCase.test_checked_hash_based_change_pyc.<locals>.checkrzr{r�rr-r�"test_checked_hash_based_change_pyc�s
�
�z@UncompressedZipImportTestCase.test_checked_hash_based_change_pyccCs"tdtdfi}|�d|t�dS)Nr#�)rkrcr`rgrrr�testEmptyPy�sz)UncompressedZipImportTestCase.testEmptyPycCsFtt�}|ddN<tdttfttt|fi}|�d|t�dS)Nr�r#��	bytearrayrnrkrcrdrmr`�r.Zbadmagic_pycrCrrr�testBadMagic�s�z*UncompressedZipImportTestCase.testBadMagiccCs^tt�}|ddN<ttt|fi}z|�d|t�Wntk
rNYnX|�d�dS)Nrr�r#z)expected ImportError; import from bad pyc)r�rnrkrmrcr`rerfr�rrr�
testBadMagic2�sz+UncompressedZipImportTestCase.testBadMagic2cCsFtt�}|ddN<tdttfttt|fi}|�d|t�dS)N��r#r�)r.Zbadtime_pycrCrrr�testBadMTime�s�z*UncompressedZipImportTestCase.testBadMTimecCsBttj}|dtttf|ttttfi}|�t|tt�dS�N�__init__)�TESTPACKrr rmrcrnrkr`)r.�packdirrCrrr�testPackages

�z)UncompressedZipImportTestCase.testPackagecCsbttj}|ttj}|dtttf|dtttf|ttttfi}|�t|ttt�dSr�)	r�rr �	TESTPACK2rmrcrnrkr`�r.r��packdir2rCrrr�testSubPackages


�z,UncompressedZipImportTestCase.testSubPackagecCsRttj}|ttj}|tdf|tdf|ttttfi}|�t|ttt�dS�Nr�)	r�rr r�rcrkrmrnr`r�rrr�testSubNamespacePackages

�z5UncompressedZipImportTestCase.testSubNamespacePackagec
CsRttj}|ttj}|tdtj}|tdf|ttttf|tdf|tdf|ttttf|tdtttf|ttttfi}|tdf|tdtttf|tdf|tdtttf|ttttfi}tj�	d�}|�
||�t}|�||�t
j�d|�t
j�d|�t�t�}|�dt|j��|j\}	}
|�tj�t�|	�tj�d�|�d|
�tj�d�t�|�tjd�dd	��}|�d
t|j��t|j�d�dtj�d
}|�|dd	�|�t�d�ttf��}|�d|j�tj�d�t�d�ttdf��}|�tj�t�|j�tj�d�d�ttf�}t�|�}|�dt|j��|j\}	}
|�tj�t�|	�tj�d�|�d|
�tj�d�t�d�|tf��}|�tj�t�|j�tj�d�t�d�|tdf��}|�tj�t�|j�tj�d�t�d�|tdf��}|�d|j�tj�d�dS)
N�3r��2�	path1.ziprr����rr9�������)r�rr r�rcrkrmrnr!�abspathrW�TEMP_DIRrFr'rYrr[r\�len�__path__�basename�splitr�listr=�__file__)
r.r�r��packdir3�files1�files2�zip1�zip2r^�p1�p2�mpath�subpkgrrr�testMixedNamespacePackages�



�
�

 �

 ��z7UncompressedZipImportTestCase.testMixedNamespacePackagec
Cs2ttj}|ttj}|tdtj}|tdf|ttttf|tdf|tdf|ttttf|tdtttf|ttttfi}tj�	d�}|�
||�|tdf|tdtttf|tdf|tdtttf|ttttfi}tj�	d�}|�
||�tj�d|�tj�d|�t
�t�}|�dt|j��|j\}	}
|�d|	�tj�d�|�d|
�tj�d�t
�|�tjd	�dd
��}|�dt|j��t|j�d�dtj�d}|�|dd
�|�t
�d	�ttf��}|�d|j�tj�d�t
�d	�ttdf��}|�d|j�tj�d�d	�ttf�}t
�|�}|�dt|j��|j\}	}
|�d|	�tj�d�|�d|
�tj�d�t
�d	�|tf��}|�d|j�tj�d
�t
�d	�|tdf��}|�d|j�tj�d
�t
�d	�|tdf��}|�d|j�tj�d
�dS)Nr�r�r�r�z	path2.ziprr�r�rr9r�r�r�)r�rr r�rcrkrmrnr!r�rWr'rYrr[r\r�r�r�rr�r=r�)
r.r�r�r�r�r�r�r�r^r�r�r�r�rrr�testNamespacePackagehst



�
�



z2UncompressedZipImportTestCase.testNamespacePackagec	Cs�ttj}|ttj}|dtttf|dtttf|ttttfdtttfi}|�t	j
t�ttd��F}|�
�D]6\}\}}t|t�|��}|j|_d|_|�||�qzW5QRXt�t�}	|�|	jt�|�|	�t�d�|	�d�}
|�|
�|�|
tj�|�|
�d��|
�d�}|�|
�d�|j �|	�t�}|�|	�t�|j �t!�"t�j#d}
tj$�%tt�}|�|
|�|�|	�|d�d�|�|	�|t�d�|�|	�|t�d�|t}t&|�}t!�"|�}|�'|t(j)k�|�|	�*t�d�|�|	�*|�d�|�|	�|�|j �|j+}|�|�*|�d�|�|�|�|j �t�ttjt�}|�|jt�|�|j,ttj�dS)Nr�ZspamrGsspamTrF)-r�rr r�rmrcrnrkr;rrKrZrr<rrLrMrNrOrHrPr7�zipimporterr\�archive�
is_package�find_module�assertIsNotNone�assertIsInstance�assertFalse�load_module�get_filenamer�rr[r�r!r=r"�
assertTruer'r]�
get_source�
__loader__�prefix)r.r�r�rCrTrDrrrU�ziZfind_mod�load_modr^Zexisting_pack_pathZexpected_path_path�mod_path�mod_name�loader�zi2rrr�testZipImporterMethods�s^


�





z4UncompressedZipImportTestCase.testZipImporterMethodsc	Cs<ttj}|ttj}|dtttf|ttttfi}|�t	j
t�ttd��F}|�
�D]6\}\}}t|t�|��}|j|_d|_|�||�q^W5QRXt�ttj|�}	|�|	jt�|�|	j|�|�|	�t�d�|	�t�}
|�|	�t�|
j�|�|	�ttjd�d�|�|	�ttjt�d�ttj|t}t�|�}|�t�}
|�|
�|� |
tj�|�!|�t��|
�t�}|�|
�t�|j�ttjt}t"|�}t#�$|�}
|�%|t&j'k�|�|	�(t�d�|�|	�(|�d�|�|	�|�|
j�|
j)}|�|�(|�d�|�|�|�|
j�dS)Nr�rGseggsTF)*r�rr r�rmrcrnrkr;rrKrZrr<rrLrMrNrOrHrPr7r�r\r�r�r�r�r�r�r�r�r�r�r"rr[r�r'r]r�r�)r.r�r�rCrTrDrrrUr�r^Zpkg_pathr�Zfind_mod_dottedr�r�r�r�rrr�$testZipImporterMethodsInSubDirectory�s`

�
��



�
zBUncompressedZipImportTestCase.testZipImporterMethodsInSubDirectoryc	Cs�|�tjt�ttd��4}|j|_d}tdd�td�D��}|�||�W5QRXt	�
t�}|�||�|��|�
dt|��dS)NrGztestdata.datcss|]
}|VqdSr&r)�.0�xrrr�	<genexpr>sz<UncompressedZipImportTestCase.testGetData.<locals>.<genexpr>�zzipimporter object)r;rrKrZrrN�bytes�rangerPr7r�r\�get_dataZassertIn�repr)r.rTrDrr�rrr�testGetDatas
z)UncompressedZipImportTestCase.testGetDatacCsFd}tt|dd�tt|��}ttt|fdtdfi}|�t|t�dS)Nz�if 1:  # indent hack
        def get_file():
            return __file__
        if __loader__.get_data("some.data") != b"some data":
            raise AssertionError("bad data")
r
rz	some.dataz	some data)rrrcr�rkrmr`)r.�srcrrCrrr�testImporterAttr&s�z.UncompressedZipImportTestCase.testImporterAttrcCs\d}tdt|fi}|�|�tj�dt�t�t�}|�	|�
d�d�|�t|j
d�dS)Nz[if 1:  # indent hack
        def test(val):
            assert(val)
            return val
r#rr�F)
rkrcrWr'r!rYrZrr[r\�test�assertRaises�AssertionError)r.r�rCr^rrr�testDefaultOptimizationLevel1s

z:UncompressedZipImportTestCase.testDefaultOptimizationLevelcCs&tdttfi}|jd|tdd�dS)Nr#s6Some StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome StuffSome Stuff)rIrjrgrrr�testImport_WithStuff>s
�z2UncompressedZipImportTestCase.testImport_WithStuffcCs|�t�|�t�dSr&)r\�inspectZ	getsourcerd)r.�modulerrr�assertModuleSourceEsz0UncompressedZipImportTestCase.assertModuleSourcecCs(tdttfi}|jd|t|jd�dS�Nr#rz)rkrcrdr`r�rgrrr�
testGetSourceHsz+UncompressedZipImportTestCase.testGetSourcecCsLtttdd�ttt��}tdttfttt|fi}|jt|t|jd�dS)Nr
rr#rz)	rrrdrcr�rkrmr`r�)r.rrCrrr�testGetCompiledSourceLs�z3UncompressedZipImportTestCase.testGetCompiledSourcecCs.tdttfdtdfi}|jd|t|d�dS)Nr#�xyz.txtz>>> log.append(True)
rzrj)r.�callbackrCrrr�
runDoctestRs
�z(UncompressedZipImportTestCase.runDoctestcCsFg}tjd}t_ztjd|dt�d�W5|t_X|�|dg�dS�Nr�T)�packageZmodule_relativeZglobs)�doctestZmasterZtestfile�localsr\)r.r��logZ
old_masterrrr�
doDoctestFileWs�
z+UncompressedZipImportTestCase.doDoctestFilecCs|�|j�dSr&)r�r�r-rrr�testDoctestFilecsz-UncompressedZipImportTestCase.testDoctestFilecCs.g}tjd|dt�d���|�|dg�dSr�)r�ZDocFileTestr��runr\)r.r�r�rrr�doDoctestSuitefs�
z,UncompressedZipImportTestCase.doDoctestSuitecCs|�|j�dSr&)r�r�r-rrr�testDoctestSuitensz.UncompressedZipImportTestCase.testDoctestSuitecCs�z|��Wn�t��dj}t|d�d\}}}}|�|t���t|j	d�d\}}}}|�|t���t
��}t|d|�|�
|���t��Yn
Xtd��dS)Nr�r�rzThis ought to be impossible)Zdo_raiser'�exc_info�tb_nextrr\�	raise_src�stripr�tb_frame�io�StringIOr	r��getvalue�endswithr�)r.r��tbrV�lno�n�line�srrr�doTracebackqsz)UncompressedZipImportTestCase.doTracebackcCs(tdttfi}|jd|t|jd�dSr�)rkrcr�r`r�rgrrr�
testTraceback�sz+UncompressedZipImportTestCase.testTracebackNzneed an unencodable filenamec	Csjtjd}|�tj|�t|d��.}ttdt�t	��}|j
|_|�|t
�W5QRXt�|��t�dS�Nz.ziprGr#)r�TESTFN_UNENCODABLEr;rKrrrkrLrMrcrNrOrPrdr7r�r��r.�filenamerTrUrrr�testUnencodable�s
z-UncompressedZipImportTestCase.testUnencodablec	Cs�tjd}|�tj|�t|d��.}ttdt�t	��}|j
|_|�|t
�W5QRXt�|�t�t�|��|�t��t�tt�|���W5QRX|�t��t�tt�|���W5QRXdSr�)rZTESTFNr;rKrrrkrLrMrcrNrOrPrdr7r�r�fsencoder��	TypeErrorr��
memoryviewrrrr�
testBytesPath�s

z+UncompressedZipImportTestCase.testBytesPathcCs&tdttfi}|jd|tdd�dS)Nr#scomment�rHrjrgrrr�testComment�sz)UncompressedZipImportTestCase.testCommentcCs(tdttfi}|jd|tddd�dS)Nr#s@cruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftcruftshi)rIrHrjrgrrr�testBeginningCruftAndComment�sz:UncompressedZipImportTestCase.testBeginningCruftAndCommentcCs*tdttfi}|jd|tddd�dS)Nr#�ci��rrjrgrrr�testLargestPossibleComment�sz8UncompressedZipImportTestCase.testLargestPossibleComment)5r1r2r3rrNr/r�rFrZrWr`rhrlrorpr��unittestZmockZpatchr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ZskipIfrrrrr	r
rrrrrr4QsZ 
	
MI81
�
	r4c@seZdZeZdS)�CompressedZipImportTestCaseN)r1r2r3rrNrrrrr�src@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�BadFileZipImportTestCasecCs|�tjtj|�dSr&)r�r7�ZipImportErrorr�)r.rrrr�assertZipFailure�s�z)BadFileZipImportTestCase.assertZipFailurecCs|�d�dS)NZAdfjdkFJKDFJjdklfjs�rr-rrr�
testNoFile�sz#BadFileZipImportTestCase.testNoFilecCs|�d�dSr�rr-rrr�testEmptyFilename�sz*BadFileZipImportTestCase.testEmptyFilenamecCsB|�ttjd�|jttjtdd�|�ttjtt�t���dS)N)Zkwd)r�rr7r�rkr�rrr-rrr�testBadArgs�s

�z$BadFileZipImportTestCase.testBadArgscCs|�dd�dS)N�Ai�rr-rrr�testFilenameTooLong�sz,BadFileZipImportTestCase.testFilenameTooLongcCs"t�t�t�t�|�t�dSr&)rrKrkZcreate_empty_filerr-rrr�
testEmptyFile�s

z&BadFileZipImportTestCase.testEmptyFilec
Csht�t�t�ttjd�}z0t�|�|�t	j
��}t	�t�W5QRXW5t�td�t�t�XdS)Nri�)rrKrkrrA�O_CREAT�chmod�closer�r7rr�)r.�fd�cmrrr�testFileUnreadable�s

z+BadFileZipImportTestCase.testFileUnreadablecCs4t�t�ttd�}|�d�|��|�t�dS)N�w+Zaaaaaaaaaaaaaaaaaaaaaa)rrKrkrArBrr)r.rErrr�testNotZipFile�s



z'BadFileZipImportTestCase.testNotZipFilecCs t�t�ttd�}|�t�dd��|�d�|��t�	t�}z�|�t
|jd�|�t
|jd�|�t
|jd�|�t
|jd�|�t
|jd�|�t
|jd�tj}|�|�d�d�|�||jd�|�||jd�|�t|jd�|�||jd�|�||jd�W5tj
��XdS)Nrz=IiPKZaaaaaaaaaaaaaaaaaa�abc)rrKrkrArBrrrr7r�r8r+r�rr�r�r��get_coder�r�rr\�OSError)r.rErT�errorrrr�_testBogusZipFile�s*



z*BadFileZipImportTestCase._testBogusZipFileN)r1r2r3rrrrrrrr r%rrrrr�src	Cs$zt�ttt�W5t�t�XdSr&)rrKrkZrun_unittestr4rrrrrr�	test_main�s�r&�__main__)7r'rrr�importlib.utilrrLr
Z
unittest.mockr�rZzipfilerrrrr7r5r�r�r��	tracebackrrr	rarerdrZtest_cor�rr"rcr�rnrkr�r�r!r�r�rZr�cache_from_sourceZpyc_filermZTestCaser%r4Z
requires_zlibrrr&r1rrrr�<module>s\
aK