Your IP : 216.73.216.60


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_zipimport.cpython-35.opt-1.pyc



��Yf�k�@s ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZddlZddlZddlZddlZddlZddlmZmZmZdZeedd�ZdZd	d
�Zdd�Zej�Zeeeee��Z d
Z!dZ"dZ#ej$j%d�Z&ej$j%d�Z'ej(j)e!d�Z*dZ+Gdd�dej,�Z-Gdd�de-�Z.e	j/Gdd�de.��Z0Gdd�dej,�Z1dd�Z2e3dkre2�dS)�N)�support)�ZipFile�ZipInfo�
ZIP_STORED�ZIP_DEFLATED)�
extract_tb�
extract_stack�print_tbzHdef get_name():
    return __name__
def get_file():
    return __file__
z<???>�execz def do_raise(): raise TypeError
cCs�tj|�}t|�td�krX|dkrBt|�}ntdt|��}tjjtjdt|�|d@�|}|S)Ngi���lz<iil��l����)	�marshal�dumps�type�int�	importlib�util�MAGIC_NUMBER�struct�pack)�co�mtime�size�data�pyc�r�8/opt/alt/python35/lib64/python3.5/test/test_zipimport.py�make_pycs-rcCs|jtjd�S)N�.)�replace�os�sep)�pathrrr�module_path_to_dotted_name*sr!Z
ziptestmoduleZziptestpackageZziptestpackage2Z	junk95142z
junk95142.zipz.pyz.pycc@s(eZdZdd�Zdd�ZdS)�ImportHooksBaseTestCasecCsbtjdd�|_tjdd�|_tjdd�|_tjj�tj�|_dS)N)	�sysr �	meta_path�
path_hooks�path_importer_cache�clearrZ
modules_setup�modules_before)�selfrrr�setUp=s

zImportHooksBaseTestCase.setUpcCsc|jtjdd�<|jtjdd�<|jtjdd�<tjj�tj|j�dS)N)	r r#r$r%r&r'rZmodules_cleanupr()r)rrr�tearDownDs

z ImportHooksBaseTestCase.tearDownN)�__name__�
__module__�__qualname__r*r+rrrrr";sr"c@s�eZdZeZdd�Zedd�Zedd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$d=d>�Z%d?d@�Z&dAdB�Z'e(j)e*j+dCkdD�dEdF��Z,dGdH�Z-dCS)I�UncompressedZipImportTestCasecCs(tj�tjj�tj|�dS)N)�	linecache�
clearcache�	zipimport�_zip_directory_cacher'r"r*)r)rrrr*Ps

