a ze@sPddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlZddlmZddlmZmZmZddlmZddlmZmZmZmZmZmZmZmZm Z m!Z!edZ"edZ#dZ$d Z%gd Z&d d Z'Gd ddZ(Gddde(e j)Z*eGddde(e j)Z+eGddde(e j)Z,e Gddde(e j)Z-GdddZ.Gddde.e j)Z/eGddde.e j)Z0eGddde.e j)Z1e Gdd d e.e j)Z2Gd!d"d"Z3Gd#d$d$e3e j)Z4eGd%d&d&e3e j)Z5eGd'd(d(e3e j)Z6e Gd)d*d*e3e j)Z7Gd+d,d,e j)Z8Gd-d.d.e j)Z9Gd/d0d0e j)Z:Gd1d2d2Z;Gd3d4d4e;e j)Ze Gd9d:d:e;e j)Z?Gd;d<dd>ZAGd?d@d@eAe j)ZBeGdAdBdBeAe j)ZCeGdCdDdDeAe j)ZDe GdEdFdFeAe j)ZEGdGdHdHZFGdIdJdJZGGdKdLdLe j)ZHeGdMdNdNe j)ZIGdOdPdPe j)ZJGdQdRdRe j)ZKGdSdTdTe j)ZLGdUdVdVe j)ZMeNZOGdWdXdXZPdYdZZQd[d\ZRGd]d^d^e j)ZSeTd_krLe UdS)`N) TemporaryFile)randintrandom randbytes) script_helper) TESTFNfindfileunlinkrmtreetemp_dirtemp_cwd requires_zlib requires_bz2 requires_lzmacaptured_stdout2dZzipfile_datafiles))Z _ziptest1Z 1q2w3e4r5t)zziptest2dir/_ziptest2Z qawsedrftg)z!ziptest2dir/ziptest3dir/_ziptest3Z azsxdcfvgb)z-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3Z 6y7u8i9o0pccs|tVt"}|V||jWdn1s40Yt"}|V||jWdn1sn0YdSN)TESTFN2r assertFalseclosedioBytesIO)testfrE/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_zipfile.py get_files$s* rc@seZdZeddZddZdBddZdCdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"d@dAZ#dS)DAbstractTestsWithSourceFilecCs&ddttD|_d|j|_dS)NcSs g|]}td|tfdqS)z'Zipfile test line %d. random float: %f ascii)bytesr.0irrr 0s z:AbstractTestsWithSourceFile.setUpClass..)rangeFIXEDTEST_SIZEline_genjoindataclsrrr setUpClass.sz&AbstractTestsWithSourceFile.setUpClasscCs:ttd}||jWdn1s,0YdSNwbopenrwriter+selffprrrsetUp5s z!AbstractTestsWithSourceFile.setUpNc Cs||d}tj|dfi|z}|td|tt|d|j|jddd&}|jD]}||q\Wdn1s0YWdn1s0YdS)N) compression compresslevelw another.namestrfilewritten-open-wmode)zipfileZipFiler3rwritestrr+r2r))r5rr8r9kwargszipfplinerrrmake_test_archive:s    z-AbstractTestsWithSourceFile.make_test_archivecCsD||||t|d|}||t|j||d|j||d|jt}|j |d| }| }|t |d| d|d| d|d| d |d|d \}} } } ||d|t| d |t| d || tt |j|} |t | d | t| | d| | d| | d| |} dd| D} |t | d | t| | d| | d| | d| | D]}||jt |jqtdddfD]2}||}||j|||jt |jq|Wdn1s60YdS)Nrr;r<)file File NamerModifiedSize%Y-%m-%d%H:%M:%Sr=cSsg|] }|jqSrfilenamer"rrrr%ir&z8AbstractTestsWithSourceFile.zip_test..)rFr@rA assertEqualreadrr+rStringIOprintdirgetvalue splitlineslenassertInsplit assertTruetimestrptimestrnamelistinfolist file_sizegetinforRtestzip)r5rr8r9rDr6 directorylinesfndatetime_sizenamesinfosr$nminforrrzip_testEsL           z$AbstractTestsWithSourceFile.zip_testcCs t|D]}|||jqdSrrror8r5rrrr test_basic{s z&AbstractTestsWithSourceFile.test_basicc Cs|||t|d|}g}|t,}|d}|sr<rr)rrr@rArBr+r8tellrWr2truncate assertRaisesEOFErrorrTr)r5r6rZ end_offset zipfiledatarrrrtest_truncated_zipfileKs2&    b     d     z2AbstractTestsWithSourceFile.test_truncated_zipfilec Csd}t|D]}t|d|j0}|t|t|}|d|Wdn1sX0Yt|d&}t|}t|t r|d||n|d|||d|t| |}|d|||d||d ||jtj kr|d ||d || |N}t|}|d |||d||jtj krX|d |Wdn1sn0Y|d t|Wdn1s0Y|d t|q dS)Nz file.namer:zmode='w'rGz filename=%rzfile=%rzmode='r'z filemode=z file_size=zcompress_type=zcompress_size=zname=%rz[closed]) rr@rAr8r3rreprrZ isinstancer_rc ZIP_STOREDr2)r5fnamerrDrGrrrr test_repris6 *        ,0z%AbstractTestsWithSourceFile.test_reprcCs$t|D]}|j||jddqdS)N rrprqrrrtest_compresslevel_basics z4AbstractTestsWithSourceFile.test_compresslevel_basiccCstjtddd\}|td|jtddd|d}|d}||jd||jdWdn1sr0YdS)Nr:rMrZ compress_1Z compress_9r)r@rArr3rrcrSr)r5rDZone_infoZ nine_inforrrtest_per_file_compresslevels   z7AbstractTestsWithSourceFile.test_per_file_compresslevelc sGfdddtj}d|}dt|d|j}|dd}|dWdn1sd0Ydztz:|dd}|dWdn1s0YWntyd 7Yn0WdWdqjWdnd0Wdn1s0Ytt|4}| | dg| | ddWdq1s^0Yqtt|H}| | ddg| | dd| | ddWdn1s0YdS) Ncs eZdZfddZZS)zCAbstractTestsWithSourceFile.test_writing_errors..BrokenFilecs,durkrtd7t|dSNrM)OSErrorsuperr3r5r+) __class__countstoprrr3s zIAbstractTestsWithSourceFile.test_writing_errors..BrokenFile.write)__name__ __module__ __qualname__r3 __classcell__rrr)rr BrokenFilesrrr:Zfile1sdata1Zfile2sdata2rM) rrr@rAr8r2r3rrWrSr`rT)r5rZtestfilerDrrrrtest_writing_errorss0 (, ,4z/AbstractTestsWithSourceFile.test_writing_errorscCsttttdSrr rrr5rrrtearDownsz$AbstractTestsWithSourceFile.tearDown)N)N)$rrr classmethodr.r7rFrorrr{r}rrrrrrrrrrrrrrrrrrrrrrrrrrrrrr-sB  6      %rc@seZdZejZdZddZddZddZ dd Z d d Z d d Z ddZ ddZddZddZddZddZddZddZdS)StoredTestsWithSourceFileNcCsl|||t|d@}|d}||jd|d}||jdWdn1s^0YdS)NrGr<r=)rFr@rArcrS external_attr)r5rr8rDzinfoZzinfo2rrrzip_test_writestr_permissionss    z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs t|D]}||tjqdSr)rrr@rrqrrrtest_writestr_permissionss z3StoredTestsWithSourceFile.test_writestr_permissionscCsttdtj}|tdWdn1s20Yttdtj"}||dgWdn1st0YdS)Nr: /absoluterGabsoluter@rArrr3rrSr`r5rDrrrtest_absolute_arcnamess*z0StoredTestsWithSourceFile.test_absolute_arcnamescCsttdtj}|ttWdn1s20Yttdtj2}|d|j|| tdgWdn1s0YdS)Nr:ar<) r@rArrr3rrBr+rSr`rrrrtest_append_to_zip_files *z1StoredTestsWithSourceFile.test_append_to_zip_filec Csd}ttd}||Wdn1s.0Yttdtj}|ttWdn1sj0Yttdp}|t|t|d6}| | tg| | t|j Wdn1s0YWdn1s0Yttd.}| | t||| }Wdn1s>0Yt |b}t|6}| | tg| | t|j Wdn1s0YWdn1s0YdS)NI am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!r0rrbrG)r2rr3r@rArrseekrYrSr`rTr+rr)r5r+rrDrbiorrrtest_append_to_non_zip_files  (* P (z5StoredTestsWithSourceFile.test_append_to_non_zip_filec CstT}t|dtj}|ttWdn1s<0Y|}Wdn1sb0Yd}tt d$}||||Wdn1s0Ytt 6}| | tg| | t|j Wdn1s0YdS)Nr:rr0)rrr@rArr3rrWr2rrSr`rTr+r5rrDrr+rrrrtest_read_concatenated_zip_files *&  ( z9StoredTestsWithSourceFile.test_read_concatenated_zip_filec CstT}t|dtj}|ttWdn1s<0Y|}Wdn1sb0Ydd}tt d$}||||Wdn1s0Ytt d0}| | tg| d|j Wdn1s0Ytt d.}| |t|||}Wdn1s>0Yt|x}t|L}| | tdg| |t|j | |d|j Wdn1s0YWdn1s0YdS)Nr:sI am not a ZipFile!i@Br0rr<r)rrr@rArr3rrWr2rrSr`rBr+rTrYrrrr$test_append_to_concatenated_zip_file s$ *&  (, (z>StoredTestsWithSourceFile.test_append_to_concatenated_zip_filecCsttdtj}|ttWdn1s20Yttd}|dWdn1sf0Yttd}||tjWdn1s0YdS)Nr:rz rG)r@rArrr3rr2rr5rDrrrrtest_ignores_newline_at_end"s * (z5StoredTestsWithSourceFile.test_ignores_newline_at_endcCsttdtj"}d|_|ttWdn1s80Yttd}|dWdn1sl0Yttd,}||tj| |jdWdn1s0YdS)Nr:this is a commentrzabcdef rG) r@rArrcommentr3rr2rrSrrrr)test_ignores_stuff_appended_past_comments*s* (zCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentsc CszttdZ}|tttd&}||t|Wdn1sN0YWdn1sl0YdS)Nr:r)r@rArr3rr2rSrTrrrrtest_write_default_name4s  z1StoredTestsWithSourceFile.test_write_default_namec Csd}tjtdd}||dWdn1s40Ytjtdd}||`}||t|j|t|j d|t|j |t|j |t|j Wdn1s0YWdn1s0YdS)N somefile.txtr:r>bogusrGr) r@rArrBr2closer ValueErrorrTrrreadableseekable)r5rrDZfidrrrtest_io_on_closed_zipextfile<s* z6StoredTestsWithSourceFile.test_io_on_closed_zipextfilec Cstjtdd}|ddWdn1s00Ytjtdd }|t|jtWdn1sn0YtjtddH}|t|jtddWdn1s0YWdn1s0YdS)Nr:r>rrrG) r@rArrBrrr3rr2rrrrtest_write_to_readonlyJs*. z0StoredTestsWithSourceFile.test_write_to_readonlycCsttdttd }|t|jtWdn1s>0Ytjtddd2}|t| t}| |j dWdn1s0YdS)N)rrr:FZstrict_timestampsirMrMrrr) osutimerr@rArrrr3rcrS date_time)r5rDrrrrtest_add_file_before_1980Ws .  z3StoredTestsWithSourceFile.test_add_file_before_1980cCs$d}zt|Wn$ty6|d|dYn0ztt||fWntyh|dYn0ttj}|dkr|d|t t d"}| t j|jtWdn1s0Yt j t ddd 2}|t|t}||jd Wdn1s0YdS) Nl& ztime.localtime(z) raises OverflowErrorz/Host fs cannot set timestamp to required value.lb fz,Linux VFS/XFS kernel bug detected: mtime_ns=r:Fr)i; ;r)r] localtime OverflowErrorskipTestrrrstat st_mtime_nsr@rArrstructerrorr3rcrSr)r5tsZmtime_nsrDrrrrtest_add_file_after_2107bs$    0  z2StoredTestsWithSourceFile.test_add_file_after_2107)rrrr@rr8rrrrrrrrrrrrrrrrrrrrs      rc@seZdZejZddZdS)DeflateTestsWithSourceFilecCsttdd}|tdtj|tdtj|d}|d}||j tj||j tjWdn1sv0YdS)Nr:ZstoremeZ deflateme) r@rArr3rr ZIP_DEFLATEDrcrSr)r5rDsinfoZdinforrrtest_per_file_compressions  z4DeflateTestsWithSourceFile.test_per_file_compressionN)rrrr@r r8r rrrrrsrc@seZdZejZdS)Bzip2TestsWithSourceFileNrrrr@ ZIP_BZIP2r8rrrrr sr c@seZdZejZdS)LzmaTestsWithSourceFileNrrrr@ZIP_LZMAr8rrrrrsrc@sHeZdZeddZddZddZddZd d Zd d Z d dZ dS)AbstractTestZip64InSmallFilescCs$ddtdtD}d||_dS)Ncss|]}td|dVqdS)zTest of zipfile line %d.r N)r!r"rrr sz;AbstractTestZip64InSmallFiles.setUpClass..r )r'r(r*r+)r-r)rrrr.sz(AbstractTestZip64InSmallFiles.setUpClasscCsVtj|_tj|_dt_dt_ttd}||jWdn1sH0YdS)Nrrr0) r@ ZIP64_LIMIT_limitZIP_FILECOUNT_LIMIT_filecount_limitr2rr3r+r4rrrr7s  z#AbstractTestZip64InSmallFiles.setUpcCsrtj|d|dd6}|td|tt|d|jWdn1sN0Yt|d|}||t|j||d|j||d|jt }| || }| }|t |d|d|d |d |d |d |d |d \}}} } ||d|t|d |t| d|| tt |j|} |t | d|t| |d| |d| |} dd| D} |t | d|t| |d| |d| | D]} || jt |jqtddfD]2}||}||j|||jt |jq|Wdn1sd0YdS)Nr:TZ allowZip64r;r<rGrPrJrrKrLrMrNrOcSsg|] }|jqSrrQr"rrrr%r&z:AbstractTestZip64InSmallFiles.zip_test..)r@rAr3rrBr+rSrTrrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrRrd)r5rr8rDr6rerfrgrhrirjrkrlr$rmrnrrrrosN  ,         z&AbstractTestZip64InSmallFiles.zip_testcCs t|D]}|||jqdSrrprqrrrrrs z(AbstractTestZip64InSmallFiles.test_basiccCstjtd|jdd}d|_d}t|D] }|d|d|dd q&|t| || ttd |j}|t| |t|D]0}| d| d }||d|dd q| dS) Nr:Trrfoo%08d%dr9rGr ) r@rArr8debugr'rBrSrYr`rrTdecode)r5rnumfilesr$zipf2contentrrrtest_too_many_filess   z1AbstractTestZip64InSmallFiles.test_too_many_filescCs$tjtd|jdd}d|_d}t|D] }|d|d|dd q&|t| || tj  |d|d Wdn1s0Y|t| || tjtd |jdd}d|_|t| || tj  |d|d Wdn1s0Y|t| || tjtd |jd d}d|_|t| |d }t||D]"}|d|d|dd qx|t| || ttd|j}|t| |t|D]2}| d|d}||d|dd q| dS)Nr:Frrrrrrrr&rTrrGr )r@rArr8rr'rBrSrYr`r LargeZipFilerrTr )r5rr!r$Z numfiles2r"r#rrrtest_too_many_files_appendsJ  . 0   z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_ttttdSr)rr@rrrr rrrrrrr)sz&AbstractTestZip64InSmallFiles.tearDownN) rrrrr.r7rorrr$r&rrrrrrs  9'rc@sTeZdZejZddZddZddZddZ d d Z dd d Z ddZ ddZ dS)StoredTestZip64InSmallFilescCsJtj|d|dd$}|tj|jtdWdn1s<0YdSNr:Frr;)r@rArr%r3rr5rr8rDrrrlarge_file_exception_test4sz5StoredTestZip64InSmallFiles.large_file_exception_testcCsLtj|d|dd&}|tj|jd|jWdn1s>0YdSr()r@rArr%rBr+r)rrrlarge_file_exception_test29s z6StoredTestZip64InSmallFiles.large_file_exception_test2cCs.t|D] }||tj||tjqdSr)rr*r@rr+rqrrrtest_large_file_exception>s z5StoredTestZip64InSmallFiles.test_large_file_exceptioncCstjtdtjdd}|tdWdn1s60Yttdtj"}||dgWdn1sx0YdS)Nr:TrrrGrrrrrrrCs *z2StoredTestZip64InSmallFiles.test_absolute_arcnamescCstjtddd}|d|jWdn1s40Ytjtddd }|d}|j}Wdn1st0Ytjtddd}|d|jWdn1s0Ytjtddd(}|d}||j|Wdn1s0YdS)Nr:Trr<rGrZstrfile2)r@rArrBr+rcextrarS)r5rDrr-rrr test_appendKs, $, z'StoredTestZip64InSmallFiles.test_appendFcCsd}d}g} g} |} |r4d} |r4| || |td| } |} |rdd} |rd| || |td| } |} |rd} |r| |td| } tjddt| ddt| g| R}tjddt| ddt| g| R}tdd dt| }tdd dt| }td d dt| }td d dt| }d }d}td t|}d| | |||||d| | ||d| ||ddd||dddd}|S)Nrlz0Y|dt|j  |jdddd}|tj }tt|Wdn1s0Y|dt|j  |jdd}|tj }tt|Wdn1s0Y|dt|j  |jdddddd}|tj }tt|Wdn1sf0Y|dt|j  |jd dddd }|tj }tt|Wdn1s0Y|dt|j  |jddd dd }|tj }tt|Wdn1s20Y|dt|j  |jd d dd }|tj }tt|Wdn1s0Y|dt|j  dS) NT)r5z file size)r5r6r7z compress size)r7)r5r6r7r8r9z header offsetF)r5r7r8r9)r5r6r7r9)r5r7r9) r=rr@ BadZipFilerArrrZr_ exceptionlower)r5Zmissing_file_size_extraeZmissing_compress_size_extraZmissing_header_offset_extrarrrtest_bad_zip64_extrasp...0000z0StoredTestZip64InSmallFiles.test_bad_zip64_extrac Csd}d}d}d}dddddddddf}tdt|dD]}t||D]}i}|D]} || qZtt|j fi|X} | d} | | j || | j || | j|| | | |WdqN1s0YqNq>dS) Nr/rr3T)r5r6)r7r8)r9r:rM)r'rY itertools combinationsupdater@rArrr=rarSrbr;r<rT) r5Zexpected_file_sizeZexpected_compress_sizeZexpected_header_offsetZexpected_contentparamsrGZcomborCczfrrrr test_generated_valid_zip64_extras&  zr&zCPyZipFileTests.test_write_filtered_python_package..Z filterfunccSstj|d S)NZbad)rrrr startswith)rrrrfilterszAPyZipFileTests.test_write_filtered_python_package..filter)rrrrgrhrdrr@rirrqrWr\ assertWarns UserWarningprint)r5rrwrtrDZ reportSIOZ reportStrr}rrr"test_write_filtered_python_packages& (0Nz1PyZipFileTests.test_write_filtered_python_packagec Csddl}tj|j}||dr(dnd}d}tr}tj|d|dB}| || }| d||| d||Wdn1s0YWdn1s0YdS) NrFrMrer:)optimizezemail/__init__zemail/mime/text) rvrrrgrhrdrr@rirqr`rZ)r5rvrwZoptlevelextrtrDrkrrrtest_write_with_optimizations   z+PyZipFileTests.test_write_with_optimizationc CsnttzRttjtdd}|dWdn1sB0Yttjtdd}|dWdn1s0Yttjtdd}|dWdn1s0Ytt}t |dF}| t| }| d|| d|| d|Wdn1s*0YWdn1sJ0YWttn tt0dS)Nmod1.pyr: print(42) mod2.pyprint(42 * 42) zmod2.txtz bla bla bla rmkdirrr2rr*r3rr@rirqr`r\rsr r5r6rtrDrkrrrtest_write_python_directorys (((   Nz*PyZipFileTests.test_write_python_directoryc Cs*ttzttjtdd}|dWdn1sB0Yttjtdd}|dWdn1s0Ytn}t |dB}|j tddd| }| d|| d|Wdn1s0YWdn1s0YWttn tt0dS) Nrr:rrrcSs |d S)Nr)rj)rgrrrrzszEPyZipFileTests.test_write_python_directory_filtered..r{rrrrr$test_write_python_directory_filtereds (( Lz3PyZipFileTests.test_write_python_directory_filteredc Cst}t|d\}ttd}|dWdn1s@0Y|t|jtt tWdn1sv0YWdn1s0YdS)Nr:z!most definitely not a python file) rr@rir2rr3r RuntimeErrorrqr )r5rtrDrrrrtest_write_non_pyfiles  (z$PyZipFileTests.test_write_non_pyfilec Cs"ttzttjtdd}|dWdn1sB0Yt}t |dz}t $}| tjtdWdn1s0Y| d| |}| d||d|Wdn1s0YWdn1s0YWttn tt0dS)Nrr:zBad syntax in python file ryzmod1.pyc)rrrr2rr*r3rr@rirrqrZrWr`rsr )r5r6rtrDsrkrrrtest_write_pyfile_bad_syntax s (2 Jz+PyZipFileTests.test_write_pyfile_bad_syntaxc Csttzttjtdd}|dWdn1s@0Ytd}t |d8}| t td| }|d|Wdn1s0YWdn1s0YWttn tt0dS)Nrr:r)rrrr2rr*r3rr@rirqrrr`r\r rrrrtest_write_pathlike#s (Jz"PyZipFileTests.test_write_pathlikeN)rrrr\rdrurxrrrrrrrrrrrrYps rYc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZeejjdkdddZeejjdkddd Zd!d"Zd#S)$ ExtractTestscCsNttdtj*}tD]\}}|||qWdn1s@0YdS)Nr:)r@rArrSMALL_TEST_DATArBr5rDfpathfdatarrrmake_test_file3s zExtractTests.make_test_filec Cst|ttd}tD]\}}||}tj t |}tj |}| ||t |d$}| ||Wdn1s0Yt|q"Wdn1s0YWdn1s0YdSNrGr)r rr@rArrextractrrr*getcwdnormpathrSr2encoderTr )r5rDrr writtenfile correctfilerrrr test_extract8s     2zExtractTests.test_extractc Cs|ttd}tD]\}}|||}tj||}tj |}| tj ||||ft |d$}| ||Wdn1s0Yt|qWdn1s0YttdSr)rr@rArrrrrr*rr\samefiler2rSrrTr )r5targetrDrrrrrrrr_test_extract_with_targetKs    2(z&ExtractTests._test_extract_with_targetcCs4t}||Wdn1s&0YdSr)r rr5extdirrrrtest_extract_with_target^sz%ExtractTests.test_extract_with_targetcCs:t }|t|Wdn1s,0YdSr)r rrrrrrr!test_extract_with_target_pathlikebsz.ExtractTests.test_extract_with_target_pathlikec Cst|ttd~}|tD]`\}}tj t |}t |d$}| | |Wdn1sx0Yt|q*Wdn1s0YWdn1s0YdSr)r rr@rAr extractallrrrr*rr2rSrrTr )r5rDrroutfilerrrrtest_extract_allfs  2zExtractTests.test_extract_allc Cs|ttd|}||tD]\\}}tj||}t |d$}| | | Wdn1sn0Yt |q$Wdn1s0Yt tdSr)rr@rArrrrrr*r2rSrrTr )r5rrDrrrrrrr_test_extract_all_with_targetss   2(z*ExtractTests._test_extract_all_with_targetcCs4t}||Wdn1s&0YdSr)r rrrrrtest_extract_all_with_targetsz)ExtractTests.test_extract_all_with_targetcCs:t }|t|Wdn1s,0YdSr)r rrrrrrr%test_extract_all_with_target_pathlikesz2ExtractTests.test_extract_all_with_target_pathlikecCsP|tj|t|d }|||Wdn1sB0YdS)Nr)r\rrisfiler2rSrT)r5rRr#rrrr check_files zExtractTests.check_filecCsBtjj}||ddd||ddd||ddddS) Nz,,?,C:,foo,bar/z,z_,C_,foo,bar/zza\b,ce|f"g?h*iza\b,c_d_e_f_g_h_i../../foo../../ba..r/ foo/ba..r)r@rAZ_sanitize_windows_namerS)r5Zsanrrrtest_sanitize_windows_namesz'ExtractTests.test_sanitize_windows_namecCsgd}||dS)N))z ../foo/barfoo/bar)z foo/../barr)z foo/../../barr)z foo/bar/..r)z ./../foo/barr)z/foo/barr)z /foo/../barr)z/foo/../../barr_test_extract_hackers_arcnames)r5Zcommon_hacknamesrrr*test_extract_hackers_arcnames_common_casess z7ExtractTests.test_extract_hackers_arcnames_common_cases\zRequires \ as path separator.cCsgd}||dS)N))z ..\foo\barr)z ..\/foo\/barr)z foo/\..\/barr)z foo\/../\barr)z C:foo/barr)z C:/foo/barr)z C://foo/barr)z C:\foo\barr)z//conky/mountpoint/foo/barr)z\\conky\mountpoint\foo\barr)z///conky/mountpoint/foo/barconky/mountpoint/foo/bar)z\\\conky\mountpoint\foo\barr)z//conky//mountpoint/foo/barr)z\\conky\\mountpoint\foo\barr)z//?/C:/foo/barr)z\\?\C:\foo\barr)zC:/../C:/foo/barz C_/foo/bar)za:b\ce|f"g?h*izb/c_d_e_f_g_h_i)rrr)r5Zwindows_hacknamesrrr*test_extract_hackers_arcnames_windows_onlysz7ExtractTests.test_extract_hackers_arcnames_windows_onlyrzRequires / as path separator.cCsgd}||dS)N))z //foo/barr)rz foo../ba..r) foo/..\barrr)r5Zposix_hacknamesrrr(test_extract_hackers_arcnames_posix_onlysz5ExtractTests.test_extract_hackers_arcnames_posix_onlyc Cs>|D]2\}}d|}ttdtj0}t}||_d|_|||Wdn1s`0Y| t j d}t j ddd}t j j |g|dR}ttd6}|||} |j| |d || |fd Wdn1s0Y|||tdttd}||Wdn1s60Y|||tdt j j t g|dR}ttd.}||} |j| |d |d Wdn1s0Y|||t|dd ttd}|Wdn1s0Y|||t|dd ttqdS) Nfoobarr:rrrsubdirZsubsubrGzextract %r: %r != %r)msgz extract %rr)rr@rArrZipInforRrrBreplacerrkrr*r[rrSrr rrr ) r5Z hacknamesZarcnameZ fixednamer#rDr targetpathrrrrrrsH * $ *  & ( z+ExtractTests._test_extract_hackers_arcnamesN)rrrrrrrrrrrrrrrunittestZskipIfrrrkrrrrrrrr1s"    rc@sPeZdZddZddZddZddZd d Zed d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z d;d<Z!d=d>Z"d?d@Z#dAdBZ$dCdDZ%dEdFZ&dGdHZ'dIdJZ(e)dKdLZ*dMdNZ+dOS)P OtherTestsc CsBttdtjh}|dd|t|ddWdn1sJ0Y||dgdWdn1s~0Yttd}| }d}|D]:}| |}|| 7}Wdq1s0Yq| |dd hd}|D]}|| |7}q| |dd hWdn1s40YdS) Nr:r[rbarrrGr&rsbarfoo) r@rArrrBr~rrSr`rar2rTrZ)r5rDrlr+rnrrrrtest_open_via_zip_infos   *4 ,z!OtherTests.test_open_via_zip_infocCs^ttd>}dD](}t|}|jdO_|||qWdn1sP0YdS)Nr:Zabcdefghijklmnopr/)r@rArr flag_bitsrB)r5Zorig_zipr+rrrr-test_writestr_extended_local_header_issue1202s  z8OtherTests.test_writestr_extended_local_header_issue1202cCsttd8}tD]"\}}|||||jdqWdn1sJ0Y||jdttd}||jdWdn1s0Y||jddS)Nr:zzipfp is not openzipfp is not closedrG)r@rArrrBZassertIsNotNoner6 assertIsNonerrrr test_close s  .,zOtherTests.test_closecCsttd*}tD]\}}|||qWdn1s<0Yz8ttd}tWdn1sr0YWn"tjy||jdYn0dS)Nr:rGr)r@rArrrBr>rr6)r5rDrrZzipfp2rrrtest_close_on_exceptions ,*z"OtherTests.test_close_on_exceptioncCs d}|ttjt|ddS)NsdPKx!p@xPKxx!p@xPK/rG)rNotImplementedErrorr@rArrrrrrtest_unsupported_version&s  z#OtherTests.test_unsupported_versioncCsRtd}t|,}|D]}||qWdn1sD0YdS)Nzzip_cp437_header.zip)rr@rAr`r2r)r5rrDr[rrrtest_read_unicode_filenames1s  z&OtherTests.test_read_unicode_filenamescCsttd>}|dd|dd||djtWdn1sP0Yttd8}||j djd||j djdWdn1s0YdS)Nr:foo.txtzTest for unicode filenameuö.txtrrGrM) r@rArrBrrarRr_rSfilelist)r5rHrrrtest_write_unicode_filenames9s  4z'OtherTests.test_write_unicode_filenamescCsNttd.}|dd||ddWdn1s@0YdS)Nr:uприкладssample)r@rArrBrSrTrrrr'test_read_after_write_unicode_filenamesCs z2OtherTests.test_read_after_write_unicode_filenamescCsttd}d}ttdtj}|||Wdn1sB0Y|t ttdtjWdn1s|0Yttd4}|| |g|| ||Wdn1s0YdS)N testfile.txt#hello, world. this is some content.xrG) r rr@rArrBrFileExistsErrorrSr`rT)r5rRr#rDrrrtest_exclusive_create_zip_fileHs* .z)OtherTests.test_exclusive_create_zip_filecCstjtrttd}d}z)r5r6rHrrrtest_close_erroneous_filegs  (z$OtherTests.test_close_erroneous_filecCsttd}|dWdn1s*0Y|tt|tttttd }|t|Wdn1s0Yt }|d|t|| dd|t|dS)Nr:rrsthis is not a legal zip file r) r2rr3rr@ is_zipfilerrrrrr4rrrtest_is_zip_erroneous_filevs ( .  z%OtherTests.test_is_zip_erroneous_filecCst}tj|dd}|ddWdn1s80Y|}tt|D](}t|d|}|tj tj|qVdS)Nr:r>rO, for a Muse of Fire!) rrr@rArBrWr'rYrr>)r5r6rrNrrrtest_damaged_zipfiles*zOtherTests.test_damaged_zipfilecCstjtdd}|ddWdn1s00Y|ttttd4}|t||dd|}Wdn1s0Yt }| ||t||dd|t|dS)Nr:r>rrrr) r@rArrBr\rr2rrTrrr3)r5rr6Z zip_contentsrrrtest_is_zip_valid_files*  &  z!OtherTests.test_is_zip_valid_filecCs|ttjtdSr)rrr@rArrrrr%test_non_existent_file_raises_OSErrors z0OtherTests.test_non_existent_file_raises_OSErrorcCsnttd}||tjtjtttd}|dWdn1sN0Y|tjtjtdS)Nr:z short file)r2rrrr@r>rAr3)r5rr6rrr!test_empty_file_raises_BadZipFiles   (z,OtherTests.test_empty_file_raises_BadZipFilecCst}tj|dd}|ddWdn1s80Y|t|jd|t|jd|t|j |t|jddtt d}| dWdn1s0Y|t|j t dS)Nr:r>rO, for a Muse of Fire!z bogus.txtrzzipfile test data) rrr@rArBrrrTr2rdrr3)r5r+rrrrr!test_closed_zip_raises_ValueErrors* (z,OtherTests.test_closed_zip_raises_ValueErrorcCs|ttjtddS)Nq)rrr@rArrrrrtest_bad_constructor_modesz$OtherTests.test_bad_constructor_modecCstjtdd}|ddWdn1s00YtjtddP}|d|t|jdd|t|jdd|t|jddWdn1s0YdS) Nr:r>rrrGrUZrU)r@rArrBrTrrr2r5rrrrtest_bad_open_modes* zOtherTests.test_bad_open_modec Cstjtddv}|dd|d@}ttD]}||ddq0||dWdn1sl0YWdn1s0YdS)Nr:r>rrrr&r) r@rArrBr2r'r(rSrT)r5rrr$rrr test_read0s    zOtherTests.test_read0cCsDtjtdd"}|t|jddWdn1s60YdS)Nr:r>rrG)r@rArrKeyErrorr2rrrrtest_open_non_existent_itemsz&OtherTests.test_open_non_existent_itemcCs|ttjtdddS)Nr:r)rrr@rArrrrrtest_bad_compression_modesz$OtherTests.test_bad_compression_modecCsJd}tt|d }|t|jdWdn1s<0YdS)NsfPK.C@xPK..C@xPK/!rGr)r@rArrrrr2)r5r+rrrrtest_unsupported_compressionsz'OtherTests.test_unsupported_compressioncCsPtjtdd.}|dd||dgWdn1sB0YdS)Nr:r>z foo.txtqqqrr)r@rArrBrSr`rrrrtest_null_byte_in_filenames z%OtherTests.test_null_byte_in_filenamecCs<|tjd|tjd|tjd|tjddS)N.8r)rSr@ZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locatorrrrrtest_struct_sizes szOtherTests.test_struct_sizesc Cstjtdd*}||jd|ddWdn1s>0Ytjtdd}||jdWdn1sz0Yd}tjtdd"}||_|ddWdn1s0Ytjtdd}||j|Wdn1s0Ydd d td D}|d }tjtdd"}||_|ddWdn1s^0Ytjtdd}||j|Wdn1s0YtjtddR}| t |d |_Wdn1s0Y|ddWdn1s0Ytjtdd}||j|Wdn1sL0Ytjtdd"}d|_|ddWdn1s0Ytjtdd}d|_Wdn1s0Ytjtdd}||jdWdn1s0Ytjtdd"}d|_|ddWdn1sD0Yt j t}tjtdd}d|_Wdn1s0Y||t j tktjtdd}||jdWdn1s0YdS)Nr:r>r&rrrGs9Bravely taking to his feet, he beat a very brave retreat.cSsg|]}d|ddqS)rrrrr"rrrr%'r&z,OtherTests.test_comments..r soopssoriginal commentrsan updated commentsoriginal comment that's longersshorter comment)r@rArrSrrBr*r'rr~rrrgetsizer\)r5rZzipfrrZcomment2Zoriginal_zip_sizerrr test_commentssP*,*, ,. *,.,&., &zOtherTests.test_commentsc CspttdtjL}|dd|td|_Wdn1sD0YWdn1sb0YdS)Nr:rrzthis is an error)r@rArrrBr TypeErrorrrrrrtest_unicode_commentMs  zOtherTests.test_unicode_commentcCsttdtj"}||jd|_Wdn1s80Yttd}||jdWdn1sr0YdS)NrrrG)r@rArrrrrrSrrrr$test_change_comment_in_empty_archiveSs  $z/OtherTests.test_change_comment_in_empty_archivecCsttdtj}|ddWdn1s20Yttdtj"}||jd|_Wdn1st0Yttd}||jdWdn1s0YdS)Nr:rrrrrG) r@rArrrBr\rrrSrrrr'test_change_comment_in_nonempty_archiveZs* $z2OtherTests.test_change_comment_in_nonempty_archivecCstjtdd}|ztjtdd}WntjyF|dYn0tjtdd}|ztjtdd}Wn|dYn0dS)Nr:r>rGz+Unable to create empty ZIP file in 'w' moderz+Unable to create empty ZIP file in 'a' mode)r@rArrr>rrrrrtest_empty_zipfilecszOtherTests.test_empty_zipfilecCs*ttd}||tjtjtddSNr:rG)r2rrrr@r>rArqrrrtest_open_empty_filets zOtherTests.test_open_empty_filecCs|ttjdddS)NZ seventies)irMrMrrr)rrr@rrrrrtest_create_zipinfo_before_1980|sz*OtherTests.test_create_zipinfo_before_1980cCs tjdd}|t|ddS)NemptyrQz&)r@rrSrr5zirrrtest_create_empty_zipinfo_reprs z)OtherTests.test_create_empty_zipinfo_reprcCst}||jd||jd||jd||jtj||jd||j d| |j d||j tj ||jtj ||jd||jd||jd||jd||jd||jd||jddS)NZNoNamerr&)rrr)r@rrSZ orig_filenamerRrrrrr-rZZ create_systemZcreate_versionZDEFAULT_VERSIONZextract_versionZreservedrZvolumeZ internal_attrrrbr;rrrr,test_create_empty_zipinfo_default_attributess"z7OtherTests.test_create_empty_zipinfo_default_attributescCsHd}tt|d}||Wdn1s:0YdS)NsnPK@abcAPK@abcPK3%rG)r@rArrrrdr5rrrrr#test_zipfile_with_short_extra_fields z.OtherTests.test_zipfile_with_short_extra_fieldc Cs~d}d}d}ttdtj}|jddd}||Wdn1sN0Y|jddd.}|t|jdddWdn1s0Y|t|jdd dWdn1s0Y|t|d d Wdn1s0Y|t|t d Wdn1s@0Y|t| Wdn1st0Y||Wdn1s0Y|jd dd}||Wdn1s0YWdn1s0Yttd Z}| | d|| | d|| | d || | gdWdn1sp0YdS)Ns"It's fun to charter an accountant!s And sail the wide accountant seas#To find, explore the funds offshorer:rr>rhandlerGr_ZabcderHbaz)rrr )r@rArrr2r3rrrBrhrrSrTr`)r5Zmsg1Zmsg2Zmsg3rZw2w1rrrtest_open_conflicting_handless2( , , , , (*Jz(OtherTests.test_open_conflicting_handlesc Csd}|d}ttd}|d|Wdn1s<0Yttd}|dd}||tj| | ||| tj | | d||tj | | || | d|||d|dtj | | t||dtj| | dWdn1s20YWdn1sR0Yt}tj|dd}|d|Wdn1s0Ytj|dd}|dd}||tj| | ||| tj | | d||tj | | || | d|||d|dtj | | t||dtj| | dWdn1s0YWdn1s0YdS) NsWhere's Bruce?sBrucer:rrGrrIr>)findr@rArrBr2rrSEEK_SETrSrSEEK_CURrTSEEK_ENDrYrr)r5txtblocrr6r+rrrtest_seek_tellsB *P,zOtherTests.test_seek_tellc Csd}t|}tj|dtjd}|ddWdn1sB0YtddJt| }|t |j dWdn1s0YWdn1s0YdS)NsPKr:)r8raz zipfile.bz2) rrr@rArrBmockZpatchrrr)r5r+Zzip_filerHrrr)test_decompress_without_3rd_party_librarys * z4OtherTests.test_decompress_without_3rd_party_librarycCsttttdSrrrrrrrszOtherTests.tearDownN),rrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrsR          : & rc@seZdZddZddZdS)AbstractBadCrcTestscCsN|j}tjt|dd }|d|Wdn1s@0YdS)NrGr>afile)zip_with_bad_crcr@rArrrSrdr rrrtest_testzip_with_bad_crcsz-AbstractBadCrcTests.test_testzip_with_bad_crcc Csf|j}tjt|dd"}|tj|jdWdn1sB0Ytjt|ddL}|dd }|tj|jWdn1s0YWdn1s0Ytjt|dd}|ddR}d|_ |tj|drqWdn1s0YWdn1s80YWdn1sX0YdS)NrGr>rr) rr@rArrrr>rTr2 MIN_READ_SIZE)r5rrZ corrupt_filerrrtest_read_with_bad_crcs0L z*AbstractBadCrcTests.test_read_with_bad_crcN)rrrrrrrrrrsrc@seZdZejZdZdS)StoredBadCrcTestssxPK ;:r afilehello,AworldPK ;:r afilePK3/N)rrrr@rr8rrrrrrsrc@seZdZejZdZdS)DeflateBadCrcTestss|PKn} =FAKEnafileHW(/Iɠ=PKn} =FAKEnafilePK33N)rrrr@r r8rrrrrr 'sr c@seZdZejZdZdS)Bzip2BadCrcTestssPK nu =FAKE8nafileBZh91AY&SYԨ@D P!u5:"(HjTe?PK nu =FAKE8n afilePK3[N)rrrr@rr8rrrrrr!4sr!c@seZdZejZdZdS)LzmaBadCrcTestssPKnu =FAKEnafile ]4I:3` q!.8PKnu =FAKEn afilePK3>N)rrrr@rr8rrrrrr"Dsr"c@sZeZdZdZdZdZdZddZddZd d Z d d Z e d dZ ddZ ddZdS)DecryptionTestssPKni.#y?&test.txtgly|-=yrZ}Lg|䋺)lPKni.#y?& test.txtPK6LsPK }38xuzeroUT ֋GڋGUx.)rr*r'r+)r-Z datacountrrrr.s z-AbstractTestsWithRandomBinaryFiles.setUpClasscCs:ttd}||jWdn1s,0YdSr/r1r4rrrr7s z(AbstractTestsWithRandomBinaryFiles.setUpcCsttttdSrrrrrrrsz+AbstractTestsWithRandomBinaryFiles.tearDowncCsJt|d|(}|td|ttWdn1s<0YdS)Nr:r;)r@rAr3rr)rrrrFs z4AbstractTestsWithRandomBinaryFiles.make_test_archivecCs|||t|d|R}|t}|t|t|j|||j||d|jWdn1sr0YdS)NrGr;)rFr@rArTrrSrYr+)r5rr8rDtestdatarrrros   z+AbstractTestsWithRandomBinaryFiles.zip_testcCs t|D]}|||jqdSrrprqrrr test_reads z,AbstractTestsWithRandomBinaryFiles.test_readc Cs2|||t|d|}g}|t,}|d}|s>qJ||q.Wdn1s^0Yg}|d,}|d}|sq||qxWdn1s0Yd|} |t | t |j || |j d|} |t | t |j || |j Wdn1s$0YdSrs) rFr@rAr2rrTrur*rSrYr+) r5rr8rDrvrwrxryrzZ testdata1Z testdata2rrrr{s(   *  *  z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCs t|D]}|||jqdSrr|rqrrrr}s z,AbstractTestsWithRandomBinaryFiles.test_openc Cs|||t|d|}g}|t2}|tdd}|sBqN||q,Wdn1sb0Yd|}| t |t |j | ||j Wdn1s0YdSr) rFr@rAr2rrTrrur*rSrYr+)r5rr8rDrvrwrxr5rrrrs  * z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCs t|D]}|||jqdSrrrqrrrr s z3AbstractTestsWithRandomBinaryFiles.test_random_openN)rrrrr.r7rrFror6r{r}rrrrrrr2s  r2c@seZdZejZdS) StoredTestsWithRandomBinaryFilesNrUrrrrr7 sr7c@seZdZejZdS)!DeflateTestsWithRandomBinaryFilesNrKrrrrr8 sr8c@seZdZejZdS)Bzip2TestsWithRandomBinaryFilesNr rrrrr9 sr9c@seZdZejZdS)LzmaTestsWithRandomBinaryFilesNrrrrrr:# sr:c@s,eZdZddZddZddZddZd S) TellablecCs||_d|_dSNr)r6offsetr4rrr__init__+ szTellable.__init__cCs|j|}|j|7_|Sr)r6r3r=)r5r+nrrrr3/ s zTellable.writecCs|jSr)r=rrrrr4 sz Tellable.tellcCs|jdSrr6flushrrrrrA7 szTellable.flushN)rrrr>r3rrArrrrr;* sr;c@s$eZdZddZddZddZdS) UnseekablecCs ||_dSr)r6r4rrrr>; szUnseekable.__init__cCs |j|Sr)r6r3rrrrr3> szUnseekable.writecCs|jdSrr@rrrrrAA szUnseekable.flushN)rrrr>r3rArrrrrB: srBc@s$eZdZddZddZddZdS)UnseekableTestsc CspddttfD]Z}|j|d6t}|dt|}t||dtj (}| dd| dd Wdn1s0Y| | dd d tj|d d }| d }| |dWdn1s0Y| d }| |d Wdn1s 0YWdn1s@0YWdq1s`0YqdS)NcSs|SrrrrrrrzF r&z/UnseekableTests.test_writestr..wrapperabcr:ones111twos222rIabcPKrGr>)r;rBsubTestrrr3BufferedWriterr@rArrBrSrWr2rT)r5rFrbfrDrzopenrrr test_writestrE s   * . zUnseekableTests.test_writestrc CsddttfD]}|j|dt}|dt|}t||dtj }| t t t t d}|dWdn1s0Y|t dt t d}|d Wdn1s0Y|t d Wdn1s0Y||dd d tj|d d}| d }||dWdn1sZ0Y| d  }||d Wdn1s0YWdn1s0YWdq1s0YqdS)NcSs|SrrrDrrrrzV r&z,UnseekableTests.test_write..rErGr:r0rIrHrKrJrIrLrGr>)r;rBrMrrr3rNr@rAr addCleanupr rr2rSrWrT)r5rFrrOrDf2rrPrrr test_writeU s&    (  (* 0 zUnseekableTests.test_writec CsnddttfD]X}|j|d4t}|dt|}t||dtj |}| dd}|dWdn1s0Y| dd}|d Wdn1s0YWdn1s0Y| | dd d t|4}| | dd| | dd Wdn1s>0YWdq1s^0YqdS) NcSs|SrrrDrrrrzk r&z1UnseekableTests.test_open_write..rErGr:rHrIrJrKrIrL)r;rBrMrrr3rNr@rArr2rSrWrT)r5rFrrOrrPrrrtest_open_writej s  (F zUnseekableTests.test_open_writeN)rrrrQrTrUrrrrrCD srCc@sheZdZeddZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZdS)TestsWithMultipleOpenscCs dtd|_dtd|_dS)NrI'rK)rdata1r$r,rrrr.} sz!TestsWithMultipleOpens.setUpClasscCsPt|dtj,}|d|j|d|jWdn1sB0YdS)Nr:rHrJ)r@rAr rBrXr$)r5rrDrrrrF sz(TestsWithMultipleOpens.make_test_archivec Cst|D]}||tj|dd}|df}|d<}|d}|d}||7}||7}Wdn1s~0YWdn1s0Y||||||jWdq1s0YqdS)NrGr>rH)rrFr@rAr2rTrSrXr5rrzopen1zopen2rXr$rrrtest_same_file s     H z%TestsWithMultipleOpens.test_same_filec Cst|D]}||tj|dd}|df}|d<}|d}|d}||7}||7}Wdn1s~0YWdn1s0Y|||j|||jWdq1s0YqdS)NrGr>rHrJrY rrFr@rAr2rTrSrXr$rZrrrtest_different_file s     Hz*TestsWithMultipleOpens.test_different_filec Cst|D]}||tj|dd}|df}|d}|d2}|d}||7}||7}Wdn1s~0YWdn1s0Y|||j|||jWdq1s0YqdS)NrGr>rHrYrJr^)r5rrr[rXr\r$rrrtest_interleaved s       Hz'TestsWithMultipleOpens.test_interleavedc Cst|D]}||t}t|d0}||d}||d}Wdn1sb0Y|d}|d}||7}||7}Wdn1s0Y| ||j | ||j qdS)NrGrHrJrY) rrF contextlib ExitStackr@rA enter_contextr2rTrSrXr$)r5rstackrr[r\rXr$rrrtest_read_after_close s   .   *z,TestsWithMultipleOpens.test_read_after_closec Cst|D]}t|dtj`}|d|j|d|j|d}|d}Wdn1sd0YWdn1s0Y| ||jddt|d$}|d}|d}Wdn1s0Y| ||j| ||jqdS)Nr:rHrJrYrG) rr@rAr rBrXr$r2rTrSr5rrr[rXr$rrrtest_read_after_write s  F (z,TestsWithMultipleOpens.test_read_after_writec Cst|D]}t|dtj`}|d|j|d(}|d|d|jWdn1sd0YWdn1s0Yt|d$}|d}|d}Wdn1s0Y| ||j| ||jqdS)Nr:rHrYrJrG) rr@rAr rBrXr2rTr$rSrfrrrtest_write_after_read s   J (z,TestsWithMultipleOpens.test_write_after_readc Cs|ttjtddR}tdD]8}|d|d}Wdq"1sP0Yq"Wdn1sp0Yttj }| | dWdn1s0YdS)NrGr>rrH) rFrr@rAr'rTr2rdevnullZ assertLessfileno)r5rrr[rrrrtest_many_opens s    > z&TestsWithMultipleOpens.test_many_opensc Cs:ttdtj}|d|jWdn1s40Yttdtj}|dd^}|d}|dd}||j Wdn1s0Y||7}Wdn1s0YWdn1s0Y| ||jtt$}| |d|j Wdn1s,0YdS)Nr:rHrrGrYrJ) r@rArr rBrXr2rTr3r$rS)r5rZr1rXr rrrtest_write_while_reading s, *H z/TestsWithMultipleOpens.test_write_while_readingcCs ttdSrrOrrrrr szTestsWithMultipleOpens.tearDownN)rrrrr.rFr]r_r`rergrhrkrlrrrrrrV{ s    rVc@s<eZdZddZddZddZddZd d Zd d Zd S)TestWithDirectorycCsttdSr)rrrrrrrr7 szTestWithDirectory.setUpc Csttd}|tWdn1s.0Y|tjtj td|tjtj tdd|tj tj tddddS)N zipdir.ziprbrG) r@rArrrr\rrisdirr*rrrrrtest_extract_dir s (z"TestWithDirectory.test_extract_dircCs ttjtd|dSNr)rrrr*rrqrrrr test_bug_6050 szTestWithDirectory.test_bug_6050c Cstjtd}t|t|jd@}tt d}| ||j d}| |j d||j|d>dB| |d|j d}| |j d ||j|d>dBWdn1s0Ytt d }|j d}| |j d||j|d>dB|j d}| |j d ||j|d>dBtjtd }t|||| tjtj|d|tt|d Wdn1s0YdS) Nrrr:rz/x/r3yrMzy/rGrr)rrr*rrrst_moder@rArr3rr\rRrjrSrrrprYlistdir)r5dirpathr?rrrrrrtest_write_dir s0     4    z TestWithDirectory.test_write_dirc Cs ttjtdttdB}|dd|j d}| |j d| |j dWdn1sh0Yttd}|j d}| |j d| |j dtjtd}t|||| tjtj|d| t|dgWdn1s0YdS) Nrr:zx/r&riArGr)rrrr*rr@rArrBrrSrRrr\rjrrprv)r5rrrrrrtest_writestr_dir# s  ,   z#TestWithDirectory.test_writestr_dircCs tttjtrttdSr)r rrrrrr rrrrr4 s zTestWithDirectory.tearDownN) rrrr7rqrsrxryrrrrrrm s rmc@s4eZdZddZddZddZddZd d Zd S) ZipInfoTestscCsHtjt}|t|jd|| ||j t j tdSNztest_zipfile.py)r@r from_filerhrS posixpathrrrRris_dirrbrrrrrrrtest_from_file; s zZipInfoTests.test_from_filecCsNtjtt}|t|j d| | ||j t jtdSr{)r@rr|rrrhrSr}rrrRrr~rbrrrrrrrtest_from_file_pathlikeA sz$ZipInfoTests.test_from_file_pathlikecCsPtjttd}|t|j d| | ||j tj tdS)Nr)r@rr|rfsencoderhrSr}rrrRrr~rbrrrrrrtest_from_file_bytesG sz!ZipInfoTests.test_from_file_bytescCsxttdZ}tj|d}|t|j d| | ||j t jtWdn1sj0YdS)Nrr)r2rhr@rr|rjrSr}rrrRrr~rbrrr)r5rrrrrtest_from_file_filenoM s  z"ZipInfoTests.test_from_file_filenocCs`tjtjt}tj|d}||j d| | ||j tj ||jddS)NZ stdlib_testsz stdlib_tests/r)rrrgabspathrhr@rr|rSrRr\r~rrrb)r5rwrrrr test_from_dirT s zZipInfoTests.test_from_dirN)rrrrrrrrrrrrrz: s rzc@sJeZdZddZddZddZddZd d Zed d Z d dZ dS)CommandLineTestcOs2tjddg|Ri|\}}}|tjdS)N-mr@r)rZassert_python_okrrlinesepr)r5argsrCrcouterrrrr zipfilecmd_ s zCommandLineTest.zipfilecmdcGstjddg|RS)Nrr@)rZassert_python_failure)r5rrrrzipfilecmd_failured sz"CommandLineTest.zipfilecmd_failurecCs||\}}}||d|d||d||d||dd\}}}||d||ddS)Nr&susageserrorsrequired-lr)rrSrZr@ZassertNotEqualstrip)r5rrrrrr test_bad_useg s  zCommandLineTest.test_bad_usecCsXtd}dD] }|||}||dq td}|d|\}}}||ddS)Nrn)-tz--tests Done testingz testtar.tarrr&)rrrSrstripr)r5zip_nameoptrrrrrrtest_test_commandq s z!CommandLineTest.test_test_commandcCstd}t}t|d}||Wdn1s<0Y|dd}dD] }|j||dd}| ||qZdS)NrnrGr backslashreplace)rz--listzascii:backslashreplace)ZPYTHONIOENCODING) rrrUr@rArVrWrrrS)r5rrtZtfZexpectedrrrrrtest_list_commandz s(z!CommandLineTest.test_list_commandc Cs\|ttttd}|dWdn1s60Ytt|ttttj tdd}|dWdn1s0Yttg}ttdtdg}dD]}z|j |t g|R}| |dtt L}| ||| ||d d | ||d d Wdn1s60YWtt qtt 0qdS) Nr:ztest 1zfile.txtztest 2rz /file.txt)z-cz--creater&rstest 1rstest 2)rRr rr2r3rr TESTFNDIRr rr*rrrSr@rAr`rT)r5rfilesr`rrrHrrrtest_create_command s$  (  (  8z#CommandLineTest.test_create_commandc Cstd}dD]}t}||||}||dt|}|D]}tj ||j dtj }| r|tj|qH|tj|t|d&}||||WdqH1s0YqHWdn1s0YWdq 1s 0Yq dS)Nrn)z-ez --extractr&rr)rr rrSr@rArarrr*rRrrkr~r\rprr2rT) r5rrrrrHrrrrrrtest_extract_command s     z$CommandLineTest.test_extract_commandN) rrrrrrrrr rrrrrrr] s    rc@seZdZddZddZddZddZee j d ee d e j d d d Zee j d ee d e j d ddZdS)TestExecutablePrependedZipcCs tddd|_tddd|_dS)NZ exe_with_zipZ ziptestdata)rZ exe_with_z64)rexe_zip exe_zip64rrrrr7 sz TestExecutablePrependedZip.setUpcCsj|t|d|t|4}|D]}||}|d|q,Wdn1s\0YdS)Nzis_zipfile failed on sFAVORITE_NUMBER)r\r@rrAr`rTrZ)r5r[rDr?r+rrr_test_zip_works s    z*TestExecutablePrependedZip._test_zip_workscCs||jdSr)rrrrrr test_read_zip_with_exe_prepended sz;TestExecutablePrependedZip.test_read_zip_with_exe_prependedcCs||jdSr)rrrrrr"test_read_zip64_with_exe_prepended sz=TestExecutablePrependedZip.test_read_zip64_with_exe_prependedzsys.executable required.z /bin/bashz#Test relies on #!/bin/bash working.cCs"t|jtjg}|d|dSNsnumber in executable: 5) subprocess check_outputrsys executablerZr5outputrrrtest_execute_zip2 sz,TestExecutablePrependedZip.test_execute_zip2cCs"t|jtjg}|d|dSr)rrrrrrZrrrrtest_execute_zip64 sz-TestExecutablePrependedZip.test_execute_zip64N)rrrr7rrrrZ skipUnlessrrrr]X_OKrrrrrrr s    rc@seZdZGdddZdS)jaracoc@seZdZGdddZdS)zjaraco.itertoolsc@s$eZdZddZddZddZdS)zjaraco.itertools.CountercCsd|_t||_dSr<)riter _orig_iter)r5r$rrrr> sz!jaraco.itertools.Counter.__init__cCs|Srrrrrr__iter__ sz!jaraco.itertools.Counter.__iter__cCst|j}|jd7_|Sr)nextrr)r5resultrrr__next__ s z!jaraco.itertools.Counter.__next__N)rrrr>rrrrrrCounter srN)rrrrrrrrrC srCN)rrrrCrrrrr srcCs&tj|D]}||dq|S)Nr&)r@ CompleteDirs _implied_dirsr`rB)rHr[rrradd_dirs srcCsZt}t|d}|dd|dd|dd|dd |d d d |_|S) Nr:rs content of azb/c.txts content of cz b/d/e.txts content of ezb/f.txts content of fz g/h/i.txts content of iz alpharep.zip)rrr@rArBrR)r+rHrrrbuild_alpharep_fixture s      rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdZd d!Zd"d#Zd$d%Zd&S)'TestPathcCst|_||jjdSr)rarbfixturesrRrrrrrr7 s zTestPath.setUpccsh|tVWdn1s&0Y|ttVWdn1sZ0YdSr)rMrrrrrrzipfile_alpharep s & zTestPath.zipfile_alpharepc cs|t|jt}|D]Z}|j}|||j}| d}| | Wdn1sf0Y|VqdSr/) rrrrcr rr6rrRr2r3rW)r5Ztmpdiralpharepbufferrstrmrrrzipfile_ondisk! s   ,zTestPath.zipfile_ondiskc CsV|D]H}t|}|\}}}|\}}}|\} |\} | \} qdSrrr@riterdir) r5rrootrrogrGrrrAhr$rrrtest_iterdir_and_types+ s     zTestPath.test_iterdir_and_typescCs|D]}t|}qdSrrr@rr5rrrrrtest_subdir_is_dir; s  zTestPath.test_subdir_is_dirc CsZ|D]L}t|}|\}}}|}|}Wdq1sJ0YqdSr)rr@rrr2rT)r5rrrrorrr+rrrr}C s    &zTestPath.test_opencCs*|D]}t|}|\}}}qdSrr)r5rrrrorrrrr6K s  zTestPath.test_readcCs<|D].}t|}|d}|ddd}qdSNrrorze.txt)rr@rjoinpathr5rrrrArrr test_joinpathR s    zTestPath.test_joinpathcCs4|D]&}t|}|d}|ddd}qdSrrrrrrtest_traverse_truedivZ s   zTestPath.test_traverse_truedivcCs*|D]}tt|}t|qdSr)rrrr_r@)r5rZpathlikerrrtest_pathlike_constructionb s z#TestPath.test_pathlike_constructioncCs*|D]}t|}|tdqdSrr)rr@rrrrrrtest_traverse_pathlikej s  zTestPath.test_traverse_pathlikecCs|D]}t|}qdSrrrrrr test_parento s  zTestPath.test_parentcCs|D]}t|}qdSrrrrrrtest_dir_parentu s  zTestPath.test_dir_parentcCs|D]}t|}qdSrrrrrrtest_missing_dir_parent{ s  z TestPath.test_missing_dir_parentcCsP|D]B}t|}|\}}}|dd|dd|d\}qdS)Nrrz bar/baz.txtr r)rr@rrrB)r5rrrrorr rrrtest_mutability s    zTestPath.test_mutabilityi cCs@t}t|d}ttt|jD]}|||q$d|_ |Sr) rrr@rAmapr_r'HUGE_ZIPFILE_NUM_ENTRIESrBr?)r5rrHentryrrr huge_zipfile s  zTestPath.huge_zipfilecCs6t|}tj|}|D]}|dq"dS)Nsuffix)r@rrrrCrrr)r5rentriesrrrrtest_joinpath_constant_time s  z$TestPath.test_joinpath_constant_timecCs"ddtdD}tj|dS)NcSs g|]}dtjt|qS)r)r*stringascii_lowercaser_)r#r?rrrr% r&z:TestPath.test_implied_dirs_performance..rW)r'r@rrrrrrtest_implied_dirs_performance sz&TestPath.test_implied_dirs_performanceN)rrrr7rrrrr}r6rrrrrrrrrrrrrrrrr s&   r__main__)Vraimportlib.utilrnrrCrrr}rrrrr]rZ unittest.mockrr@tempfilerrrrZ test.supportrrrr r r r r rrrrrr(Z DATAFILES_DIRrrrZTestCaserrr rrr'rJrLrMrNrTrVrWrXrYrrrrr r!r"r#r2r7r8r9r:r;rBrCrVrmrzrrtupleZconsumerrrrrmainrrrrs   0  C       BA  g[     7}A#P' $