a �DOg�X�@s�dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZzddlZejZWney�dZejZYn0z ddlZWney�dZYn0z ddlZWney�dZYn0gd�ZGdd�de�ZGdd�de�ZeZZdZd Zd ZdZd Zd Zd Z d Z!dZ"dZ#dZ$dZ%dZ&dZ'e �(e&�Z)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1d Z2dZ3dZ4dZ5e �(e4�Z6dZ7dZ8dZ9dZ:dZ;dZd Z?dZ@dZAdZBd ZCdZDd ZEd ZFd!ZGd"ZHd#ZId$ZJd%ZKe �(eJ�ZLdZMdZNdZOdZPdZQdZRdZSdZTd ZUdZVdZWdZXd&ZYd'ZZe �(eY�Z[d(Z\d)Z]e �(e\�Z^dZ_dZ`dZadZbdZcdZddZedZfd ZgdZhd*Zie �jd+�Zkd,d-�Zld.d/�Zmd0d1�Znd2d3�Zod4d5�ZpGd6d7�d7eq�Zrdasd8d9�Ztd:d;�ZuGdd?�d?�Zwd@dAdBdBdBdBdCdDdEdFdCdGdHdIdJdKdLdM�ZxdNdO�ZydodPdQ�ZzdRdS�Z{GdTdU�dU�Z|GdVdW�dW�Z}GdXdY�dYej~�ZGdZd[�d[ej~�Z�Gd\d]�d]�Z�Gd^d_�d_e��Z�d`da�Z�dbdc�Z�e�j�Z�ddde�Z�Gdfdg�dge��Z�Gdhdi�die��Z�Gdjdk�dk�Z�dpdldm�Z�e�dnk�r�e��dS)qzP Read and write ZIP files. XXX references to utf-8 need further investigation. �N) � BadZipFile� BadZipfile�error� ZIP_STORED� ZIP_DEFLATED� ZIP_BZIP2�ZIP_LZMA� is_zipfile�ZipInfo�ZipFile� PyZipFile� LargeZipFile�Pathc@s eZdZdS)rN)�__name__� __module__� __qualname__�rr�/usr/lib64/python3.9/zipfile.pyr*src@seZdZdZdS)r zu Raised when writing a zipfile, the zipfile requires ZIP64 extensions and those extensions are disabled. N)rrr�__doc__rrrrr .sr i�������� ���-�.�?s<4s4H2LHsPK�������� z<4s4B4HL2L5H2LsPK� � � ����z <4s2B4HL2L2HsPKz<4sLQLsPKz <4sQ2H2L4QsPKiPK�r0�structr/�structEndArchive64Locator�stringEndArchive64Locatorr�sizeEndCentDir64�structEndArchive64�stringEndArchive64�_ECD_SIGNATURE�_ECD_DISK_NUMBER�_ECD_DISK_START�_ECD_ENTRIES_THIS_DISK�_ECD_ENTRIES_TOTAL� _ECD_SIZE� _ECD_OFFSET)�fpin�offset�endrec�data�sigZdisknoZreloffZdisksZsz�create_versionZ read_versionZdisk_numZdisk_dirZdircountZ dircount2ZdirsizeZ diroffsetrrr� _EndRecData64�s:       �rYc Csf|�dd�|��}z|�t d�Wnty:YdS0|��}t|�tkr�|dd�tkr�|dd�dkr�t�t |�}t |�}|� d�|� |t�t |t |�St |dtd�}|�|d�|��}|�t�}|dk�rb|||t�}t|�tk�rdSt t�t |��}|t}||t|t|�}|� |�|� ||�t |||||�SdS) z�Return data from the "End of Central Directory" record, or None. The data is a list of the nine items in the ZIP "End of central dir" record followed by a tenth item, the file seek offset of this record.rrNr �����sr-i)rD�tell�sizeEndCentDirr:r>r0�stringEndArchiverFr/�structEndArchive�listr1rY�max�rfind�_ECD_COMMENT_SIZE) rSZfilesizerVrUZmaxCommentStartr5ZrecDataZ commentSize�commentrrrr9sD   ��      �r9c@s\eZdZdZdZddd�Zdd�Zdd d �Zd d �Zdd�Z e ddd�dd��Z dd�Z d S)r z>Class with attributes describing each file in the ZIP archive.)� orig_filenamerB� date_time� compress_type�_compresslevelrcr3� create_systemrX�extract_version�reserved� flag_bits�volume� internal_attr� external_attr� header_offset�CRC� compress_size� file_size� _raw_time� _end_offset�NoName��rrrrrcCs�||_|�td��}|dkr(|d|�}tjdkrJtj|vrJ|�tjd�}||_||_|ddkrjtd��t |_ d|_ d|_ d|_ tjdkr�d|_nd|_t|_t|_d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr�/rwz+ZIP does not support timestamps before 1980r-�win32r)rd�find�chr�os�sep�replacerBre� ValueErrorrrfrgrcr3�sys�platformrh�DEFAULT_VERSIONrXrirjrkrlrmrnrqrrrt)�selfrBreZ null_byterrr�__init__Xs6   zZipInfo.__init__cCs�d|jj|jfg}|jtkr8|�dt�|j|j��|jd?}|jd@}|rd|�dt � |��|rv|�d|�|� �}|r�|j r�|�d|j �|r�|j r�|jtks�|j |j kr�|�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__rrBrfrr1�compressor_names�getrn�stat�filemode�is_dirrrrqr2)r�rC�hi�lo�isdirrrr�__repr__�s0 ��    � � zZipInfo.__repr__NcCs||j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}|jd @rfd}}}n|j}|j}|j}|j}d} |d ur�|tkp�|tk}|r�d } |t�| dt� | �d ||�}|tks�|tkr�|s�t d ��d}d}t } |j t k�rtt| �} n|j tk�rtt| �} t| |j�|_t| |j�|_|��\} } t�tt|j|j| |j |||||t| �t|�� } | | |S)z-Return the per-file header as a bytes object.rrwr$rr!rrr&r rNz|_|r�d|_|jd O_n|j|_|S) a_Construct an appropriate ZipInfo for a file on the filesystem. filename should be the path to a file or directory on the filesystem. arcname is the name which it will have within the archive (by default, this will be the same as filename, but without a drive letter and with leading path separators removed). rr"rwrv�;)r�r���;r�Nrrxrr))� isinstancer|�PathLike�fspathr��S_ISDIR�st_mode�time� localtime�st_mtime�path�normpath� splitdriver}�altseprnrr�st_size) �clsrB�arcnamer��str��mtimere�zinforrr� from_file�s0       zZipInfo.from_filecCs|jddkS)z2Return True if this archive member is a directory.�����rx�rBr�rrrr�szZipInfo.is_dir)rurv)N)N) rrrr� __slots__r�r�r�r�r�� classmethodr�r�rrrrr =s , .%r cCs0td�D]"}|d@r"|d?dA}q|dL}q|S)Nrrl q[)�range)�crcr7rrr�_gen_crcs   r�csld�d�d�tdur&ttttd���at��fdd������fdd��|D] }�|�qL��fd d �}|S) NixV4i�gE#i�xV4�cs|d?�||Ad@AS)z(Compute the CRC32 primitive on one byte.r��r)Zchr�)�crctablerr�crc325sz_ZipDecrypter..crc32cs<�|�����d@d@��ddd@���d?���dS)Nr�r�i�r�r)�c)r��key0�key1�key2rr� update_keys9s z"_ZipDecrypter..update_keyscsNt�}|j}|D]4}�dB}|||dAd?d@N}�|�||�qt|�S)zDecrypt a bytes object.rrrr�)� bytearrayr1�bytes)rVrCr1r��k)r�r�rr� decrypterCs z _ZipDecrypter..decrypter)� _crctabler_�mapr�r�)�pwd�pr�r)r�r�r�r�r�r�r� _ZipDecrypter+s   r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) �LZMACompressorcCs d|_dS�N)�_compr�rrrr�SszLZMACompressor.__init__cCsFt�dtji�}tjtjt�tj|�gd�|_t�dddt |��|S)N�id��filterszr[�r��nrVrrrr>�s  z_SharedFile.readcCs$|jdur |j}d|_|�|�dSr�)r r )r��fileobjrrrr�s z_SharedFile.closeN)r)r�)rrrr�r[rDr>rrrrrr �s  r c@s4eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd S) � _TellablecCs||_d|_dS�Nr)r<rT�r�r<rrrr��sz_Tellable.__init__cCs|j�|�}|j|7_|Sr�)r<�writerT)r�rVrrrrr�s z_Tellable.writecCs|jSr�)rTr�rrrr[�sz_Tellable.tellcCs|j��dSr�)r<r�r�rrrr�sz_Tellable.flushcCs|j��dSr�)r<rr�rrrrsz_Tellable.closeN)rrrr�rr[r�rrrrrr�s rcs�eZdZdZdZdZdZd(dd�Zd d �Zd d �Z d)dd�Z d*dd�Z dd�Z d+dd�Z dd�Zdd�Zdd�Zdd�Z�fdd �Zd!d"�Zd,d$d%�Zd&d'�Z�ZS)-� ZipExtFilezZFile-like object for reading an archive member. Is returned by ZipFile.open(). i@iiNFcCs&||_||_||_|j|_|j|_|j|_t |j�|_ d|_ d|_ d|_ d|_||_|j|_t|d�rz|j|_td�|_nd|_d|_z4|��r�|��|_|j|_|j|_|j|_d|_Wnty�Yn0d|_|�r"|j d@r�|j!d?d@}n|jd?d@}|�"�}||k�r"t#d |j$��dS) NFr-rrpTrr�r�zBad password for file %r)%�_fileobj�_pwd�_close_fileobjrf�_compress_typerq�_compress_leftrr�_leftr� _decompressor�_eof� _readbuffer�_offset�newlines�moderB�namer@rp� _expected_crcr�� _running_crc� _seekablerr[�_orig_compress_start�_orig_compress_size�_orig_file_size�_orig_start_crc�AttributeError� _decrypterrkrs�_init_decrypterr�rd)r�rr*�zipinfor�Z close_fileobjZ check_byte�hrrrr�sF        zZipExtFile.__init__cCs4t|j�|_|j�d�}|jd8_|�|�dS)Nrr&)r�r r4rr>r#)r�r�rrrr5Js  zZipExtFile._init_decryptercCsvd|jj|jjfg}|jsX|�d|j|jf�|jtkrb|�dt � |j|j��n |�d�|�d�d� |�S)N�<%s.%sz name=%r mode=%rr�� [closed]r�r�) r�rr�closedr1r+r*r"rr�r�r2�r�rCrrrr�Us� ��  zZipExtFile.__repr__r�cCsL|dkr>|j�d|j�d}|dkr>|j|j|�}||_|Stj�||�S)zrRead and return a line from the stream. If limit is specified, at most limit bytes will be read. r� r)r'rzr(�io�BufferedIOBase�readline)r��limitr6�linerrrr?cszZipExtFile.readlinercCsr|t|j�|jkr\|�|�}t|�|jkrJ||j|jd�|_d|_n|jt|�8_|j|j|jd�S)z6Returns buffered bytes without advancing the position.Nri)r0r'r(r>)r�r�chunkrrr�peekss zZipExtFile.peekcCs|jrtd��dS)N�I/O operation on closed file.T)r:rr�rrr�readable�szZipExtFile.readablecCs|jrtd��|dus|dkrV|j|jd�}d|_d|_|jsR||�|j�7}q:|S||j}|t|j�kr�|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_|dk�r|j�s|�|�}|t|�kr�||_||_||d|�7}�q||7}|t|�8}q�|S)z�Read and return up to n bytes. If the argument is omitted, None, or negative, data is read and returned until EOF is reached. zread from closed file.Nrr-)r:rr'r(r&�_read1�MAX_Nr0)r�r�buf�endrVrrrr>�s8   zZipExtFile.readcCs@|jdurdSt||j�|_|jr<|j|jkr     zZipExtFile.read1cCs"|js|dkrdS|jtkrH|jj}|t|�krR||�|t|��7}n |�|�}|jtkrj|jdk|_nx|jtkr�t ||j �}|j� ||�}|jj p�|jdko�|jj |_|jr�||j� �7}n |j� |�}|jj p�|jdk|_|d|j�}|jt|�8_|jdk�rd|_|�|�|S)Nrr-T)r&r"rr%�unconsumed_tailr0�_read2rr#r`� MIN_READ_SIZEr�r�r�r$rKrrrrrF�s4       �   zZipExtFile._read1cCsd|jdkrdSt||j�}t||j�}|j�|�}|jt|�8_|sLt�|jdur`|�|�}|S)Nrr-) r#r`rO�minrr>r0�EOFErrorr4rrrrrN�s      zZipExtFile._read2cs0z|jr|j��Wt���n t���0dSr�)r!rr�superr��r�rrr s zZipExtFile.closecCs|jrtd��|jS�NrD)r:rr.r�rrrrszZipExtFile.seekablercCsL|jrtd��|jst�d��|��}|dkr4|}n.|dkrF||}n|dkrZ|j|}ntd��||jkrr|j}|dkr~d}||}||j}|dkr�|t|j �kr�||_d}nf|dk�r|j � |j �|j |_|j|_|j|_d|_ d|_t|j�|_d|_|}|jdu�r|��|dk�rDt|j|�}|�|�||8}�q|��S) Nzseek on closed file.�!underlying stream is not seekablerrrzCwhence must be os.SEEK_SET (0), os.SEEK_CUR (1), or os.SEEK_END (2)r-F)r:rr.r=�UnsupportedOperationr[r1r(r0r'rrDr/r2r-r0r#r$rr"r%r&r4r5rP� MAX_SEEK_READr>)r�rTrZcurr_posZnew_posZ read_offsetZ buff_offsetZread_lenrrrrDsL            zZipExtFile.seekcCs>|jrtd��|jst�d��|j|jt|j�|j }|S)Nztell on closed file.rU) r:rr.r=rVr1r$r0r'r()r�Zfileposrrrr[Is  zZipExtFile.tell)NF)r�)r)r�)r)rrrrrGrOrWr�r5r�r?rCrEr>rKrLrFrNrrrDr[� __classcell__rrrSrr s*� 3    # %$  2rcs@eZdZdd�Zedd��Zdd�Zdd�Z�fd d �Z�Z S) � _ZipWriteFilecCs8||_||_||_t|j|j�|_d|_d|_d|_ dSr) �_zinfo�_zip64�_zipfilerrfrg� _compressor� _file_size�_compress_size�_crc)r��zfr�r�rrrr�Ss�z_ZipWriteFile.__init__cCs|jjSr�)r\r<r�rrrr]sz_ZipWriteFile._fileobjcCsdS)NTrr�rrr�writableasz_ZipWriteFile.writablecCs�|jrtd��t|ttf�r&t|�}nt|�}|j}|j|7_t ||j �|_ |j rt|j � |�}|j t|�7_ |j�|�|SrT)r:rr�r�r�r0� memoryview�nbytesr^r�r`r]r�r_rr)r�rVrdrrrrds   z_ZipWriteFile.writec sj|jr dS�zNt���|jrR|j��}|jt|�7_|j�|�|j|j _ n |j |j _ |j |j _ |j |j _|j jd@r�|jr�dnd}|j�t�|t|j j |j j |j j��|j��|j_nn|js�|j tkr�td��|jtkr�td��|j��|j_|j�|j j�|j�|j �|j��|j�|jj�|jj�|j �|j |jj|j j<Wd|j_ n d|j_ 0dS)Nrzdd �Zd?d!d"�d#d$�Zd@d%d&�ZdAd'd(�ZdBd)d*�Zed+d,��Zd-d.�Zd/d0�ZdCd1d2�ZdDd3d4�Zd5d6�Z d7d8�Z!d9d:�Z"d;d<�Z#dS)Er ai Class with methods to open, read, write, close, list zip files. z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True, compresslevel=None) file: Either the path to the file, or a file-like object. If it is a path, the file will be opened and closed by ZipFile. mode: The mode can be either read 'r', write 'w', exclusive create 'x', or append 'a'. compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma). allowZip64: if True ZipFile will create files with ZIP64 extensions when needed, otherwise it will raise an exception when this would be necessary. compresslevel: None (default for the given compression type) or an integer specifying the level to pass to the compressor. When using ZIP_STORED or ZIP_LZMA this keyword has no effect. When using ZIP_DEFLATED integers 0 through 9 are accepted. When using ZIP_BZIP2 integers 1 through 9 are accepted. N�rTr�c CsH|dvrtd��t|�||_d|_d|_i|_g|_||_||_||_ d|_ d|_ ||_ t |tj�rpt�|�}t |t�r�d|_||_ddd d dd d d �}||}zt�||�|_Wq�ty�||vr�||}Yq��Yq�0q�q�nd|_||_t|dd�|_d|_t��|_d|_d|_�z|dk�r2|��n�|dv�r�d|_z|j� �|_!Wn0t"tf�y�t#|j�|_d|_!d|_Yn40z|j�$|j!�Wnt"tf�y�d|_Yn0nd|dk�rz|��|j�$|j!�Wn4t%�y|j�$dd�d|_|j� �|_!Yn0ntd��Wn$|j} d|_|�&| ��Yn0dS)z]Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.)rj�w�x�az+ZipFile requires mode 'r', 'w', 'x', or 'a'FrNr-r?�w+b�x+b�r+b�wb�xb)rjrkrlrmrprnrorr+Trj)rkrlrmrz"Mode must be 'r', 'w', 'x', or 'a')'rr�� _allowZip64� _didModify�debugrhrgr�rr*r��_comment�_strict_timestampsr�r|r�r��str� _filePassedrBr=rAr<r:�getattr� _fileRefCnt� threading�RLockr r.r�_RealGetContentsr[rfr3rrDr�_fpclose) r�rr*r�� allowZip64rr�ZmodeDictr�r<rrrr��s�   �          zZipFile.__init__cCs|Sr�rr�rrr� __enter__szZipFile.__enter__cCs |��dSr��r)r��type�value� tracebackrrr�__exit__szZipFile.__exit__cCs�d|jj|jjfg}|jdurd|jr8|�d|j�n|jdurR|�d|j�|�d|j�n |�d�|�d�d�|�S)Nr8z file=%rz filename=%rz mode=%rr9r�r�) r�rrr<ryr1rBr*r2r;rrrr�!s�    zZipFile.__repr__c Cs�|j}z t|�}Wnty,td��Yn0|s:td��|jdkrLt|�|t}|t}|t|_ |t ||}|t t kr�|t t8}|jdkr�||}td|||�|||_|�|jd�|�|�}t�|�}d}||k�r�|�t�} t| �tk�rtd��t�t| �} | ttk�r*td��|jdk�r>t| �|�| t�} | d} | d @�rj| �d �} n | �d �} t| �} |�| t�| _|�| t �| _!| t"| _#| dd �\ | _$| _%| _&| _'| _(| _)} }| _*| _+| _,| j&t-k�r�t.d | j&d��| dd�\| _/| _0| _1| | _2|d?d|d?d@|d@| d?| d?d@| d@df| _3| �4�| j#|| _#|j5�6| �| |j7| j8<|t| t| t| t }|jdkr�td|�q�|j}t9|j5dd�dd�D]}||_:|j#}�q�dS)z/Read in the table of contents for the ZIP file.zFile is not a zip filerrzgiven, inferred, offsetrzTruncated central directoryz&Bad magic number for central directoryr!r�r��cp437rzzip file version %.1fr%r(r+r$rwr�r&r�totalcSs|jSr�)ro)r�rrr�~r-z*ZipFile._RealGetContents..T)�key�reverseN);r<r9r:rru�printrQrR� _ECD_COMMENTrv� _ECD_LOCATIONrLrKrIrErfrDr>r=�BytesIO�sizeCentralDirr0rFr/�structCentralDir� _CD_SIGNATURE�stringCentralDir�_CD_FILENAME_LENGTH�decoder �_CD_EXTRA_FIELD_LENGTHr3�_CD_COMMENT_LENGTHrc�_CD_LOCAL_HEADER_OFFSETrorXrhrirjrkrfrprqrr�MAX_EXTRACT_VERSIONr�rlrmrnrsrer�rgr1rhrB�sortedrt)r�r<rUZsize_cdZ offset_cd�concatZinferredrVr��centdirrB�flagsrl�t�dZ end_offsetr�rrrr~/s�                   �   ��   ��  � zZipFile._RealGetContentscCsdd�|jD�S)z+Return a list of file names in the archive.cSsg|] }|j�qSrr�)�.0rVrrr� �r-z$ZipFile.namelist..�rgr�rrr�namelist�szZipFile.namelistcCs|jS)zJReturn a list of class ZipInfo instances for files in the archive.r�r�rrr�infolist�szZipFile.infolistcCsLtdd|d�|jD]0}d|jdd�}td|j||jf|d�qdS)z+Print a table of contents for the zip file.z%-46s %19s %12s)z File Namez Modified ZSize)rz%d-%02d-%02d %02d:%02d:%02dNr"z %-46s %s %12d)r�rgrerBrr)r�rr��daterrr�printdir�s� �zZipFile.printdirc Cspd}|jD]`}z>|�|jd��}|�|�r,q Wd�n1s@0YWq tyh|jYS0q dS)z%Read all the files and check the CRC.irjN)rgrArBr>r)r�Z chunk_sizer��frrr�testzip�s  $ zZipFile.testzipcCs$|j�|�}|dur td|��|S)z,Return the instance of ZipInfo given 'name'.Nz(There is no item named %r in the archive)rhr��KeyError)r�r+�inforrr�getinfo�s  �zZipFile.getinfocCs6|r t|t�s tdt|�j��|r,||_nd|_dS)z)Set default password for encrypted files.�pwd: expected bytes, got %sN)r�r�� TypeErrorr�rr�)r�r�rrr� setpassword�s zZipFile.setpasswordcCs|jS)z.The comment text associated with the ZIP file.)rvr�rrrrc�szZipFile.commentcCs^t|t�stdt|�j��t|�tkrNddl}|jdtdd�|dt�}||_ d|_ dS)Nzcomment: expected bytes, got %srz3Archive comment is too long; truncating to %d bytesr�� stacklevelT) r�r�r�r�rr0�ZIP_MAX_COMMENT�warnings�warnrvrt)r�rcr�rrrrc�s  �� cCs:|�|d|��}|��Wd�S1s,0YdS)zReturn file bytes for name.rjN�rAr>)r�r+r�r<rrrr>�sz ZipFile.readF�� force_zip64c sJ|dvrtd��|r0t|t�s0tdt|�j��|rD|dkrDtd���jsRtd��t|t�rb|}n,|dkr�t|�}�j|_ �j |_ n �� |�}|dkr��j ||d�S�jr�td���jd 7_t�j|j�j�j�fd d ��}�zL|�t�}t|�tk�rtd ��t�t|�}|ttk�r&td ��|�|t�}|t�rL|�|t�|jd@�r`t d��|jd@�rtt d��|t!d@�r�|�"d�} n |�"d�} | |j#k�r�td|j#|f��|j$du�r�|�%�|j&|j$k�r�td|j#�d���|jd @} | �r|�s�j'}|�st(d|��nd}t)||||d�WS|�*��Yn0dS)auReturn file-like object for 'name'. name is a string for the file name within the ZIP file, or a ZipInfo object. mode should be 'r' to read a file already in the ZIP file, or 'w' to write to a file newly added to the archive. pwd is the password to decrypt files (only used for reading). When writing, if the file size is not known in advance but may exceed 2 GiB, pass force_zip64 to use the ZIP64 format, which can handle large files. If the size is known in advance, it is best to pass a ZipInfo instance for name, with zinfo.file_size set. >rkrjzopen() requires mode "r" or "w"r�rkz'pwd is only supported for reading filesz2Attempt to use ZIP archive that was already closedr�rrcs�jSr�)rrr�rrr��r-zZipFile.open..zTruncated file headerz Bad magic number for file header� z$compressed patched data (flag bit 5)�@zstrong encryption (flag bit 6)r�r�r�z/File name in directory %r and header %r differ.NzOverlapped entries: z (possible zip bomb)z6File %r is encrypted, password required for extractionT)+rr�r�r�r�rr<r r�rfrrgr��_open_to_writerr{r rorr r>�sizeFileHeaderr0rrFr/r�� _FH_SIGNATUREr��_FH_FILENAME_LENGTH�_FH_EXTRA_FIELD_LENGTHrkr��_FH_GENERAL_PURPOSE_FLAG_BITSr�rdrtr[rqr�r�rr) r�r+r*r�r�r�Zzef_fileZfheader�fnameZ fname_strZ is_encryptedrr�rrA�s� �    �        �� � �z ZipFile.opencCs�|r|jstd��|jr td��d|_d|_d|_|jtkrJ|jdO_|js^|jdO_|j sjd|_ |jo�|p�|j dt k}|jr�|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.rrr��g�������?T)rsrrrqrprkrfrr.rnrrr�r<rDrfr[ro� _writecheckrtrr�rY)r�r�r�r�rrrr�1s4 � �  zZipFile._open_to_writecCs*|durt��}n t�|�}|�|||�S)a#Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using `path'. N)r|�getcwdr��_extract_member)r��memberr�r�rrr�extractZs  zZipFile.extractcCsH|dur|��}|dur"t��}n t�|�}|D]}|�|||�q0dS)z�Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist(). N)r�r|r�r�r�)r�r��membersr�r6rrr� extractallgs  zZipFile.extractallcCs^|j}|s(d}t�|dt|��}||_|�|�}dd�|�|�D�}|�dd�|D��}|S)z;Replace bad characters and remove trailing dots from parts.z:<>|"?*�_css|]}|�d�VqdS)�.N)�rstrip�r�rlrrr� �r-z1ZipFile._sanitize_windows_name..css|]}|r|VqdSr�rr�rrrr��r-)�!_windows_illegal_name_trans_tablerx� maketransr0� translate�splitr2)r�r��pathsep�tableZillegalrrr�_sanitize_windows_namexs zZipFile._sanitize_windows_namec sxt|t�s|�|�}|j�dtjj�}tjjrB|�tjjtjj�}tj� |�d}dtjj tjj f�tjj� �fdd�|� tjj�D��}tjjdkr�|�|tjj�}tj� ||�}tj�|�}tj�|�}|r�tj�|�s�t�|�|���r tj�|��st�|�|S|j||d��H}t|d��}t�||�Wd �n1�sJ0YWd �n1�sj0Y|S) zbExtract the ZipInfo object 'member' to a physical file on the path targetpath. rxrr�c3s|]}|�vr|VqdSr�rr��Zinvalid_path_partsrrr��s�z*ZipFile._extract_member..�\�r�rqN)r�r r�rBr~r|r�r}r�r��curdir�pardirr2r�r�r��dirname�exists�makedirsr�r��mkdirrA�shutil� copyfileobj)r�r�� targetpathr�r�Z upperdirs�source�targetrr�rr��s2  &      �LzZipFile._extract_membercCs�|j|jvr(ddl}|jd|jdd�|jdvr:td��|jsHtd��t|j�|j s�d}t |j �t krpd }n|j tkr�d }n|jtkr�d }|r�t|d ��dS) z6Check for errors before writing a file to the archive.rNzDuplicate name: %rrr��rkrlrmz&write() requires mode 'w', 'x', or 'a'z4Attempt to write ZIP archive that was already closed� Files countZFilesizez Zipfile size� would require ZIP64 extensions)rBrhr�r�r*rr<r�rfrsr0rg�ZIP_FILECOUNT_LIMITrrr�ror )r�r�r��requires_zip64rrrr��s,  �   �zZipFile._writecheckc Cs�|jstd��|jrtd��tj|||jd�}|��rDd|_d|_n0|durT||_ n|j |_ |durl||_ n|j |_ |���r&|j ��|jr�|j�|j�|j��|_|j tkr�|jdO_|�|�d|_|j�|�||j|j<|j�|�d��|j��|_Wd�n1�s0Ynht|d ��L}|�|d ��}t�||d �Wd�n1�sd0YWd�n1�s�0YdS) zLPut the bytes from filename into the archive under the name arcname.�7Attempt to write to ZIP archive that was already closedz>Can't write to ZIP archive while an open writing handle existsr�rNrTFr?rki ) r<rrr r�rwr�rqrprfr�rgrr r.rDrfr[rorrkr�rtrgr1rhrBrr�rAr�r�)r�rBr�rfrr��src�destrrrr�sF���      .z ZipFile.writec Cs"t|t�r|�d�}t|t�sxt|t�t���dd�d�}|j|_|j|_ |j ddkrpd|_ |j dO_ q|d |_ n|}|j s�t d ��|jr�t d ��|dur�||_|dur�||_ t|�|_|j�H|j|d d ��}|�|�Wd�n1s�0YWd�n1�s0YdS)aWrite a file into the archive. The contents is 'data', which may be either a 'str' or a 'bytes' instance; if it is a 'str', it is encoded as UTF-8 first. 'zinfo_or_arcname' is either a ZipInfo instance or the name of the file in the archive.r�Nr")rBrer�rxi�Ar)r�r�z?Can't write to ZIP archive while an open writing handle exists.rk)r*)r�rxr�r r�r�r�rfrrgrBrnr<rrr0rrr rAr)r�Zzinfo_or_arcnamerVrfrr�r�rrr�writestr�s:   ��� zZipFile.writestrcCs |��dS)z2Call the "close()" method in case the user forgot.Nr�r�rrr�__del__"szZipFile.__del__c Cs�|jdurdS|jrtd��zl|jdvrp|jrp|j�,|jrJ|j�|j�|� �Wd�n1sf0YW|j}d|_|� |�n|j}d|_|� |�0dS)zOClose the file, and for mode 'w', 'x' and 'a' write the ending records.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*rtr r.rDrf�_write_end_recordrrrrrr&s  ( �z ZipFile.closecCs|jD�]�}|j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}g}|jtksr|jtkr�|�|j�|�|j�d }d }n |j}|j}|jtkr�|�|j�d }n|j}|j} d} |�rt| d �} t j d d t |�ddt |�g|�R�| } t } |j tk�r&tt| �} n|j tk�rrAr�r�r�r�r�r�r�rr�r�rr�rrrrrr �sP�� ZT      f )  *� 2� )^r c@s4eZdZdZdeddfdd�Zd d d �Zd d �ZdS)r zDClass to create ZIP archives with Python library files and packages.rjTr�cCstj|||||d�||_dS)N)r*r�r�)r r�� _optimize)r�rr*r�r��optimizerrrr��s �zPyZipFile.__init__r�NcCs�t�|�}|rD||�sD|jr@tj�|�r,dnd}td||f�dStj�|�\}}tj�|��rhtj�|d�}tj�|��r�|r�d||f}n|}|jr�td|d|�|� |d d �|�\}} |jr�td | �|� || �t t� |��} | � d�| D]�} tj�|| �} tj�| �\} }tj�| ��rRtj�tj�| d���r�|j| ||d �q�|d kr�|�r~|| ��s~|jr�td| �q�|� | d d �|�\}} |j�r�td | �|� || �q�n�|j�r�td|�t t� |��D]�} tj�|| �} tj�| �\} }|d k�r�|�r,|| ��s,|j�r�td| ��q�|� | d d �|�\}} |j�rVtd | �|� || ��q�nP|d d�d k�r�td��|� |d d �|�\}} |j�r�td| �|� || �dS)a�Add all files from "pathname" to the ZIP archive. If pathname is a package directory, search the directory and all package subdirectories recursively for all *.py and enter the modules into the archive. If pathname is a plain directory, listdir *.py and enter all modules. Else, pathname must be a Python *.py file and the module will be put into the archive. Added modules are always module.pyc. This method will compile the module.py into module.pyc if necessary. If filterfunc(pathname) is given, it is called with every argument. When it is False, the file or directory is skipped. r�rz%s %r skipped by filterfuncNz __init__.py�%s/%szAdding package in�asr�����ZAdding)� filterfunc�.pyzfile %r skipped by filterfunczAdding files from directoryz.Files added with writepy() must end with ".py"z Adding file)r|r�rur�r�r�r�r2�isfile� _get_codenamerr��listdir�remove�splitext�writepyr�)r��pathname�basenamer�Zlabel�dirr+Zinitnamer�r��dirlistrBr��root�extrrrr��s�     � �    � � zPyZipFile.writepyc sd�fdd� }|d}|d}tjj|dd�}tjj|dd�}tjj|d d�}�jdk�r\tj�|�r�t�|�jt�|�jkr�|} } n�tj�|�r�t�|�jt�|�jkr�|} |} n�tj�|�r�t�|�jt�|�jkr�|} |} nvtj�|��rt�|�jt�|�jk�r|} |} nD||��rRt j j d k�r4|} nt j j dk�rH|} n|} |} n|} } n��jd k�rr|} |} n<|} �jdk�r�|} n&�jd k�r�|} nd � �j�} t | ��tj�| ��r�t�| �jt�|�jk�s�||�jd ��s�|} } tj�| �d} |�rd || f} | | fS)aReturn (filename, archivename) for the path. Given a module name path, return the correct file path and archive name, compiling if necessary. For example, given /python/lib/string, return (/python/lib/string.pyc, string). r�c sdddl}�jrtd|�z|j|d|d�Wn2|jy^}zt|j�WYd}~dSd}~00dS)NrZ CompilingT)�doraiser�F)� py_compilerur��compile�PyCompileError�msg)rr�r�errr�rr�_compiles  z)PyZipFile._get_codename.._compiler�z.pycr�)� optimizationrrrz"invalid value for 'optimize': {!r})r�r�)r�)� importlib�util�cache_from_sourcer�r|r�r�r�r�r�r�r��formatrr�) r�r�r�r Zfile_pyZfile_pycZ pycache_opt0Z pycache_opt1Z pycache_opt2r�r�rZ archivenamerr�rr��sj   �  � ��      � zPyZipFile._get_codename)r�N)rrrrrr�r�r�rrrrr �s �  Rr cCst�t|�dd�S)a2 Given a path with elements separated by posixpath.sep, generate all parents of that path. >>> list(_parents('b/d')) ['b'] >>> list(_parents('/b/d/')) ['/b'] >>> list(_parents('b/d/f/')) ['b/d', 'b'] >>> list(_parents('b')) [] >>> list(_parents('')) [] rN)� itertools�islice� _ancestry)r�rrr�_parentsOsrccs2|�tj�}|�tj�r.|Vt�|�\}}q dS)a� Given a path with elements separated by posixpath.sep, generate all elements of that path. >>> list(_ancestry('b/d')) ['b/d', 'b'] >>> list(_ancestry('/b/d/')) ['/b/d', '/b'] >>> list(_ancestry('b/d/f/')) ['b/d/f', 'b/d', 'b'] >>> list(_ancestry('b')) ['b'] >>> list(_ancestry('')) [] Multiple separators are treated like a single. >>> list(_ancestry('//b//d///f//')) ['//b//d///f', '//b//d', '//b'] N)r�� posixpathr}r�)r��tailrrrrbs  rcCst�t|�j|�S)zZ Return items in minuend not in subtrahend, retaining order with O(1) lookup. )r� filterfalse�set� __contains__)ZminuendZ subtrahendrrr� _difference�srcsHeZdZdZedd��Z�fdd�Zdd�Zdd �Ze d d ��Z �Z S) � CompleteDirszk A ZipFile subclass that ensures that implied directories are always included in the namelist. cCs.tj�tt|��}dd�|D�}tt||��S)Ncss|]}|tjVqdSr�)rr})r�r�rrrr��r-z-CompleteDirs._implied_dirs..)r�chain� from_iterabler�r�_deduper)�names�parentsZas_dirsrrr� _implied_dirs�szCompleteDirs._implied_dirscs tt|���}|t|�|��Sr�)rRrr�r_r )r�rrSrrr��szCompleteDirs.namelistcCs t|���Sr�)rr�r�rrr� _name_set�szCompleteDirs._name_setcCs,|��}|d}||vo||v}|r(|S|S)zx If the name represents a directory, return that name as a directory (with the trailing slash). rx)r!)r�r+rr�Z dir_matchrrr� resolve_dir�szCompleteDirs.resolve_dircCsNt|t�r|St|t�s ||�Sd|jvr.t}|�|�}t|��t|��|S)zl Given a source (filename or zipfile), return an appropriate CompleteDirs subclass. rj)r�rr r*�__new__�vars�update)r�r��resrrr�make�s    zCompleteDirs.make) rrrr� staticmethodr r�r!r"r�r'rXrrrSrr�s   rcs,eZdZdZ�fdd�Z�fdd�Z�ZS)� FastLookupzV ZipFile subclass to ensure implicit dirs exist and are resolved rapidly. csFt�t��|jWd�S1s&0Ytt|���|_|jSr�)� contextlib�suppressr3Z_FastLookup__namesrRr)r�r�rSrrr��s $zFastLookup.namelistcsFt�t��|jWd�S1s&0Ytt|���|_|jSr�)r*r+r3Z_FastLookup__lookuprRr)r!r�rSrrr!�s $zFastLookup._name_set)rrrrr�r!rXrrrSrr)�s r)c@s�eZdZdZdZd$dd�Zd%dd�Zed d ��Zd d �Z d d�Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd�Zdd�Zdd �ZeZed!d"��Zd#S)&ru� A pathlib-compatible interface for zip files. Consider a zip file with this structure:: . ├── a.txt └── b ├── c.txt └── d └── e.txt >>> data = io.BytesIO() >>> zf = ZipFile(data, 'w') >>> zf.writestr('a.txt', 'content of a') >>> zf.writestr('b/c.txt', 'content of c') >>> zf.writestr('b/d/e.txt', 'content of e') >>> zf.filename = 'abcde.zip' Path accepts the zipfile object itself or a filename >>> root = Path(zf) From there, several path operations are available. Directory iteration (including the zip file itself): >>> a, b = root.iterdir() >>> a Path('abcde.zip', 'a.txt') >>> b Path('abcde.zip', 'b/') name property: >>> b.name 'b' join with divide operator: >>> c = b / 'c.txt' >>> c Path('abcde.zip', 'b/c.txt') >>> c.name 'c.txt' Read text: >>> c.read_text() 'content of c' existence: >>> c.exists() True >>> (b / 'missing.txt').exists() False Coercion to string: >>> str(c) 'abcde.zip/b/c.txt' z>{self.__class__.__name__}({self.root.filename!r}, {self.at!r})r�cCst�|�|_||_dSr�)r)r'r�at)r�rr,rrrr� s z Path.__init__rjcOs\|�dd�}|d}|jj|j||d�}d|vrD|s8|r@td��|Stj|g|�Ri|��S)z� Open this entry as text or binary following the semantics of ``pathlib.Path.open()`` by passing arguments through to io.TextIOWrapper(). r�Nrr��bz*encoding args invalid for binary operation)�poprrAr,rr=� TextIOWrapper)r�r*�args�kwargsr�Zzip_mode�streamrrrrA s z Path.opencCst�|j�d��S�Nrx)rr�r,r�r�rrrr+# sz Path.namecOsD|jdg|�Ri|���}|��Wd�S1s60YdS)Nrjr�)r�r0r1�strmrrr� read_text' szPath.read_textcCs6|�d��}|��Wd�S1s(0YdS)Nr?r�)r�r4rrr� read_bytes+ s zPath.read_bytescCst�|j�d��|j�d�kSr3)rr�r,r�)r�r�rrr� _is_child/ szPath._is_childcCs t|j|�Sr�)rr)r�r,rrr�_next2 sz Path._nextcCs|j p|j�d�Sr3)r,�endswithr�rrrr�5 sz Path.is_dircCs |�� Sr�)r�r�rrr�is_file8 sz Path.is_filecCs|j|j��vSr�)r,rr!r�rrrr�; sz Path.existscCs.|��std��t|j|j���}t|j|�S)NzCan't listdir a file)r�rr�r8rr��filterr7)r�Zsubsrrr�iterdir> sz Path.iterdircCst�|jj|j�Sr�)rr2rrBr,r�rrr�__str__D sz Path.__str__cCs|jj|d�S)Nr�)� _Path__reprrr�rrrr�G sz Path.__repr__cCs t�|j|�}|�|j�|��Sr�)rr2r,r8rr")r��add�nextrrr�joinpathJ sz Path.joinpathcCs(t�|j�d��}|r|d7}|�|�Sr3)rr�r,r�r8)r�Z parent_atrrr�parentP sz Path.parentN)r�)rj)rrrrr>r�rArir+r5r6r7r8r�r:r�r<r=r�rA� __truediv__rBrrrrr�s(@   rc s ddl}d}|j|d�}|jdd�}|jdddd d �|jd d d ddd�|jdddddd�|jddddd �|�|�}|jdur�|j}t|d��}|��}Wd�n1s�0Y|r�td� |��td��nB|j du�r"|j }t|d��}|� �Wd�n1�s0Yn�|j du�rp|j \}}t|d��}|� |�Wd�n1�sd0Yn�|jdu�r|j�d�} |j} �fdd��t| d��f}| D]P} tj�| �} | �s�tj�tj�| ��} | dtjtjfv�r�d} �|| | ��q�Wd�n1�s0YdS) Nrz3A simple command-line interface for zipfile module.)� descriptionT)�requiredz-lz--list� zShow listing of a zipfile)�metavar�helpz-ez --extractr)rFz zExtract zipfile into target dir)�nargsrGrHz-cz--create�+)zzzCreate zipfile from sourcesz-tz--testzTest if a zipfile is validrjz.The following enclosed file is corrupted: {!r}z Done testingcsptj�|�r|�||t�nPtj�|�rl|r8|�||�tt�|��D]$}�|tj�||�tj�||��qFdSr�) r|r�r�rrr�r�r�r2)rar��zippathZnm��addToZiprrrM� s   �zmain..addToZiprkr�)�argparse�ArgumentParser�add_mutually_exclusive_group� add_argument� parse_args�testr r�r�rr_r�r�r�Zcreater.r|r�r�r�r�r�) r0rNrD�parser�groupr�raZbadfiler�Zzip_name�filesr�rKrrLr�mainX s\   � � � �   &   *   ,    rW�__main__)N)N)�rZbinascii�importlib.utilr r=rr|rr�r�rFr�r|r�r*r�r�� ImportErrorr�r��__all__� Exceptionrr rrr�r�r�rrrrr�r�r�r�r�r^r]r�r\rLrMrNrOrPrQrRrbr�r�r�r�r�r�Z_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_SIZEr�r�r�Z_CD_DISK_NUMBER_STARTZ_CD_INTERNAL_FILE_ATTRIBUTESZ_CD_EXTERNAL_FILE_ATTRIBUTESr�r�r�r�r�Z_FH_EXTRACT_VERSIONZ_FH_EXTRACT_SYSTEMr�Z_FH_COMPRESSION_METHODZ_FH_LAST_MOD_TIMEZ_FH_LAST_MOD_DATEZ_FH_CRCZ_FH_COMPRESSED_SIZEZ_FH_UNCOMPRESSED_SIZEr�r�rGrHrErJrKrIZ_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_CENTDIRre�Structr.r8r=r rYr9�objectr r�r�r�r�r�r�r�rrr rr>rrYr r rr�dict�fromkeysrrrr)rrWrrrrr�sT                +=^&� (KU/2 =