z#UncompressedZipImportTestCase.setUpc	
Cs�|jtj|�x�|j�D]�\}\}}tjj||�}|dtjkr|tjj|�s�tj	|�q tjj
|�}tjj|�s�tj	|�t|d��}|j|�WdQRXq WdS)N��wb���)
�
addCleanuprZrmtree�itemsrr �joinr�isdir�makedirs�dirname�open�write)	r)�filesZdirName�namerrr Zdname�fprrr�makeTreeWs
z&UncompressedZipImportTestCase.makeTreecKs�|jtj|�t|d��^}xT|j�D]F\}\}}t|tj|��}|j|_	|j
||�q2WWdQRX|jdd�}	|	dk	r�t|d��}
|
j
�}WdQRXt|d��!}
|
j|	�|
j|�WdQRXdS)N�w�stuff�rbr5)r7r�unlinkrr8r�time�	localtime�compression�
compress_type�writestr�getr=�readr>)r)r?ZzipName�kw�zr@rr�zinforD�frrr�makeZiphs
z%UncompressedZipImportTestCase.makeZipcOs�|j||�tjjdt�tjdj|��}|jd�}|dk	r`||�|r�|j	�}|j
|tjjt|�|�dS)Nrr�call)rRr#r �insert�TEMP_ZIPr�
import_moduler9rLZget_file�assertEqualr)r)Zexpected_extr?�modulesrN�modrS�filerrr�doTest}s
z$UncompressedZipImportTestCase.doTestcCs�dtjkr|jd�dtjkr5tjd=dttfi}y|jd|d�Wn.tk
r�|jt	kr�|j
d�YnX|jtkr�|j
d�dS)N�zlibzzlib is a builtin modulezzlib.pyz.pyz&expected test to not raise ImportErrorz"expected test to raise ImportError)r#�builtin_module_namesZskipTestrX�NOW�test_srcr[�ImportErrorrIr�failr)r)r?rrr�
testAFakeZlib�s


z+UncompressedZipImportTestCase.testAFakeZlibcCs-tdttfi}|jd|t�dS)Nz.py)�TESTMODr^r_r[)r)r?rrr�testPy�sz$UncompressedZipImportTestCase.testPycCs-ttttfi}|jt|t�dS)N)rc�pyc_extr^�test_pycr[)r)r?rrr�testPyc�sz%UncompressedZipImportTestCase.testPyccCs=tdttfttttfi}|jt|t�dS)Nz.py)rcr^r_rerfr[)r)r?rrr�testBoth�sz&UncompressedZipImportTestCase.testBothcCs-tdtdfi}|jd|t�dS)Nz.py�)rcr^r[)r)r?rrr�testEmptyPy�sz)UncompressedZipImportTestCase.testEmptyPycCsWtt�}|ddN<tdttfttt|fi}|jd|t�dS)Nr�z.py)�	bytearrayrfrcr^r_rer[)r)�badmagic_pycr?rrr�testBadMagic�s
z*UncompressedZipImportTestCase.testBadMagiccCsmtt�}|ddN<ttt|fi}y|jd|t�Wntk
r[YnX|jd�dS)Nrrkz.pyz)expected ImportError; import from bad pyc)rlrfrcrer^r[r`ra)r)rmr?rrr�
testBadMagic2�s
z+UncompressedZipImportTestCase.testBadMagic2cCsWtt�}|ddN<tdttfttt|fi}|jd|t�dS)N��z.py)rlrfrcr^r_rer[)r)Zbadtime_pycr?rrr�testBadMTime�s
z*UncompressedZipImportTestCase.testBadMTimecCsUttj}|dtttf|ttttfi}|jt|tt�dS)N�__init__)�TESTPACKrrrer^rfrcr[)r)�packdirr?rrr�testPackage�s
z)UncompressedZipImportTestCase.testPackagecCs}ttj}|ttj}|dtttf|dtttf|ttttfi}|jt|ttt�dS)Nrs)	rtrr�	TESTPACK2rer^rfrcr[)r)ru�packdir2r?rrr�testSubPackage�s
z,UncompressedZipImportTestCase.testSubPackagecCsmttj}|ttj}|tdf|tdf|ttttfi}|jt|ttt�dS)Nri)	rtrrrwr^rcrerfr[)r)rurxr?rrr�testSubNamespacePackage�s
z5UncompressedZipImportTestCase.testSubNamespacePackagec
Cs�ttj}|ttj}|tdtj}|tdf|ttttf|tdf|tdf|ttttf|tdtttf|ttttfi}|tdf|tdtttf|tdf|tdtttf|ttttfi}tjj	d�}|j
||�t}|j||�t
jjd|�t
jjd|�tjt�}|jdt|j��|j\}	}
|jtjjt�|	jtj�d�|jd|
jtj�d�tj|jtjd�dd
��}|jdt|j��t|j�djdtj�d}|j|dd�|�tjdjttf��}|jd|jjtj�d�tjdjttdf��}|jtjjt�|jjtj�d�djttf�}tj|�}|jdt|j��|j\}	}
|jtjjt�|	jtj�d�|jd|
jtj�d�tjdj|tf��}|jtjjt�|jjtj�d�tjdj|tdf��}|jtjjt�|jjtj�d�tjdj|tdf��}|jd|jjtj�d�dS)N�3ri�2z	path1.ziprrqrr4�rk���r~r6r6���rrr���r�r�)rtrrrwr^rcrerfr �abspathrR�TEMP_DIRrBr#rTrrVrW�len�__path__�basename�splitr�listr9�__file__)
r)rurx�packdir3�files1�files2�zip1�zip2rY�p1�p2�mpath�subpkgrrr�testMixedNamespacePackage�sb
, ('#", ""z7UncompressedZipImportTestCase.testMixedNamespacePackagec
CsWttj}|ttj}|tdtj}|tdf|ttttf|tdf|tdf|ttttf|tdtttf|ttttfi}tjj	d�}|j
||�|tdf|tdtttf|tdf|tdtttf|ttttfi}tjj	d�}|j
||�tjjd|�tjjd|�t
jt�}|jdt|j��|j\}	}
|jd|	jtj�d�|jd|
jtj�d
�t
j|jtjd�dd��}|jd	t|j��t|j�djdtj�d	}|j|dd�|�t
jdjttf��}|jd|jjtj�d�t
jdjttdf��}|jd|jjtj�d�djttf�}t
j|�}|jdt|j��|j\}	}
|jd|	jtj�d�|jd|
jtj�d�t
jdj|tf��}|jd|jjtj�d�t
jdj|tdf��}|jd|jjtj�d�t
jdj|tdf��}|jd|jjtj�d�dS)Nr{riz	path1.zipr|z	path2.ziprrqrr4r}rkr~r~r6r6rrrrr�r�r�)rtrrrwr^rcrerfr r�rRr#rTrrVrWr�r�r�rr�r9r�)
r)rurxr�r�r�r�r�rYr�r�r�r�rrr�testNamespacePackageCs\
  ('#"#  #"#"z2UncompressedZipImportTestCase.testNamespacePackagecCsttj}|ttj}|dtttf|dtttf|ttttfi}tt	d�}ztx]|j
�D]O\}\}}t|tj
|��}|j|_d|_|j||�qW|j�tjt	�}	|j|	jt	�|j|	jt�d�|	jt�}
|j|	jt�|
j�tjt�jd}tjjt	t�}|j||�|j|	j|d�d�|j|	j|t�d�|j|	j|t�d�|t}
t |
�}tj|�}
|j!|t"j#k�|j|	j$t�d�|j|	j$|
�d�|j|	j|
�|
j�|
j%}|j|j$|�d�|j|j|�|
j�tjt	tjt�}|j|jt	�|j|j&ttj�Wd|j�tj't	�XdS)NrsrCsspamTrF)(rtrrrwrer^rfrcrrUr8rrGrHrIrJ�commentrK�closer2�zipimporterrW�archive�
is_package�load_module�get_filenamer�rrVr�r r9r!�
assertTruer#rX�
get_source�
__loader__�prefix�remove)r)rurxr?rOr@rrrP�zirYZexisting_pack_pathZexpected_path_path�mod_path�mod_name�loaderZzi2rrr�testZipImporterMethods�sN
	

	
z4UncompressedZipImportTestCase.testZipImporterMethodscCs�ttj}|ttj}|dtttf|ttttfi}tt	d�}zx]|j
�D]O\}\}}t|tj
|��}|j|_d|_|j||�qkW|j�tjt	tj|�}	|j|	jt	�|j|	j|�|j|	jt�d�|	jt�}
|j|	jt�|
j�|j|	jttjd�d�|j|	jttjt�d�ttjt}t|�}tj|�}
|j|t j!k�|j|	j"t�d�|j|	j"|�d�|j|	j|�|
j�|
j#}
|j|
j"|�d�|j|
j|�|
j�Wd|j�tj$t	�XdS)NrsrCseggsTF)%rtrrrwrer^rfrcrrUr8rrGrHrIrJr�rKr�r2r�rWr�r�r�r�r�r�r!rrVr�r#rXr�r�r�)r)rurxr?rOr@rrrPr�rYr�r�r�rrr�$testZipImporterMethodsInSubDirectory�sD
	
	 
zBUncompressedZipImportTestCase.testZipImporterMethodsInSubDirectorycCs�ttd�}|j|_z�d}tdd�td�D��}|j||�|j�tjt�}|j	||j
|��|jdt|��Wd|j�t
jt�XdS)NrCztestdata.datcss|]}|VqdS)Nr)�.0�xrrr�	<genexpr>�sz<UncompressedZipImportTestCase.testGetData.<locals>.<genexpr>�zzipimporter object)rrUrI�bytes�rangerKr�r2r�rW�get_dataZassertIn�reprrr�)r)rOr@rr�rrr�testGetData�s

