o hb@sJ ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZz ddlZejZWneyTdZejZYnwzddlZWn eyfdZYnwzddlZWn eyxdZYnwgdZGdddeZGdddeZeZZdZdZdZdZd Zd Z d Z!d Z"d Z#dZ$dZ%dZ&dZ'dZ(e )e'Z*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2d Z3dZ4dZ5dZ6e )e5Z7dZ8dZ9dZ:dZ;dZdZ?d Z@dZAdZBdZCd ZDdZEd ZFdZGd ZHd!ZId"ZJd#ZKd$ZLe )eKZMdZNdZOdZPdZQdZRdZSdZTdZUd ZVdZWdZXdZYd%ZZd&Z[e )eZZ\d'Z]d(Z^e )e]Z_dZ`dZadZbdZcdZddZedZfdZgd ZhdZid)Zje kd*Zld+d,Zmd-d.Znd/d0Zod1d2Zpd3d4ZqGd5d6d6erZsdatd7d8Zud9d:ZvGd;d<d<ZwGd=d>d>Zxidd?dd@ddAddAddAddAddBddCd dDddEddBd dFd dGd"dHdIdJdKdLdMdNZydOdPZzdrdQdRZ{dSdTZ|GdUdVdVZ}GdWdXdXZ~GdYdZdZejZGd[d\d\ejZGd]d^d^ZGd_d`d`eZdadbZdcddZejZ dedfZGdgdhdheZGdidjdjeZdrdkdlZGdmdndnZdrdodpZedqkr#edSdS)sN) BadZipFile BadZipfileerror ZIP_STORED ZIP_DEFLATED ZIP_BZIP2ZIP_LZMA is_zipfileZipInfoZipFile PyZipFile LargeZipFilePathc@ eZdZdS)rN__name__ __module__ __qualname__rr./opt/alt/python310/lib64/python3.10/zipfile.pyr,rc@r)r Nrrrrrr 0rr i -.?s<4s4H2LHsPK z<4s4B4HL2L5H2LsPK z <4s2B4HL2L2HsPKz<4sLQLsPKz <4sQ2H2L4QsPKiPKrrrr s     r c Cs |t8}|dkr |S|||t}t|tkrtdtt|\}}}}|tkr/|S|dks7|dkr;t d|t 8}||krGt d||||}|t }t|t kr_td| t s~||kr~||d}|t }t|t kr~td| t st dtt |\ }} } } } } }}}}|||ks| dt |krt d||t<| |t<| |t<||t<||t<||t<||t<|||t<|S) NrzUnknown I/O errorrz3zipfiles that span multiple disks are not supportedz.Corrupt zip64 end of central directory locatorz/Zip64 end of central directory record not foundrz-Corrupt zip64 end of central directory record)sizeEndCentDir64Locatorseekr@r2r<structr1structEndArchive64LocatorstringEndArchive64LocatorrsizeEndCentDir64 startswithstringEndArchive64structEndArchive64_ECD_SIGNATURE_ECD_DISK_NUMBER_ECD_DISK_START_ECD_ENTRIES_THIS_DISK_ECD_ENTRIES_TOTAL _ECD_SIZE _ECD_OFFSET _ECD_LOCATION)fpinoffsetendrecdataZsigZdisknoZreloffZdisksZextraszZszcreate_versionZ read_versionZdisk_numZdisk_dirZdircountZ dircount2ZdirsizeZ diroffsetrrr _EndRecData64sX             r\c Csb |dd|}z |t dWn tyYdSw|}t|tkrW|ddtkrW|dddkrWtt |}t |}| d| |tt ||t|St |dtd}||d|}|t}|dkr|||t}t|tkrdSt tt |}|t}||t|t|}| || ||t ||||SdS)Nrr r"sr/i)rGtellsizeEndCentDirr<r@r2stringEndArchiverHr1structEndArchivelistr3r\maxrfind_ECD_COMMENT_SIZE) rWZfilesizerZrYZmaxCommentStartr7ZrecDataZ commentSizecommentrrrr;s@         r;c@sZeZdZ dZdddZddZdd d Zd d Zd dZe dddddZ ddZ dS)r ) orig_filenamerD date_time compress_type_compresslevelrfr5 create_systemr[extract_versionreserved flag_bitsvolume internal_attr external_attr header_offsetCRC compress_size file_size _raw_time _end_offsetNoNamerrrrrcCs||_|td}|dkr|d|}tjdkr%tj|vr%|tjd}||_||_|ddkr5tdt |_ d|_ d|_ d|_ tjdkrJd|_nd|_t|_t|_d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr/rzz+ZIP does not support timestamps before 1980r/Zwin32r!)rgfindchrossepreplacerDrh ValueErrorrrirjrfr5sysplatformrkDEFAULT_VERSIONr[rlrmrnrorprqrtrurw)selfrDrhZ null_byterrr__init__ls6    zZipInfo.__init__cCsd|jj|jfg}|jtkr|dt|j|j|jd?}|jd@}|r2|dt ||r;|d|| }|rD|j rL|d|j |rQ|j rd|jtks\|j |j krd|d|j |d d |S) Nz<%s filename=%r compress_type=%sr+rz filemode=%rz external_attr=%#xz file_size=%rz compress_size=%r>) __class__rrDrirr3compressor_namesgetrqstatfilemodeis_dirrurtr4)rrEhiloisdirrrr__repr__s,         zZipInfo.__repr__NcCsz |j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}|jd @r4d}}}n |j}|j}|j}|j}d} |durN|tkpM|tk}|rbd } |t| dt | d ||}|tksj|tkrv|spt d d }d }t } |j t krtt| } n |j tkrtt| } t| |j|_t| |j|_|\} } ttt|j|j| |j |||||t| t| } | | |S)Nrrzr&rr#r r!r(r"rzz |jd|jfWSty|jd|jdBfYSw)Nasciiutf-8)rDencodernUnicodeEncodeErrorrrrrrs  zZipInfo._encodeFilenameFlagscCs6|j}tj}t|dkr|d|dd\}}|dt|kr'td||f|dkr|d|d}zD|jdvrLd}|d|dd\|_|dd}|jd krdd }|d|dd\|_|dd}|jd krvd }|d|dd\|_Wntjytd |d dw||dd}t|dks dSdS)Nr"r.z"Corrupt extra field %04x (size=%d)r)lrz File sizez|}tj tj |d}|dtj tjfvrd|dd}|dtj tjfvsT|rj|d7}|||}|jd @d >|_|rd|_|jd O_|S|j|_|S) Nrr$rzry;)rr;rrr{rr+) isinstancer~PathLikefspathrS_ISDIRst_modetime localtimest_mtimepathnormpath splitdriveraltseprqrust_size) clsrDarcnamerstrmtimerhzinforrr from_files6        zZipInfo.from_filecCs |jddkS)Nr{rDrrrrr%szZipInfo.is_dir)rxryN) rrr __slots__rrrrr classmethodrrrrrrr Qs , . %r cCs0tdD]}|d@r|d?dA}q|dL}q|S)Nrrl q[)range)crcr9rrr_gen_crc/s  rcsldddtdurttttdatfddfdd|D]}|q&fd d }|S) NixV4igE#ixV4cs |d?||Ad@AS)Nrr)Zchr)crctablerrcrc32Isz_ZipDecrypter..crc32cs<|d@d@ddd@d?dS)Nrrirr)c)rkey0key1key2rr update_keysMs z"_ZipDecrypter..update_keyscsP t}|j}|D]}dB}|||dAd?d@N}|||q t|S)Nr rrr) bytearrayr3bytes)rZrEr3rk)rrrr decrypterWs z _ZipDecrypter..decrypter) _crctablerbmaprr)pwdprr)rrrrrrr _ZipDecrypter?s   rc@s,eZdZddZddZddZddZd S) LZMACompressorcCs d|_dSr)_comprrrrrgs zLZMACompressor.__init__cCsFtdtji}tjtjttj|gd|_tdddt ||S)NidfilterszrXrr>rrrr s z_Tellable.__init__cCs|j|}|j|7_|Sr)r>writerX)rrZrrrrrs z_Tellable.writecCr r)rXrrrrr^rz_Tellable.tellcC|jdSr)r>rrrrrrz_Tellable.flushcCrr)r>r rrrrr rz_Tellable.closeN)rrrrrr^rr rrrrr s  rcseZdZ dZdZdZ  d'ddZdd Zd d Zd(d dZ d)ddZ ddZ d(ddZ ddZ ddZddZddZfddZd d!Zd*d#d$Zd%d&ZZS)+ ZipExtFilei@iiNFcCs&||_||_||_|j|_|j|_|j|_t |j|_ d|_ d|_ d|_ d|_||_|j|_t|dr=|j|_td|_nd|_d|_z|r\||_|j|_|j|_|j|_d|_Wn tyfYnwd|_|r|j d@ry|j!d?d@}n|jd?d@}|"}||krt#d |j$dSdS) NFr/rrsTrrrzBad password for file %r)%_fileobj_pwd_close_fileobjri_compress_typert_compress_leftru_leftr _decompressor_eof _readbuffer_offsetnewlinesmoderDnamerBrs _expected_crcr _running_crc _seekablerr^_orig_compress_start_orig_compress_size_orig_file_size_orig_start_crcAttributeError _decrypterrnrv_init_decrypterrrg)rrr(zipinforZ close_fileobjZ check_bytehrrrr+sN      zZipExtFile.__init__cCs4t|j|_|jd}|jd8_||dS)Nrr()rrr2rr@r!)rrrrrr3^s  zZipExtFile._init_decryptercCsvd|jj|jjfg}|js,|d|j|jf|jtkr+|dt |j|jn|d|dd |S)N<%s.%sz name=%r mode=%rr [closed]rr) rrrclosedr3r)r(r rrrr4rrErrrris    zZipExtFile.__repr__rcCsN |dkr |jd|jd}|dkr |j|j|}||_|Stj||S)Nr r)r%r|r&ioBufferedIOBasereadline)rlimitr8linerrrr=wszZipExtFile.readlinercCst |t|j|jkr/||}t||jkr&||j|jd|_d|_n |jt|8_|j|j|jdS)Nri)r2r%r&r@)rrchunkrrrpeeks zZipExtFile.peekcCs|jrtddS)NI/O operation on closed file.T)r8rrrrrreadableszZipExtFile.readablecCs$ |jrtd|dus|dkr.|j|jd}d|_d|_|js,|||j7}|jr!|S||j}|t|jkrG|j|j|}||_|S|t|j}|j|jd}d|_d|_|dkr|js||}|t|kr||_||_||d|7} |S||7}|t|8}|dkr|jrc|S)Nzread from closed file.rr/)r8rr%r&r$_read1MAX_Nr2)rrbufendrZrrrr@s@     zZipExtFile.readcCsD|jdurdSt||j|_|jr|j|jkr td|jdSdS)NzBad CRC-32 for file %r)r*rr+r$rr))rnewdatarrr _update_crcs zZipExtFile._update_crccCs |dus |dkr.|j|jd}d|_d|_|js,||j}|r)||7} |S|jr|S||j}|t|jkrG|j|j|}||_|S|t|j}|j|jd}d|_d|_|dkr|js||}|t|kr||_||_||d|7} |S|r||7} |S|jrc|SNrr/)r%r&r$rDrEr2)rrrFrZrGrrrread1sJ     zZipExtFile.read1cCs |js|dkr dS|jtkr$|jj}|t|kr#|||t|7}n||}|jtkr5|jdk|_n<|jtkrat ||j }|j ||}|jj pT|jdkoT|jj |_|jr`||j 7}n|j |}|jj po|jdk|_|d|j}|jt|8_|jdkrd|_|||S)Nrr/T)r$r rr#Zunconsumed_tailr2_read2rr!rc MIN_READ_SIZErrrr"rIrrrrrDs8          zZipExtFile._read1cCsd|jdkrdSt||j}t||j}|j|}|jt|8_|s&t|jdur0||}|SrJ) r!rcrMminrr@r2EOFErrorr2rrrrrLs      zZipExtFile._read2cs>z|jr|jWtdSWtdStwr)rrr superrrrrr s  zZipExtFile.closecCs|jrtd|jSNrB)r8rr,rrrrr&szZipExtFile.seekablercCsJ|jrtd|jstd|}|dkr|}n|dkr#||}n|dkr-|j|}ntd||jkr9|j}|dkr?d}||}||j}|dkrY|t|j krY||_d}n1|dkr|j |j |j |_|j|_|j|_d|_ d|_t|j|_d|_|}|jdur||dkrt|j|}||||8}|dks|S) Nzseek on closed file.!underlying stream is not seekablerrr zCwhence must be os.SEEK_SET (0), os.SEEK_CUR (1), or os.SEEK_END (2)r/F)r8rr,r;UnsupportedOperationr^r/r&r2r%rrGr-r0r+r.r!r"rr r#r$r2r3rN MAX_SEEK_READr@)rrXrZcurr_posZnew_posZ read_offsetZ buff_offsetZread_lenrrrrG+sN         zZipExtFile.seekcCs>|jrtd|jstd|j|jt|j|j }|S)Nztell on closed file.rS) r8rr,r;rTr/r"r2r%r&)rZfileposrrrr^]s  zZipExtFile.tell)NFrrr)rrrrErMrUrr3rr=rArCr@rIrKrDrLr rrGr^ __classcell__rrrQrrs, 3   # %$  2rcs@eZdZddZeddZddZddZfd d ZZ S) _ZipWriteFilecCs8||_||_||_t|j|j|_d|_d|_d|_ dSr) _zinfo_zip64_zipfilerrirj _compressor _file_size_compress_size_crc)rzfrrrrrrgs z_ZipWriteFile.__init__cCs|jjSr)r[r>rrrrrqsz_ZipWriteFile._fileobjcCsdS)NTrrrrrwritableuz_ZipWriteFile.writablecCs|jrtdt|ttfrt|}nt|}|j}|j|7_t ||j |_ |j r:|j |}|j t|7_ |j||SrR)r8rrrrr2 memoryviewnbytesr]rr_r\rr^rr)rrZrdrrrrxs   z_ZipWriteFile.writec sf|jrdSzt|jr(|j}|jt|7_|j||j|j _ n|j |j _ |j |j _ |j |j _|j jd@r_|jrBdnd}|jt|t|j j |j j |j j|j|j_n7|jst|j tkrktd|jtkrttd|j|j_|j|j j|j|j |j|j|jj|jj|j |j |jj|j j<Wd|j_ dSd|j_ w)Nrzd$d%Zd?d&d'Zd@d(d)Zed*d+Zd,d-Zd.d/Z  d@d0d1Z d?d2d3Zd4d5Zd6d7Z d8d9Z!d:d;Z"dS)Ar NrTrc CsB |dvr tdt|||_d|_d|_i|_g|_||_||_||_ d|_ d|_ ||_ t |tjr9t|}t |trqd|_||_dddd dd d d }||} z t|||_Wntyn||vrm||}YqRw n d|_||_t|dd|_d|_t|_d |_d|_z|dkr|WdS|dvrd |_z|j |_!Wnt"tfyt#|j|_d|_!d|_YWdSwz |j$|j!WWdSt"tfyd|_YWdSw|dkrz||j$|j!WWdSt%y |j$ddd |_|j |_!YWdSwtd|j} d|_|&| )N)rjwxaz+ZipFile requires mode 'r', 'w', 'x', or 'a'Frr/rAw+bx+br+bwbZxb)rjrkrlrmrprnroTrr)rj)rkrlrmr z"Mode must be 'r', 'w', 'x', or 'a')'rr _allowZip64 _didModifydebugrhrgrrr(r_comment_strict_timestampsrr~rrstr _filePassedrDr;rCr>r<getattr _fileRefCnt threadingRLockrr,r_RealGetContentsr^rfr1rrGr_fpclose) rr r(r allowZip64rrZmodeDictrr>rrrrs         zZipFile.__init__cCs|Srrrrrr __enter__/rbzZipFile.__enter__cCs |dSrr )rtypevalue tracebackrrr__exit__2 zZipFile.__exit__cCsd|jj|jjfg}|jdur2|jr|d|jn |jdur)|d|j|d|jn|d|dd|S)Nr6z file=%rz filename=%rz mode=%rr7rr) rrrr>rxr3rDr(r4r9rrrr5s     zZipFile.__repr__c Cs |j}zt|}Wn tytdw|std|jdkr%t||t}|t}|t|_ |t ||}|jdkrJ||}td||||||_ |j dkrXtd| |j d| |}t|}d}||krT| t} t| tkrtdtt| } | ttkrtd|jdkrt| | | t} | d } | d @r| d } n| d } t| } | | t| _| | t| _| t| _| dd \ | _ | _!| _"| _#| _$| _%} }| _&| _'| _(| j"t)krt*d| j"d| dd\| _+| _,| _-| | _.|d?d|d ?d@|d@| d?| d ?d@| d@df| _/| 0| j|| _|j12| | |j3| j4<|t| t| t| t}|jdkrPtd|||ksp|j }t5|j1ddddD] }||_6|j}qadS)NzFile is not a zip filerr zgiven, inferred, offsetrz Bad offset for central directoryzTruncated central directoryz&Bad magic number for central directoryr#rrcp437rzzip file version %.1fr'r*r-r&rzrr(rtotalcSr r)rr)rrrrz*ZipFile._RealGetContents..T)keyreverse)7r>r;r<rrtprintrTrU _ECD_COMMENTrurVrfrGr@r;BytesIOsizeCentralDirr2rHr1structCentralDir _CD_SIGNATUREstringCentralDir_CD_FILENAME_LENGTHdecoder _CD_EXTRA_FIELD_LENGTHr5_CD_COMMENT_LENGTHrf_CD_LOCAL_HEADER_OFFSETrrr[rkrlrmrnrirsrtruMAX_EXTRACT_VERSIONrrorprqrvrhrrgr3rhrDsortedrw)rr>rYZsize_cdZ offset_cdconcatZinferredrZrcentdirrDflagsrltd end_offsetrrrrr}Cs                           /  zZipFile._RealGetContentscCs dd|jDS)NcSsg|]}|jqSrr).0rZrrr sz$ZipFile.namelist..rgrrrrnamelistszZipFile.namelistcC |jSrrrrrrinfolistszZipFile.infolistcCsN tdd|d|jD]}d|jdd}td|j||jf|dq dS)Nz%-46s %19s %12s)z File Namez Modified ZSize)r z%d-%02d-%02d %02d:%02d:%02dr$z %-46s %s %12d)rrgrhrDru)rr rdaterrrprintdirs zZipFile.printdirc Csz d}|jD]4}z$||jd}||r ||sWdn1s&wYWqty:|jYSwdS)Nirj)rgrCrDr@r)rZ chunk_sizerfrrrtestzips    zZipFile.testzipcCs& |j|}|durtd||S)Nz(There is no item named %r in the archive)rhrKeyError)rr)inforrrgetinfos zZipFile.getinfocCs: |rt|tstdt|j|r||_dSd|_dS)Npwd: expected bytes, got %s)rr TypeErrorrrr)rrrrr setpasswords   zZipFile.setpasswordcCrr)rurrrrrfszZipFile.commentcCs^t|tstdt|jt|tkr'ddl}|jdtdd|dt}||_ d|_ dS)Nzcomment: expected bytes, got %srz3Archive comment is too long; truncating to %d bytesr  stacklevelT) rrrrrr2ZIP_MAX_COMMENTwarningswarnrurs)rrfrrrrrfs    cCs< ||d| }|WdS1swYdSNrjrCr@)rr)rr>rrrr@s$z ZipFile.readF force_zip64c s, |dvr td|rt|tstdt|j|r#|dkr#tdjs*tdt|tr2|}n|dkrCt|}j|_ j |_ n |}|dkrSj ||dSjrZtdjd 7_tj|jjjfd d }z|t}t|tkrtd tt|}|ttkrtd ||t}|tr||t|jd@rt d|jd@rt d|t!d@r|"d} n|"d} | |j#krtd|j#|f|j$dur|%|j&|j$krtd|j#d|jd @} | r|sj'}|st(d|nd}t)||||dWS|*)N>rjrkzopen() requires mode "r" or "w"rrkz'pwd is only supported for reading filesz2Attempt to use ZIP archive that was already closedrrrcsjSr)rrrrrrrzZipFile.open..zTruncated file headerz Bad magic number for file header z$compressed patched data (flag bit 5)@zstrong encryption (flag bit 6)rrrz/File name in directory %r and header %r differ.zOverlapped entries: z (possible zip bomb)z6File %r is encrypted, password required for extractionT)+rrrrrrr>r rrirrjr_open_to_writerrzrrrr~rr@sizeFileHeaderr2rrHr1r _FH_SIGNATUREr_FH_FILENAME_LENGTH_FH_EXTRA_FIELD_LENGTHrnr_FH_GENERAL_PURPOSE_FLAG_BITSrrgrwr^rtrrrr ) rr)r(rrrZzef_fileZfheaderfnameZ fname_strZ is_encryptedrrrrCs                 z ZipFile.opencCs|r |js td|jrtdd|_d|_d|_|jtkr%|jdO_|js/|jdO_|j s5d|_ |jo@|p@|j dt k}|jrK|j |j|j |_||d|_|j ||d|_t|||S) NzHforce_zip64 is True, but allowZip64 was False when opening the ZIP file.zzCan't write to the ZIP file while there is another write handle open on it. Close the first handle before opening another.rr rg?T)rrrrrtrsrnrirr,rqrurr>rGrfr^rr _writecheckrsrrrX)rrrrrrrrDs4     zZipFile._open_to_writecCs, |dur t}nt|}||||Sr)r~getcwdr_extract_member)rmemberrrrrrextractms   zZipFile.extractcCsJ |dur |}|durt}nt|}|D] }||||qdSr)rr~rrr)rrmembersrr4rrr extractallzs  zZipFile.extractallcCs` |j}|sd}t|dt|}||_||}dd||D}|dd|D}|S)Nz:<>|"?*_css|]}|dVqdS).N)rstriprrlrrr z1ZipFile._sanitize_windows_name..css|]}|r|VqdSrrrrrrrs)!_windows_illegal_name_trans_tablerw maketransr2 translatesplitr4)rrpathseptableZillegalrrr_sanitize_windows_names zZipFile._sanitize_windows_namec s t|ts ||}|jdtjj}tjjr"|tjjtjj}tj |d}dtjj tjj ftjj fdd| tjjD}tjjdkrT||tjj}tj ||}tj|}tj|}|rttj|stt||rtj|st||S|j||d,}t|d}t||Wdn1swYWd|SWd|S1swY|S) Nr{rrc3s|] }|vr|VqdSrrrZinvalid_path_partsrrrs z*ZipFile._extract_member..\rrq)rr rrDrr~rrrrcurdirpardirr4rrrdirnameexistsmakedirsrrmkdirrCshutil copyfileobj)rrZ targetpathrrZ upperdirssourcetargetrrrrs>  &      ( zZipFile._extract_membercCs |j|jvrddl}|jd|jdd|jdvrtd|js%tdt|j|j sPd}t |j t kr9d}n|j tkrAd }n|jtkrHd }|rRt|d dSdS) NrzDuplicate name: %rr!rrkrlrmz&write() requires mode 'w', 'x', or 'a'z4Attempt to write ZIP archive that was already closed Files countZFilesizez Zipfile size would require ZIP64 extensions)rDrhrrr(rr>rrirrr2rgZIP_FILECOUNT_LIMITrurrrr )rrrrequires_zip64rrrrs2     zZipFile._writecheckc Cs |jstd|jrtdtj|||jd}|r#d|_d|_n|dur+||_ n|j |_ |dur7||_ n|j |_ |r|j H|jrM|j|j|j|_|j tkr_|jdO_||d|_|j|||j|j<|j|d|j|_WddS1swYdSt|d.}||d }t||d Wdn1swYWddSWddS1swYdS) N7Attempt to write to ZIP archive that was already closedz>Can't write to ZIP archive while an open writing handle existsrrr TFrArki ) r>rrr rrvrrtrsrirrjrrr,rGrfr^rrrrnrrsrgr3rhrDrrrCrr)rrDrrirrsrcdestrrrrsL     "Pz ZipFile.writec Cs4 t|tr |d}t|ts=t|ttddd}|j|_|j|_ |j ddkr9d|_ |j dO_ nd|_ n|}|j sFt d |jrMt d |durT||_|dur[||_ t||_|j-|j|d d  }||Wdn1s{wYWddSWddS1swYdS) Nrr$)rDrhrr{iAr+rrz?Can't write to ZIP archive while an open writing handle exists.rk)r()rrwrr rrrrirrjrDrqr>rrr2rurrCr)rZzinfo_or_arcnamerZrirrrrrrwritestr sD     "zZipFile.writestrcCs |dSrrrrrr__del__5s zZipFile.__del__c Cs |jdurdS|jrtdza|jdvrG|jrU|j|jr&|j|j| Wdn21s4wYW|j}d|_| |dSW|j}d|_| |dSW|j}d|_| |dSW|j}d|_| |dS|j}d|_| |w)NzvCan't close the ZIP file while there is an open writing handle on it. Close the writing handle before closing the zip.r) r>rrr(rsrr,rGrf_write_end_recordr~rrrrr 9s<   z ZipFile.closecCs|jD]}|j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}g}|jtks8|jtkrI||j||jd }d }n|j}|j}|jtkr]||jd }n|j}|j} d} |rt| d } t j d d t |ddt |g|R| } t } |j tkrtt| } n |j tkrtt| } t| |j} t| |j} |\} }t tt| |j| |j||j |||j||t | t | t |jd|j|j|}|j||j| |j| |j|jq|j }t |j}||j!}|j!}d}|t"krd}n|tkrd}n|tkrd}|rX|j#s#t$|dt t%t&t'ddddd|||| }|j|t t(t)d|d}|j|t*|d}t*|d }t*|d }t t+t,dd||||t |j- }|j||j|j-|j.dkr|j/|j0dS)Nrrzr&rr#r r!r(r"rrVr.QrrzCentral directory offsetzCentral directory sizerrrrrm)1rgrhrurrtr3rrr5r:rHrr2rrirrcrrrrlr[rrrrkrmrsrfrprqr>rr^rfrrrr rNrMrKrIrJrNrar`rur(truncater)rrrrrr5rurtrrZ extra_datarrlr[rDrnrZpos2Z centDirCountZ centDirSizeZ centDirOffsetrZ zip64endrecZ zip64locrecrYrrrrOs $$                                    zZipFile._write_end_recordcCs.|jd8_|js|js|dSdSdSNr)rzrxr rrrrr~s  zZipFile._fpcloser)rjN)F)NN)NNN)#rrrr>rrrrrrr}rrrrrrrirfsetterr@rCrrrrrrrrrrr rr~rrrrr sR ZS        f )  * 2 ) ^r c@s2eZdZ deddfddZd dd Zd d ZdS) r rjTrcCstj|||||d||_dS)N)r(rr)r r _optimize)rr r(rroptimizerrrrs  zPyZipFile.__init__rNcCs t|}|r#||s#|jr!tj|rdnd}td||fdStj|\}}tj|r.tj|d}tj|r|rHd||f}n|}|jrTtd|d|| |dd |\}} |jrhtd | | || t t |} | d| D]Y} tj|| } tj| \} }tj| rtjtj| dr|j| ||d q||d kr|r|| s|jrtd | q|| | dd |\}} |jrtd | | || q|dS|jrtd|t t |D]D} tj|| } tj| \} }|d kr+|r|| s|jrtd | q| | dd |\}} |jr%td | | || qdS|d dd kr;td| |dd |\}} |jrPtd| | || dS)Nrr z%s %r skipped by filterfuncz __init__.py%s/%szAdding package inasrZAdding) filterfunc.pyzfile %r skipped by filterfunczAdding files from directoryz.Files added with writepy() must end with ".py"z Adding file)r~rrtrrrrr4isfile _get_codenamerrlistdirremovesplitextwritepyr)rpathnamebasenamerZlabeldirr)ZinitnamerrZdirlistrDrrootZextrrrrs                zPyZipFile.writepyc s dfdd }|d}|d}tjj|dd}tjj|dd}tjj|d d}jdkrtj|rDt|jt|jkrD|} } ntj|r[t|jt|jkr[|} |} ntj|rrt|jt|jkrr|} |} nztj|rt|jt|jkr|} |} nc||rt j j d kr|} n t j j dkr|} n|} |} nH|} } nCjd kr|} |} n|} jdkr|} njd kr|} n d j} t | tj| rt| jt|jks||jd s|} } tj| d} |rd || f} | | fS)Nrc sbddl}jr td|z |j|d|dWdS|jy0}z t|jWYd}~dSd}~ww)NrZ CompilingT)doraiserF) py_compilertrcompilePyCompileErrormsg)r rrerrrrr_compiles  z)PyZipFile._get_codename.._compilerz.pycr) optimizationrr rz"invalid value for 'optimize': {!r})rrr) importlibutilcache_from_sourcerr~rrrrrrrformatrr) rrrr Zfile_pyZfile_pycZ pycache_opt0Z pycache_opt1Z pycache_opt2rrr Z archivenamerrrrsb                zPyZipFile._get_codename)rN)rrrrrrrrrrrr s  Rr cCs tt|ddSr) itertoolsislice _ancestry)rrrr_parentsbsrccsD |tj}|tjr |Vt|\}}|tjsdSdSr)r posixpathrr)rtailrrrrus  rcCs tt|j|Sr)r filterfalseset __contains__)ZminuendZ subtrahendrrr _differencesrcsReZdZ eddZfddZddZddZfd d Ze d d Z Z S) CompleteDirscCs.tjtt|}dd|D}tt||S)Ncss|]}|tjVqdSr)rr)rrrrrrrz-CompleteDirs._implied_dirs..)rchain from_iterablerr_deduper)namesparentsZas_dirsrrr _implied_dirsszCompleteDirs._implied_dirscs tt|}|t||Sr)rPrrrbr!)rrrQrrrszCompleteDirs.namelistcCs t|Sr)rrrrrr _name_setrzCompleteDirs._name_setcCs. |}|d}||vo||v}|r|S|SNr{)r")rr)rrZ dir_matchrrr resolve_dirs  zCompleteDirs.resolve_dircsF zt|WSty"|dr||vrt|dYSw)Nr{r)rPrrendswithr"r )rr)rQrrrs zCompleteDirs.getinfocCs: t|tr|St|ts||Sd|jvrt}||_|Sr)rrr r(r)rrrrrmakes   zCompleteDirs.make) rrr staticmethodr!rr"r$rrr&rWrrrQrrs    rcs*eZdZ fddZfddZZS) FastLookupcFtt |jWdS1swYtt||_|jSr) contextlibsuppressr1Z_FastLookup__namesrPr(rrrQrrr  zFastLookup.namelistcr)r)r*r+r1Z_FastLookup__lookuprPr(r"rrQrrr"r,zFastLookup._name_set)rrrrr"rWrrrQrr(s r(cOst|d||fS)Nr!)r; text_encoding)encodingargskwargsrrr_extract_text_encodingsr1c@seZdZ dZd&ddZd'dddd Zed d Zed d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#ZeZed$d%ZdS)(rz>{self.__class__.__name__}({self.root.filename!r}, {self.at!r})rcCs t||_||_dSr)r(r&rat)rrr2rrrr@ s z Path.__init__rjNrcOs |r t||d}|s|dkrt||jj|j||d}d|vr1|s+|r/td|St|i|\}}}t j ||g|Ri|S)Nrrjrbz*encoding args invalid for binary operation) rIsADirectoryErrorrFileNotFoundErrorrrCr2rr1r; TextIOWrapper)rr(rr/r0Zzip_modestreamr.rrrrCM sz Path.opencCst|jjp |jjSr)pathlibZ PurePosixPathr2r)rDrrrrr)a z Path.namecCst|jj|jSr)r8rrrDjoinpathr2rrrrrDe r9z Path.filenamecOsZt|i|\}}}|jd|g|Ri| }|WdS1s&wYdSr)r1rCr@)rr/r0r.strmrrr read_texti s$zPath.read_textcCs6|d }|WdS1swYdS)NrAr)rr;rrr read_bytesn s $zPath.read_bytescCst|jd|jdkSr#)rrr2r)rrrrr _is_childr szPath._is_childcCs||j|Sr)rr)rr2rrr_nextu rz Path._nextcCs|j p |jdSr#)r2r%rrrrrx sz Path.is_dircCs|o| Sr)rrrrrris_file{ z Path.is_filecCs|j|jvSr)r2rr"rrrrr~ sz Path.existscCs.|stdt|j|j}t|j|S)NzCan't listdir a file)rrrr?rrfilterr>)rZsubsrrriterdir s z Path.iterdircCst|jj|jSr)rr4rrDr2rrrr__str__ rAz Path.__str__cCs|jj|dS)Nr) _Path__reprrrrrrr rz Path.__repr__cGs&tj|jg|R}||j|Sr)rr4r2r?rr$)rothernextrrrr: sz Path.joinpathcCs6|js|jjSt|jd}|r|d7}||Sr#)r2rDparentrrrr?)rZ parent_atrrrrH s  z Path.parent)r)rj)rrrrErrCrir)rDr<r=r>r?rr@rrCrDrr: __truediv__rHrrrrrs.M    rc s ddl}d}|j|d}|jdd}|jdddd d |jd d d ddd|jdddddd|jddddd ||}|jdurm|j}t|d }|}Wdn1sYwY|rgtd |tddS|j dur|j }t|d }| WddS1swYdS|j dur|j \}}t|d}| |WddS1swYdS|jdur|jd} |j} fddt| d1}| D]%} tj| } | stjtj| } | dtjtjfvrd} || | qWddS1swYdSdS) Nrz3A simple command-line interface for zipfile module.) descriptionT)Zrequiredz-lz--list zShow listing of a zipfile)metavarhelpz-ez --extractr )rKz zExtract zipfile into target dir)nargsrLrMz-cz--create+)zzzCreate zipfile from sourcesz-tz--testzTest if a zipfile is validrjz.The following enclosed file is corrupted: {!r}z Done testingcsvtj|r|||tdStj|r7|r|||tt|D]}|tj||tj||q$dSdSr) r~rrrrrrrr4)r`rzippathZnmaddToZiprrrR s   zmain..addToZiprkr)argparseArgumentParserZadd_mutually_exclusive_group add_argument parse_argstestr rrrrbrrrZcreatepopr~rrrrr) r/rSrJparsergrouprr`ZbadfilerZzip_namefilesrrPrrQrmain sh              "    "     $r\__main__r)Zbinasciiimportlib.utilr r;rr~rrerrrHrr{rr*r8rr ImportErrorrr__all__ Exceptionrr rrrrrrrrrrrrrrrar`rr_rOrPrQrRrSrTrUrerrVrrrrZ_CD_CREATE_VERSIONZ_CD_CREATE_SYSTEMZ_CD_EXTRACT_VERSIONZ_CD_EXTRACT_SYSTEMZ _CD_FLAG_BITSZ_CD_COMPRESS_TYPEZ_CD_TIMEZ_CD_DATEZ_CD_CRCZ_CD_COMPRESSED_SIZEZ_CD_UNCOMPRESSED_SIZErrrZ_CD_DISK_NUMBER_STARTZ_CD_INTERNAL_FILE_ATTRIBUTESZ_CD_EXTERNAL_FILE_ATTRIBUTESrrrrrZ_FH_EXTRACT_VERSIONZ_FH_EXTRACT_SYSTEMrZ_FH_COMPRESSION_METHODZ_FH_LAST_MOD_TIMEZ_FH_LAST_MOD_DATEZ_FH_CRCZ_FH_COMPRESSED_SIZEZ_FH_UNCOMPRESSED_SIZErrrIrJrFrNrMrKZ_CD64_SIGNATUREZ_CD64_DIRECTORY_RECSIZEZ_CD64_CREATE_VERSIONZ_CD64_EXTRACT_VERSIONZ_CD64_DISK_NUMBERZ_CD64_DISK_NUMBER_STARTZ_CD64_NUMBER_ENTRIES_THIS_DISKZ_CD64_NUMBER_ENTRIES_TOTALZ_CD64_DIRECTORY_SIZEZ_CD64_OFFSET_START_CENTDIRreZStructr0r:r?r r\r;objectr rrrrrrrrrrrr<rrXr r rrdictfromkeysrrrr(r1rr\rrrrrs              <<^&      (KU~/<  . =