a �DOg U�@sdZddlZddlZddlZddlZddlZddlZddlZddlZgd�Z d\Z Z Z Z Zd\ZZdZdZdZd edddfd d �Zd d �ZGdd�d�ZGdd�de�ZGdd�dej�ZGdd�dej�Zefdd�dd�Zdd�Zdd�Ze dkr�e�dS)z�Functions that read and write gzipped files. The user of the file doesn't have to worry about the compression, but random access is not allowed.�N)� BadGzipFile�GzipFile�open�compress� decompress)�����)rrr�� �rbcCs�d|vr d|vrPtd|f��n0|dur0td��|dur@td��|durPtd��|�dd�}t|tttjf�r|t|||�}n,t|d �s�t|d �r�td|||�}nt d ��d|vr�t � ||||�S|SdS) a Open a gzip-compressed file in binary or text mode. The filename argument can be an actual filename (a str or bytes object), or an existing file object to read from or write to. The mode argument can be "r", "rb", "w", "wb", "x", "xb", "a" or "ab" for binary mode, or "rt", "wt", "xt" or "at" for text mode. The default mode is "rb", and the default compresslevel is 9. For binary mode, this function is equivalent to the GzipFile constructor: GzipFile(filename, mode, compresslevel). In this case, the encoding, errors and newline arguments must not be provided. For text mode, a GzipFile object is created, and wrapped in an io.TextIOWrapper instance with the specified encoding, error handling behavior, and line ending(s). �t�bzInvalid mode: %rNz0Argument 'encoding' not supported in binary modez.Argument 'errors' not supported in binary modez/Argument 'newline' not supported in binary mode��read�writez1filename must be a str or bytes object, or a file) � ValueError�replace� isinstance�str�bytes�os�PathLiker�hasattr� TypeError�io� TextIOWrapper)�filename�mode� compresslevel�encoding�errors�newlineZgz_mode� binary_file�r&�/usr/lib64/python3.9/gzip.pyrs$ rcCs|�t�d|��dS)Nz|jdur||_n|jt|�8_dSt|j�|_d|_dSr/)r4r0r1r2)r5r7r&r&r'r7bs   z_PaddedFile.prependcCsd|_d|_|j�|�Sr9)r4r0r3�seek)r5Zoffr&r&r'r;ksz_PaddedFile.seekcCsdS�NTr&�r5r&r&r'�seekablepsz_PaddedFile.seekableN)r.)r.) �__name__� __module__� __qualname__�__doc__r8rr7r;r>r&r&r&r'r-Js   r-c@seZdZdZdS)rz6Exception raised in some cases for invalid gzip files.N)r?r@rArBr&r&r&r'rtsrc@s�eZdZdZdZddeddfdd�Zedd��Zedd��Z d d �Z d d �Z d d�Z dd�Z d,dd�Zd-dd�Zdd�Zedd��Zdd�Zejfdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zejfd(d)�Zd.d*d+�ZdS)/ra The GzipFile class simulates most of the methods of a file object with the exception of the truncate() method. This class only supports opening files in binary mode. If you need to open a compressed file in text mode, use the gzip.open() function. Nc CsV|r"d|vsd|vr"td�|���|r6d|vr6|d7}|durTt�||pJd�}|_|dur|t|dd�}t|ttf�s�d}n t � |�}|}|dur�t|d d�}|� d �r�t |_ t|�}t�|�|_||_nl|� d ��r(|dur�d dl}|�d td�t|_ |�|�t�|tjtj tjd �|_||_ntd�|���||_|j tk�rR|� |�dS)aGConstructor for the GzipFile class. At least one of fileobj and filename must be given a non-trivial value. The new class instance is based on fileobj, which can be a regular file, an io.BytesIO object, or any other object which simulates a file. It defaults to None, in which case filename is opened to provide a file object. When fileobj is not None, the filename argument is only used to be included in the gzip file header, which may include the original filename of the uncompressed file. It defaults to the filename of fileobj, if discernible; otherwise, it defaults to the empty string, and in this case the original filename is not included in the header. The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or 'xb' depending on whether the file will be read or written. The default is the mode of fileobj if discernible; otherwise, the default is 'rb'. A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and 'wb', 'a' and 'ab', and 'x' and 'xb'. The compresslevel argument is an integer from 0 to 9 controlling the level of compression; 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression. 0 is no compression at all. The default is 9. The mtime argument is an optional numeric timestamp to be written to the last modification time field in the stream when compressing. If omitted or None, the current time is used. r�UzInvalid mode: {!r}rNr�namerr �r)�w�a�xrz�GzipFile was opened for writing, but this will change in future Python releases. Specify the mode argument for opening it for writing.r)!r�format�builtinsr� myfileobj�getattrrrrr�fspath� startswith�READr � _GzipReaderr�BufferedReaderr0rD�warnings�warn� FutureWarning�WRITE� _init_write�zlib� compressobj�DEFLATED� MAX_WBITS� DEF_MEM_LEVELr� _write_mtime�fileobj�_write_gzip_header) r5rr r!r]�mtimeZorigmode�rawrRr&r&r'r8�sN#       � � zGzipFile.__init__cCsBddl}|�dtd�|jtkr<|jdd�dkr<|jdS|jS)Nrzuse the name attributer������.gz)rRrS�DeprecationWarningr rUrD)r5rRr&r&r'r�s  zGzipFile.filenamecCs |jjjS)z0Last modification time read from stream, or None)r0r`� _last_mtimer=r&r&r'r_�szGzipFile.mtimecCs.t|j�}d|dd�dtt|��dS)Nz)�reprr]�hex�id)r5�sr&r&r'�__repr__�s zGzipFile.__repr__cCs.||_t�d�|_d|_g|_d|_d|_dS�Nr.r)rDrW�crc32�crcr:Zwritebuf�bufsize�offset)r5rr&r&r'rV�s  zGzipFile._init_writecCs|j�d�|j�d�zuszGzipFile.seekablecCs�|jtkr�|tjkr2|tjkr*|j|}ntd��||jkrDtd��||j}d}t|d�D]}|� |�q^|� d|d�n |jt kr�|� �|j � ||�S|jS)NzSeek from end not supportedzNegative seek in write modes�rv)r rUr�SEEK_SET�SEEK_CURrqrr��rangerrOr�r0r;)r5rq�whence�count�chunk�ir&r&r'r;xs         z GzipFile.seekcCs|��|j�|�Sr9)r�r0�readline)r5r:r&r&r'r��szGzipFile.readline)re)re)re)r?r@rArBrKr�r8�propertyrr_rlrVr^rrr�r�r�r�rW� Z_SYNC_FLUSHr�r�r�r�r�r>rr�r;r�r&r&r&r'rxs6 � Q      rcsZeZdZ�fdd�Zdd�Zdd�Zdd�Zdd d �Zd d �Zdd�Z �fdd�Z �Z S)rPcs,t�jt|�tjtj d�d|_d|_dS)N)ZwbitsT)�superr8r-rW� decompressobjrZ� _new_memberrd)r5�fp�� __class__r&r'r8�s �z_GzipReader.__init__cCst�d�|_d|_dSrm)rWrn�_crc� _stream_sizer=r&r&r'� _init_read�s z_GzipReader._init_readcCsF|j�|�}t|�|krB|j�|t|��}|s8td��||7}q |S)z�Read exactly *n* bytes from `self._fp` This method is required because self._fp may be unbuffered, i.e. return short reads. �ACompressed file ended before the end-of-stream marker was reached)�_fprr1�EOFError)r5r�r�rr&r&r'� _read_exact�s   z_GzipReader._read_exactcCs�|j�d�}|dkrdS|dkr,td|��t�d|�d��\}}|_|dkrVtd��|t@r|t�d |�d��\}|�|�|t@r�|j�d �}|r�|d kr�q�q�|t @r�|j�d �}|r�|d kr�q�q�|t @r�|�d�d S) Nrr.FrrzNot a gzipped file (%r)z|dd�dkr�t �d|���t|d�}t�|dd�d�}nB|dk�r"t jj}t ddt jj|d�}nt�|d�}t|dd�}|�d�}|�sP�q^|�|��q<|t jju�rt|��|t jjur�|��q�dS)Nr)�ArgumentParserzeA simple command line interface for the gzip module: act like gzip, but do not delete the input file.)� descriptionz--fast� store_truezcompress faster)�action�helpz--bestzcompress betterz-dz --decompresszact like gunzip instead of gzip�args�*�-r3)�nargs�default�metavarrr)rr r]rarbzfilename doesn't end in .gz: r�)rr r]r!r�)�argparser��add_mutually_exclusive_group� add_argument� parse_args�_COMPRESS_LEVEL_TRADEOFF�fastr�Zbestr�r�rr�sys�stdin�buffer�stdout�exitrrJrrr�) r��parser�groupr�r!�argr6�gr�r&r&r'�main/sR � �     �   r��__main__)!rBr(r�rrrWrJr� _compression�__all__ZFTEXTr�r�r}r�rOrUr�r�r�rr,r-r�r� BaseStreamr�DecompressReaderrPrrr�r?r&r&r&r'�s6 � ,* 0