z)UncompressedZipImportTestCase.testGetDatacCscd}tt|dd�tt|��}ttt|fdtdfi}|jt|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")
z<???>r
z	some.dataz	some data)r�compiler^r�rcrer[)r)�srcrr?rrr�testImporterAttr�s
$z.UncompressedZipImportTestCase.testImporterAttrcCs~d}tdt|fi}|j|�tjjdt�tjt�}|j	|j
d�d�|jt|j
d�dS)Nz[if 1:  # indent hack
        def test(val):
            assert(val)
            return val
z.pyrr4F)
rcr^rRr#r rTrUrrVrW�test�assertRaises�AssertionError)r)r�r?rYrrr�testDefaultOptimizationLevels
z:UncompressedZipImportTestCase.testDefaultOptimizationLevelcCs7tdttfi}|jd|tddd�dS)Nz.pyrDs
Some Stuff�)rcr^r_r[)r)r?rrr�testImport_WithStuffsz2UncompressedZipImportTestCase.testImport_WithStuffcCs|jtj|�t�dS)N)rW�inspectZ	getsourcer_)r)�modulerrr�assertModuleSourcesz0UncompressedZipImportTestCase.assertModuleSourcecCs6tdttfi}|jd|td|j�dS)Nz.pyrS)rcr^r_r[r�)r)r?rrr�
testGetSourcesz+UncompressedZipImportTestCase.testGetSourcecCsjtttdd�ttt��}tdttfttt|fi}|jt|td|j�dS)Nz<???>r
z.pyrS)	rr�r_r^r�rcrer[r�)r)rr?rrr�testGetCompiledSources$z3UncompressedZipImportTestCase.testGetCompiledSourcecCs?tdttfdtdfi}|jd|td|�dS)Nz.pyzxyz.txtz>>> log.append(True)
rS)rcr^r_r[)r)�callbackr?rrr�
runDoctest%sz(UncompressedZipImportTestCase.runDoctestcCscg}tjd}t_z&tjdd|dddt��Wd|t_X|j|dg�dS)Nzxyz.txt�package�module_relativeT�globs)�doctestZmasterZtestfile�localsrW)r)r��logZ
old_masterrrr�
doDoctestFile*s
z+UncompressedZipImportTestCase.doDoctestFilecCs|j|j�dS)N)r�r�)r)rrr�testDoctestFile6sz-UncompressedZipImportTestCase.testDoctestFilecCsEg}tjdd|dddt��j�|j|dg�dS)Nzxyz.txtr�r�Tr�)r�ZDocFileTestr�ZrunrW)r)r�r�rrr�doDoctestSuite9s
z,UncompressedZipImportTestCase.doDoctestSuitecCs|j|j�dS)N)r�r�)r)rrr�testDoctestSuiteAsz.UncompressedZipImportTestCase.testDoctestSuitec
Cs�y|j�Wn�tj�dj}t|d�d\}}}}|j|tj��t|j	d�d\}}}}|j|tj��t
j�}t|d|�|j
|j�jt��Yn
Xtd��dS)Nrqr4rzThis ought to be impossible)Zdo_raiser#�exc_info�tb_nextrrW�	raise_src�stripr�tb_frame�io�StringIOr	r��getvalue�endswithr�)r)r��tbrQZlno�n�line�srrr�doTracebackDs"!z)UncompressedZipImportTestCase.doTracebackcCs6tdttfi}|jd|td|j�dS)Nz.pyrS)rcr^r�r[r�)r)r?rrr�
testTracebackVsz+UncompressedZipImportTestCase.testTracebackNzneed an unencodable filenamecCs�tjd}t|d�}ttdtjt��}|j|_	|j
|t�|j�zt
j|�jt�Wdtj|�XdS)Nz.ziprCz.py)r�TESTFN_UNENCODABLErrrcrGrHr^rIrJrKr_r�r2r�r�rr�)r)�filenamerOrPrrr�testUnencodableZs

