HEX
Server: LiteSpeed
System: Linux us-phx-web629.main-hosting.eu 5.14.0-503.23.2.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 12 05:52:18 EST 2025 x86_64
User: u756937133 (756937133)
PHP: 8.2.27
Disabled: passthru,chgrp
Upload Files
File: //opt/gsutil/third_party/apitools/apitools/base/py/__pycache__/gzip.cpython-39.pyc
a

�z�g�U�@s�dZddlZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
gd�Zd\ZZ
ZZZd\ZZdd
d�Zdd
�ZGdd�de�ZGdd�de
j�Zddd�Zdd�ZdS)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)�builtins)�range)�GzipFile�open�compress�
decompress)�����)rr	�rb�	cCst|||�S)z�Shorthand for GzipFile(filename, mode, compresslevel).

    The filename argument is required; mode defaults to 'rb'
    and compresslevel defaults to 9.

    )r)�filename�mode�
compresslevel�r�9/opt/gsutil/third_party/apitools/apitools/base/py/gzip.pyr"srcCs|�t�d|��dS)Nz<L)�write�struct�pack)�output�valuerrr�write32u,src@sFeZdZdZddd�Zdd�Zddd	�Zd
d�Zdd
d�Zdd�Z	dS)�_PaddedFilez�Minimal read-only file object that prepends a string to the contents
    of an actual file. Shouldn't be used outside of gzip.py, as it lacks
    essential functionality.�cCs ||_t|�|_||_d|_dS�Nr)�_buffer�len�_length�file�_read)�self�f�prependrrr�__init__7s
z_PaddedFile.__init__cCs~|jdur|j�|�S|j||jkrJ|j}|j|7_|j||j�S|j}d|_|j|d�|j�||j|�SdS�N)r!r �readrr)r"�sizer'rrrr'=s
�z_PaddedFile.readFcCsf|jdur||_n>|r:t|�|jkr:|jt|�8_dS|j|jd�||_t|j�|_d|_dSr)r!rrr)r"r$Zreadpreviousrrrr$Js
z_PaddedFile.prependcCs|jdurdS|j|jd�S)Nr)r!r�r"rrr�unusedUs
z_PaddedFile.unusedrcCsn|dkrT|jdurTd||jkr.|jkrDnn|j|7_dS||j|j7}d|_d|_|j�||�S)Nrr)r!rrr �seek)r"�offset�whencerrrr+Zs z_PaddedFile.seekcCst|j|�Sr&)�getattrr )r"�namerrr�__getattr__fsz_PaddedFile.__getattr__N)r)rF)r)
�__name__�
__module__�__qualname__�__doc__r%r'r$r*r+r0rrrrr2s


rc@s
eZdZdZdZdZd>dd�Zedd��Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd?dd�Zd@dd�Zdd�Zd d!�ZdAd#d$�Zd%d&�Zd'd(�Zed)d*��Zd+d,�Zejfd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!dBd:d;�Z"dCd<d=�Z#dS)DraThe GzipFile class simulates most of the methods of a file object with
    the exception of the readinto() and truncate() methods.

    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.

    Ni�rcCs<|r"d|vsd|vr"td�|���|r6d|vr6|d7}|durTt�||pJd�}|_|durxt|dd�}t|tj�sxd}|dur�t|d	d�}|�	d
�r�t
|_d|_d|_
d
|_d
|_||_d|_t|�}nH|�	d��rt|_|�|�t�|tjtjtjd
�|_ntd�|���||_d
|_||_|jtk�r8|��dS)azConstructor 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 includes 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', or 'wb',
        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', and 'a' and 'ab'.

        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 stream when compressing.  All gzip compressed streams
        are required to contain a timestamp.  If omitted or None, the
        current time is used.  This module ignores the timestamp when
        decompressing; however, some programs, such as gunzip, make use
        of it.  The format of the timestamp is the same as that of the
        return value of time.time() and of the st_mtime member of the
        object returned by os.stat().

        �t�UzInvalid mode: {!r}�bNr
r/�r�rTrr�d)�w�a)�
ValueError�formatrr�	myfileobjr.�
isinstance�six�string_types�
startswith�READr�_new_member�extrabuf�	extrasize�
extrastartr/�min_readsizer�WRITE�_init_write�zlib�compressobj�DEFLATED�	MAX_WBITS�
DEF_MEM_LEVELr�fileobjr,�mtime�_write_gzip_header)r"rrrrQrRrrrr%vsH(


