Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_zipimport.cpython-39.pyc

a

XC?h1u�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZddlZddlZddlZddlZddlZddlmZmZmZzddlZWney�dZYn0dZeedd�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
�2�Gdd�de1��Z3Gdd�dej/�Z4dd�Z5e6dk�r�e�7�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
cCs6t�|�}tjjt�ddt|�d@|d@�|}|S)Nz<iLLr���)�marshal�dumps�	importlib�util�MAGIC_NUMBER�struct�pack�int)�co�mtime�size�data�pyc�r�8/opt/alt/python39/lib64/python3.9/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�setUp=s

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

z ImportHooksBaseTestCase.tearDownN)�__name__�
__module__�__qualname__r/r0rrrrr%;sr%c@s�eZdZeZdd�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,dIdJ�Z-e�.e/j0dKudL�dMdN��Z1dOdP�Z2dQdR�Z3dSdT�Z4dUdV�Z5dKS)W�UncompressedZipImportTestCasecCs t��tj��t�|�dSr&)�	linecache�
clearcache�	zipimport�_zip_directory_cacher+r%r/r-rrrr/Ps
z#UncompressedZipImportTestCase.setUpc		Cs�|�tj|�|��D]�\}\}}tj�||�}|dtjkrVtj�|�s�t�	|�qtj�
|�}tj�|�sxt�	|�t|d��}|�|�Wd�q1s�0YqdS)N����wb)
�
addCleanuprZrmtree�itemsrr!�joinr �isdir�makedirs�dirname�open�write)	r.�filesZdirName�namerrr!Zdname�fprrr�makeTreeWs
z&UncompressedZipImportTestCase.makeTreecKs|�tj|�t|d��d}|��D]0\}\}}t|t�|��}|j|_	|�
||�q"|�dd�}	|	durn|	|_Wd�n1s�0Y|�dd�}
|
du�rt
|d��}|��}Wd�n1s�0Yt
|d��$}|�|
�|�|�Wd�n1�s
0YdS)N�w�comment�stuff�rbr:)r;r�unlinkrr<r�time�	localtime�compression�
compress_type�writestr�getrHrA�readrB)r.rCZzipName�kw�zrDrr�zinforHrI�frrr�makeZiphs $
&
z%UncompressedZipImportTestCase.makeZipcOsz|j|fi|��tj�dt�t�d�|��}|�d�}|durJ||�|rv|�	�}|�
|tjjtg|�R�|�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�dtjvr|�d�dtjvr&tjd=dttfi}z|�d|d�Wn&tyj|jt	krf|�
d�Yn0|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�WntyLYn0|�d�dS)Nrr�r#z)expected ImportError; import from bad pyc)r�rnrkrmrcr`rerfr�rrr�
testBadMagic2�sz+UncompressedZipImportTestCase.testBadMagic2cCsFtt�}|ddN<tdttfttt|fi}|�d|t�dS)N��r#r�)r.Zbadtime_pycrCrrr�testBadMTime�s�z*UncompressedZipImportTestCase.testBadMTimecCs>ttdtt��}tdttfttt|fi}|�d|t�dS)Nrr#)r�test_co�lenrdrkrcrmr`)r.Ztwenty_thirty_eight_pycrCrrr�
test2038MTime�s
�z+UncompressedZipImportTestCase.test2038MTimecCsBttj}|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�testSubPackage	s
�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\r��__path__�basename�splitr�listr=�__file__)
r.r�r��packdir3�files1�files2�zip1�zip2r^�p1�p2�mpath�subpkgrrr�testMixedNamespacePackagesl
��

 �

 ��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�testNamespacePackageks`
��



z2UncompressedZipImportTestCase.testNamespacePackagec	Cs�ttj}|ttj}|dtttf|dtttf|ttttfdtttfi}|�t	j
t�ttd��P}|�
�D]6\}\}}t|t�|��}|j|_d|_|�||�qzWd�n1s�0Yt�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)v�|�|	�*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�sX
�,





z4UncompressedZipImportTestCase.testZipImporterMethodscCsPttj}|ttj}|dtttf|ttttfi}|�t	j
t�ttd��P}|�
�D]6\}\}}t|t�|��}|j|_d|_|�||�q^Wd�n1s�0Yt�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'v�|�|	�(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�sX
�,
��



�
zBUncompressedZipImportTestCase.testZipImporterMethodsInSubDirectorycCs�|�tjt�ttd��>}|j|_d}tdd�td�D��}|�||�Wd�n1s\0Yt	�
t�}|�||�|��|�
dt|��dS)NrGztestdata.datcss|]
}|VqdSr&r)�.0�xrrr�	<genexpr>"�z<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�testDefaultOptimizationLevel4s

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_WithStuffAs
�z2UncompressedZipImportTestCase.testImport_WithStuffcCs|�t�|�t�dSr&)r\�inspectZ	getsourcerd)r.�modulerrr�assertModuleSourceHsz0UncompressedZipImportTestCase.assertModuleSourcecCs(tdttfi}|jd|t|jd�dS�Nr#rz)rkrcrdr`r�rgrrr�
testGetSourceKsz+UncompressedZipImportTestCase.testGetSourcecCsLtttdd�ttt��}tdttfttt|fi}|jt|t|jd�dS)Nr
rr#rz)	rrrdrcr�rkrmr`r�)r.rrCrrr�testGetCompiledSourceOs
�z3UncompressedZipImportTestCase.testGetCompiledSourcecCs.tdttfdtdfi}|jd|t|d�dS)Nr#�xyz.txtz>>> log.append(True)
rzrj)r.�callbackrCrrr�
runDoctestUs�z(UncompressedZipImportTestCase.runDoctestcCsLg}tjd}t_ztjd|dt�d�W|t_n|t_0|�|dg�dS�Nr�T)�packageZmodule_relativeZglobs)�doctestZmasterZtestfile�localsr\)r.r��logZ
old_masterrrr�
doDoctestFileZs�z+UncompressedZipImportTestCase.doDoctestFilecCs|�|j�dSr&)r�r�r-rrr�testDoctestFilefsz-UncompressedZipImportTestCase.testDoctestFilecCs.g}tjd|dt�d���|�|dg�dSr�)r�ZDocFileTestr��runr\)r.r�r�rrr�doDoctestSuiteis�
z,UncompressedZipImportTestCase.doDoctestSuitecCs|�|j�dSr&)r�r�r-rrr�testDoctestSuiteqsz.UncompressedZipImportTestCase.testDoctestSuitec	
Cs�z|��Wn�ty�}z�|jj}t|d�d\}}}}|�|t���t|j	d�d\}}}}|�|t���t
��}t|d|�|�
|���t��WYd}~nd}~00td��dS)Nr�rzThis ought to be impossible)Zdo_raise�	Exception�
__traceback__�tb_nextrr\�	raise_src�stripr�tb_frame�io�StringIOr	r��getvalue�endswithr�)	r.r��e�tbrV�lno�n�line�srrr�doTracebackts*z)UncompressedZipImportTestCase.doTracebackcCs(tdttfi}|jd|t|jd�dSr�)rkrcr�r`rrgrrr�
testTraceback�sz+UncompressedZipImportTestCase.testTracebackNzneed an unencodable filenamecCs~tjd}|�tj|�t|d��8}ttdt�t	��}|j
|_|�|t
�Wd�n1s`0Yt�|��t�dS�Nz.ziprGr#)r�TESTFN_UNENCODABLEr;rKrrrkrLrMrcrNrOrPrdr7r�r��r.�filenamerTrUrrr�testUnencodable�s
*z-UncompressedZipImportTestCase.testUnencodablecCstjd}|�tj|�t|d��8}ttdt�t	��}|j
|_|�|t
�Wd�n1s`0Yt�|�t�t�|��|�t��$t�tt�|���Wd�n1s�0Y|�t��$t�tt�|���Wd�n1s�0YdSr)rZTESTFNr;rKrrrkrLrMrcrNrOrPrdr7r�r�fsencoder��	TypeErrorr��
memoryviewrrrr�
testBytesPath�s
*
2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��r
rjrgrrr�testLargestPossibleComment�sz8UncompressedZipImportTestCase.testLargestPossibleComment)6r1r2r3rrNr/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�rrZskipIfrrrrrrrrrrrr4Ls\ 
	
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�r
r7r�rkr�rr	r-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
Cs�t�t�t�ttjd�}zZt�|�|�tj	��}t�
t�Wd�n1sR0YWt�td�t�t�nt�td�t�t�0dS)Nri�)rrKrkrrA�O_CREAT�closer�r7rr��chmod)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|jd�|�
t|j
d�|�
t|jd�|�
t|jd�|�
t|jd�|�
t|jd�tj}|�|�d�d�|�
||j
d�|�
||jd�|�
t|jd�|�
||jd�|�
||jd�Wtj��ntj��0dS)Nr$z=IiPKZaaaaaaaaaaaaaaaaaa�abc)rrKrkrArBrrrr7r�r�r
r�r�r��get_coder�r�rr\�OSErrorr8r+)r.rErT�errorrrr�_testBogusZipFile�s*



z*BadFileZipImportTestCase._testBogusZipFileN)r1r2r3rrrrrrr#r%r*rrrrr�srcCst�t�dSr&)rrKrkrrrr�tearDownModulesr+�__main__)8r'rr
r�importlib.utilrrLrZ
unittest.mockr�rZzipfilerrrrr7r5r�r�r��	tracebackrrr	rarerdrr�r�rr"rcr�rnrkr�r�r!r�r�rZr�cache_from_sourceZpyc_filermZTestCaser%r4Z
requires_zlibrrr+r1�mainrrrr�<module>s\
iK