z-UncompressedZipImportTestCase.testUnencodablecCs�tjd}|jtj|�t|d��?}ttdtjt	��}|j
|_|j|t
�WdQRXtj|�tjtj|��tjttj|���tjttj|���dS)Nz.ziprCz.py)rZTESTFNr7rFrrrcrGrHr^rIrJrKr_r2r�r�fsencoderl�
memoryview)r)r�rOrPrrr�
testBytesPathhs

z+UncompressedZipImportTestCase.testBytesPath).r,r-r.rrIr*r�rBrUrRr[rbrdrgrhrjrnrorrrvryrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��unittestZskipIfrr�r�r�rrrrr/LsJ 	
MI3+

r/c@seZdZeZdS)�CompressedZipImportTestCaseN)r,r-r.rrIrrrrr�vsr�c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�BadFileZipImportTestCasecCs|jtjtj|�dS)N)r�r2�ZipImportErrorr�)r)r�rrr�assertZipFailure|sz)BadFileZipImportTestCase.assertZipFailurecCs|jd�dS)NZAdfjdkFJKDFJjdklfjs)r�)r)rrr�
testNoFile�sz#BadFileZipImportTestCase.testNoFilecCs|jd�dS)Nri)r�)r)rrr�testEmptyFilename�sz*BadFileZipImportTestCase.testEmptyFilenamecCs[|jttjd�|jttjtdd�|jttjttjt���dS)NZkwd)r��	TypeErrorr2r�rcr�rr�)r)rrr�testBadArgs�sz$BadFileZipImportTestCase.testBadArgscCs|jdd�dS)N�Ai�)r�)r)rrr�testFilenameTooLong�sz,BadFileZipImportTestCase.testFilenameTooLongcCs+tjt�tjt�|jt�dS)N)rrFrcZcreate_empty_filer�)r)rrr�
testEmptyFile�s