�zGzipFile.__init__cCsBddl}|�dtd�|jtkr<|jdd�dkr<|jdS|jS)Nrzuse the name attributer	���z.gz)�warnings�warn�DeprecationWarningrrJr/)r"rUrrrr�s

zGzipFile.filenamecCsB|j}t|t�r|j}t|�}d|dd�dtt|��dS)Nz<gzip r���� �>)rQr@rr �repr�hex�id)r"rQ�srrr�__repr__�s

zGzipFile.__repr__cCs|jrtd��dS)zLRaises a ValueError if the underlying file object has been closed.

        zI/O operation on closed file.N)�closedr=r)rrr�
_check_closed�szGzipFile._check_closedcCs,||_t�d�d@|_d|_g|_d|_dS�Nr���r)r/rL�crc32�crcr(�writebuf�bufsize)r"rrrrrK�s
zGzipFile._init_writecCs�|j�d�|j�d�z>tj�|j�}t|tj�s>|�	d�}|�
d�rT|dd�}Wntyld}Yn0d}|rzt}|j�t�
|��	d��|j}|dur�t��}t|jt|��|j�d�|j�d	�|r�|j�|d
�dS)N���zlatin-1s.gzrTrr����)rQr�os�path�basenamer/r@rA�binary_type�encode�endswith�UnicodeEncodeError�FNAME�unichrrR�timer�int)r"�fname�flagsrRrrrrS�s,


zGzipFile._write_gzip_headercCst�d�d@|_d|_dSrb)rLrdrer(r)rrr�
_init_readszGzipFile._init_readcCsF|j�|�}t|�|krB|j�|t|��}|s8td��||7}q|S)NzACompressed file ended before the end-of-stream marker was reached)rQr'r�EOFError)r"�n�datar7rrr�_read_exacts
zGzipFile._read_exactcCs�|j�d�}|dkrdS|dkr(td��t�d|�d��\}}|_|dkrRtd��|t@rxt�d	|�d��\}|�|�|t@r�|j�d
�}|r�|dkr�q�q�|t	@r�|j�d
�}|r�|dkr�q�q�|t
@r�|�d�|j��}|r�|j�|�}|�
|�dS)
Nr	rFrhzNot a gzipped filez<BBIxxrzUnknown compression methodz<HrrlT)rQr'�OSErrorr�unpackr~rR�FEXTRArt�FCOMMENT�FHCRCr*r�_add_read_data)r"�magic�method�flag�	extra_lenr^r*�
uncompressrrr�_read_gzip_headers4



zGzipFile._read_gzip_headercCs�|��|jtkr&ddl}t|jd��|jdur8td��t|t	�rJ|�
�}t|�dkr�|j�|j
�
|��|jt|�7_t�||j�d@|_|jt|�7_t|�S)Nrz$write() on read-only GzipFile objectz!write() on closed GzipFile objectrc)rarrJ�errnor�EBADFrQr=r@�
memoryview�tobytesrrrr(rLrdrer,)r"r}r�rrrr6s


zGzipFile.writerXcCs�|��|jtkr&ddl}t|jd��|jdkr>|jdur>dSd}|dkrn|�|�rft	|j
|d�}qJ|j}n8||jkr�|�|�s�||jkr�|j}q�t	|j
|d�}qn|j|j}|j
|||�}|j||_|j|7_|S)Nrz$read() on write-only GzipFile objectr�r	)rarrDr�rr�rGrQr!�min�max_read_chunkr,rHrF)r"r(r��readsizer,�chunkrrrr'Ks,




z
GzipFile.readcCs�|��|jtkr&ddl}t|jd��|jdkr>|jdur>dS|jdkrR|��rRq>|dksd||jkrj|j}|j	|j
}|j|||�}|j|8_|j	|7_	|S)Nrz%read1() on write-only GzipFile objectr)rarrDr�rr�rGrQr!r,rHrF)r"r(r�r,r�rrr�read1hs
zGzipFile.read1cCs�|jtkrddl}t|jd��|dkr*d}|jdkr^|jdurBdS|jdkr^|�t|d��r^qB|j	|j
}|j}|t|j�|ks�J�|j|||�S)Nrz$peek() on write-only GzipFile objectr:rr�)
rrDr�rr�rGrQr!�maxr,rHrrF)r"r|r�r,�	remainingrrr�peek~s