z&BadFileZipImportTestCase.testEmptyFilecCs�tjt�tjttjd�}z:tj|�|jtj	��}tj
t�WdQRXWdtjtd�tjt�XdS)Nri�)rrFrcrr=�O_CREATr�r�r2r�r��chmod)r)�fd�cmrrr�testFileUnreadable�s

z+BadFileZipImportTestCase.testFileUnreadablecCsHtjt�ttd�}|jdd�|j�|jt�dS)Nzw+�a�)rrFrcr=r>r�r�)r)rArrr�testNotZipFile�s


z'BadFileZipImportTestCase.testNotZipFilec
Cs�tjt�ttd�}|jtjdd��|jd�|j�tj	t�}z|j
t|jd�|j
t|j
d�|j
t|jd�|j
t|jd�|j
t|jd�|j
t|jd�tj}|j|jd�d�|j
||j
d�|j
||jd�|j
t|jd�|j
||jd�|j
||jd�Wdtjj�XdS)Nzw+z=IiPKr���abcZaaaaaaaaaaaaaaaaaa)rrFrcr=r>rrr�r2r�r�r��find_moduler�r��get_coder�r�r�rW�OSErrorr3r')r)rArO�errorrrr�_testBogusZipFile�s*


	z*BadFileZipImportTestCase._testBogusZipFileN)r,r-r.r�r�r�r�r�r�r�r�r�rrrrr�{sr�cCs,ztjttt�Wdtjt�XdS)N)rZrun_unittestr/r�r�rFrcrrrr�	test_main�sr��__main__)4r#rrr�importlib.utilrrGr�r�rZzipfilerrrrr2r0r�r�r��	tracebackrrr	r_r�Ztest_cor�rr!r^r�rfrcrtrwr r�r�rUr�cache_from_sourceZpyc_filereZTestCaser"r/Z
requires_zlibr�r�r�r,rrrr�<module>sN"��,K