z
GzipFile.peekcCs&t|�|j|_|jt|�8_dSr&)rrGr,)r"�bufrrr�_unread�szGzipFile._unreadr�cCs�|jdurdS|jr>|��|��s(dSt�tj�|_d|_|j�|�}|dkr�|j�	�}|j�
|jjd�|��|�
|�dS|j�|�}|�
|�|jjdkr�|j�
|jjd�|��d|_dS)NFrT)rQrErzr�rL�
decompressobjrOrr'�flushr$�unused_data�	_read_eofr�)r"r(r�r�rrrr!�s,



zGzipFile._readcCs`t�||j�d@|_|j|j}|j|d�||_|jt|�|_|j|_|jt|�|_dS�Nrc)	rLrdrer,rHrFrGrr()r"r}r,rrrr��szGzipFile._add_read_datacCs�t�d|�d��\}}||jkr<tdt|�t|j�f��n||jd@krRtd��d}|dkrl|j�d�}qV|r~|j�	|d�dS)	Nz<IIrzCRC check failed %s != %srcz!Incorrect length of data producedrlrT)
rr�r~rerr\r(rQr'r$)r"rd�isize�crrrr��s

�
zGzipFile._read_eofcCs
|jduSr&�rQr)rrrr`�szGzipFile.closedcCs�|j}|durdSd|_zR|jtkrP|�|j���t||j�t||jd@�W|j	}|r�d|_	|�
�n|j	}|r�d|_	|�
�0dSr�)rQrrJrrr�rrer(r?�close)r"rQr?rrrr��s"

�zGzipFile.closecCs4|��|jtkr0|j�|j�|��|j��dSr&)rarrJrQrrr�)r"�	zlib_moderrrr��s
zGzipFile.flushcCs
|j��S)z�Invoke the underlying file object's fileno() method.

        This will raise AttributeError if the underlying file object
        doesn't support fileno().
        )rQ�filenor)rrrr��szGzipFile.filenocCs@|jtkrtd��|j�d�d|_d|_d|_d|_d|_	dS)z[Return the uncompressed stream file position indicator to the
        beginning of the filezCan't rewind in write moderTrN)
rrDrrQr+rErFrGrHr,r)rrr�rewinds
zGzipFile.rewindcCs
|jtkSr&)rrDr)rrr�readableszGzipFile.readablecCs
|jtkSr&)rrJr)rrr�writableszGzipFile.writablecCsdS)NTrr)rrr�seekableszGzipFile.seekablercCs�|r |dkr|j|}ntd��|jtkr~||jkr<td��||j}td�}t|d�D]}|�|�qZ|�t|d��nP|jtkr�||jkr�|�	�||j}t|d�D]}|�
d�q�|�
|d�|jS)NrzSeek from end not supportedzNegative seek in write moder�)r,r=rrJr�bytesrrrDr�r')r"r,r-�countr��irrrr+s(





z
GzipFile.seekcCsH|dkrn|j|j}|j�d|�d}|dkr`|j||8_|j||7_|j||�Stj}|j}n|}g}|dk�r|�|�}|�d�}||ks�|dkr�t	|�|kr�|d}|dks�|dkr�|�
|d|d��|�||dd���q|�
|�|t	|�}t||d�}qv||jk�r>t||jdd�|_d�
|�S)Nr�
rrXrr	i)r,rHrF�findrG�sys�maxsizerIr'r�appendr�r��join)r"r(r,r�r�Zbufsr�rrr�readline2s4



zGzipFile.readline)NNrNN)rX)rX)r�)r)rX)$r1r2r3r4r?r�r%�propertyrr_rarKrSrzr~r�rr'r�r�r�r!r�r�r`r�rL�Z_SYNC_FLUSHr�r�r�r�r�r�r+r�rrrrrjsD�
V

%


,

rcCsHt��}t|d|d��}|�|�Wd�n1s60Y|��S)z�Compress data in one shot and return the compressed string.
    Optional argument is the compression level, in range of 0-9.
    �wb)rQrrN)�io�BytesIOrr�getvalue)r}rr�r#rrrrZs(rcCs<tt�|�d��}|��Wd�S1s.0YdS)zYDecompress a gzip compressed string in one shot.
    Return the decompressed string.
    r�N)rr�r�r')r}r#rrrrdsr)r
r)r)r4rA�	six.movesrrrr�rvrmrLr��__all__�FTEXTr�r�rtr�rDrJrr�objectr�BufferedIOBaserrrrrrr�<module>	s*

8s