ok

Mini Shell

Direktori : /proc/self/root/opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python37/lib64/python3.7/__pycache__/gzip.cpython-37.pyc

B

�x�c�P�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddddgZ	d\Z
ZZZ
Zd\ZZd	Zd
ZdZdd
d�Zdd�ZGdd�d�ZGdd�dej�ZGdd�dej�Zddd�Zdd�Zdd�Zedkr�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�GzipFile�open�compress�
decompress)�����)rrr��	�rbcCs�d|kr d|krPtd|f��n0|dk	r0td��|dk	r@td��|dk	rPtd��|�dd�}t|tttjf�r|t|||�}n,t|d	�s�t|d
�r�td|||�}nt	d��d|kr�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_modeZbinary_file�r$�)/opt/alt/python37/lib64/python3.7/gzip.pyrs$cCs|�t�d|��dS)Nz<L)r�structZpack)�output�valuer$r$r%�write32uEsr)c@s<eZdZdZddd�Zdd�Zddd�Zd	d
�Zdd�Zd
S)�_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�prependr$r$r%�__init__Os
z_PaddedFile.__init__cCs~|jdkr|j�|�S|j||jkrJ|j}|j|7_|j||j�S|j}d|_|j|d�|j�||j|�SdS)N)r0r/rr.r,)r1�sizerr$r$r%rUs
z_PaddedFile.readcCs>|jdkr||_n|jt|�8_dSt|j�|_d|_dS)Nr)r0r,r-r.)r1r3r$r$r%r3bs
z_PaddedFile.prependcCsd|_d|_|j�|�S)N)r0r,r/�seek)r1Zoffr$r$r%r6ksz_PaddedFile.seekcCsdS)NTr$)r1r$r$r%�seekablepsz_PaddedFile.seekableN)r+)r+)	�__name__�
__module__�__qualname__�__doc__r4rr3r6r7r$r$r$r%r*Js

	r*c@s�eZdZdZdZd-dd�Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zd.dd�Z
d/dd�Zdd�Zedd��Zdd�Zejfdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zejfd)d*�Zd0d+d,�ZdS)1ra
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.

    NrcCs4|r"d|ksd|kr"td�|���|r6d|kr6|d7}|dkrTt�||pJd�}|_|dkr|t|dd�}t|ttf�s�d}n
t	�
|�}|dkr�t|d	d�}|�d
�r�t|_
t|�}t�|�|_||_nN|�d��rt|_
|�|�t�|tjtjtjd�|_||_ntd�|���||_|j
tk�r0|�|�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�xr)r�format�builtinsr�	myfileobj�getattrrrrr�fspath�
startswith�READr�_GzipReaderr�BufferedReaderr,r=�WRITE�_init_write�zlibZcompressobjZDEFLATED�	MAX_WBITSZ
DEF_MEM_LEVELr�_write_mtime�fileobj�_write_gzip_header)r1rrr rP�mtime�rawr$r$r%r4�s>#


zGzipFile.__init__cCsBddl}|�dtd�|jtkr<|jdd�dkr<|jdS|jS)Nrzuse the name attributer���z.gz)�warnings�warn�DeprecationWarningrrKr=)r1rUr$r$r%r�s

zGzipFile.filenamecCs
|jjjS)z0Last modification time read from stream, or None)r,rS�_last_mtime)r1r$r$r%rR�szGzipFile.mtimecCs.t|j�}d|dd�dtt|��dS)Nz<gzip r���� �>)�reprrP�hex�id)r1�sr$r$r%�__repr__�s
zGzipFile.__repr__cCs.||_t�d�|_d|_g|_d|_d|_dS)Nr+r)r=rM�crc32�crcr5Zwritebuf�bufsize�offset)r1rr$r$r%rL�szGzipFile._init_writecCs|j�d�|j�d�y<tj�|j�}t|t�s<|�d�}|�	d�rR|dd�}Wnt
k
rld}YnXd}|rzt}|j�t|��d��|j
}|dkr�t��}t|jt|��|tkr�d}n|tkr�d	}nd
}|j�|�|j�d�|�r|j�|d
�dS)Ns��zlatin-1s.gzrTr+r�����)rPrr�path�basenamer=rr�encode�endswith�UnicodeEncodeError�FNAME�chrrO�timer)�int�_COMPRESS_LEVEL_BEST�_COMPRESS_LEVEL_FAST)r1r Zfname�flagsrRZxflr$r$r%rQ�s6



zGzipFile._write_gzip_headercCs�|��|jtkr&ddl}t|jd��|jdkr8td��t|t	�rLt
|�}nt|�}|j}|dkr�|j�
|j�|��|j|7_t�||j�|_|j|7_|S)Nrz$write() on read-only GzipFile objectz!write() on closed GzipFile object)�_check_not_closedrrK�errno�OSError�EBADFrPrrrr-�
memoryview�nbytesrrr5rMrarbrd)r1�datarw�lengthr$r$r%rs 



zGzipFile.writerYcCs2|��|jtkr&ddl}t|jd��|j�|�S)Nrz$read() on write-only GzipFile object)rvrrHrwrxryr,r)r1r5rwr$r$r%rs

z
GzipFile.readcCs@|��|jtkr&ddl}t|jd��|dkr4tj}|j�	|�S)zdImplements BufferedIOBase.read1()

        Reads up to a buffer's worth of data is size is negative.rNz%read1() on write-only GzipFile object)
rvrrHrwrxryr�DEFAULT_BUFFER_SIZEr,�read1)r1r5rwr$r$r%r!s
zGzipFile.read1cCs2|��|jtkr&ddl}t|jd��|j�|�S)Nrz$peek() on write-only GzipFile object)rvrrHrwrxryr,�peek)r1�nrwr$r$r%r�.s

z
GzipFile.peekcCs
|jdkS)N)rP)r1r$r$r%�closed5szGzipFile.closedcCs�|j}|dkrdSd|_zP|jtkrR|�|j���t||j�t||jd@�n|jt	krf|j
��Wd|j}|r�d|_|��XdS)Nl��)
rPrrKrr�flushr)rbr5rHr,�closerD)r1rPrDr$r$r%r�9s

zGzipFile.closecCs4|��|jtkr0|j�|j�|��|j��dS)N)rvrrKrPrrr�)r1Z	zlib_moder$r$r%r�Ls
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().
        )rP�fileno)r1r$r$r%r�SszGzipFile.filenocCs"|jtkrtd��|j�d�dS)z[Return the uncompressed stream file position indicator to the
        beginning of the filezCan't rewind in write moderN)rrHrxr,r6)r1r$r$r%�rewind[s
zGzipFile.rewindcCs
|jtkS)N)rrH)r1r$r$r%�readablebszGzipFile.readablecCs
|jtkS)N)rrK)r1r$r$r%�writableeszGzipFile.writablecCsdS)NTr$)r1r$r$r%r7hszGzipFile.seekablecCs�|jtkr�|tjkr2|tjkr*|j|}ntd��||jkrDtd��||j}d}xt|d�D]}|�	|�q`W|�	d|d�n |jt
kr�|��|j�
||�S|jS)NzSeek from end not supportedzNegative seek in write modesirh)rrKr�SEEK_SET�SEEK_CURrdrrx�rangerrHrvr,r6)r1rd�whence�count�chunk�ir$r$r%r6ks 





z
GzipFile.seekcCs|��|j�|�S)N)rvr,�readline)r1r5r$r$r%r�szGzipFile.readline)NNrNN)rY)rY)rY)r8r9r:r;rDr4�propertyrrRr`rLrQrrrr�r�r�rMZZ_SYNC_FLUSHr�r�r�r�r�r7rr�r6r�r$r$r$r%rss.
H 


csZeZdZ�fdd�Zdd�Zdd�Zdd�Zdd
d�Zdd
�Zdd�Z	�fdd�Z
�ZS)rIcs,t�jt|�tjtjd�d|_d|_dS)N)ZwbitsT)�superr4r*rMZ
decompressobjrN�_new_memberrX)r1�fp)�	__class__r$r%r4�sz_GzipReader.__init__cCst�d�|_d|_dS)Nr+r)rMra�_crc�_stream_size)r1r$r$r%�
_init_read�sz_GzipReader._init_readcCsJ|j�|�}x8t|�|krD|j�|t|��}|s:td��||7}qW|S)z�Read exactly *n* bytes from `self._fp`

        This method is required because self._fp may be unbuffered,
        i.e. return short reads.
        zACompressed file ended before the end-of-stream marker was reached)�_fprr-�EOFError)r1r�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�x|j�d
�}|r�|dkr�Pq�W|t	@r�x|j�d
�}|r�|dkr�Pq�W|t
@r�|�d�dS)
Nrr+Fs�zNot a gzipped file (%r)z<BBIxxr	zUnknown compression methodz<HrrhT)r�rrxr&�unpackr�rX�FEXTRAro�FCOMMENT�FHCRC)r1�magic�method�flagZ	extra_lenr_r$r$r%�_read_gzip_header�s0

z_GzipReader._read_gzip_headerrYcCs�|dkr|��S|sdSx�|jjr@|��d|_|jf|j�|_|jrh|��|��sb|j	|_
dSd|_|j�t
j�}|j�||�}|jjdkr�|j�|jj�n|jjdkr�|j�|jj�|dkr�P|dkrtd��qW|�|�|j	t|�7_	|S)Nrr+TFzACompressed file ended before the end-of-stream marker was reached)�readallZ
_decompressor�eof�	_read_eofr�Z_decomp_factoryZ_decomp_argsr�r�Z_posZ_sizer�rrr~rZunconsumed_tailr3Zunused_datar��_add_read_datar-)r1r5�bufZ
uncompressr$r$r%r�s:

z_GzipReader.readcCs$t�||j�|_|jt|�|_dS)N)rMrar�r�r-)r1r|r$r$r%r��sz_GzipReader._add_read_datacCs�t�d|�d��\}}||jkr<tdt|�t|j�f��n||jd@krRtd��d}x|dkrn|j�d�}qXW|r�|j�	|�dS)Nz<IIr	zCRC check failed %s != %sl��z!Incorrect length of data producedrhr)
r&r�r�r�rxr]r�r�rr3)r1raZisize�cr$r$r%r��s


z_GzipReader._read_eofcst���d|_dS)NT)r��_rewindr�)r1)r�r$r%r�
s
z_GzipReader._rewind)rY)r8r9r:r4r�r�r�rr�r�r��
__classcell__r$r$)r�r%rI�s!
3rIc	Cs4t��}t|d|d��}|�|�WdQRX|��S)z�Compress data in one shot and return the compressed string.
    Optional argument is the compression level, in range of 0-9.
    �wb)rPrr N)r�BytesIOrr�getvalue)r|r r�r2r$r$r%rsc	Cs$tt�|�d��
}|��SQRXdS)zYDecompress a gzip compressed string in one shot.
    Return the decompressed string.
    )rPN)rrr�r)r|r2r$r$r%rscCs:tjdd�}|o|ddk}|r.|dd�}|s8dg}x�|D]�}|r�|dkrjtddtjjd�}tjj}q�|dd�d	kr�td
t|��q>t|d�}t	�|dd�d�}n>|dkr�tjj}tddtjjd�}nt	�|d�}t|d	d�}x|�
d�}|s�P|�|�q�W|tjjk	�r|��|tjjk	r>|��q>WdS)
Nrrz-d�-rr
)rrrPrTz.gzzfilename doesn't end in .gz:r�i)
�sys�argvr�stdin�buffer�stdout�printr\rrCrrr�)�argsr�argr2�gr�r$r$r%�_test"s<



r��__main__)r
rNNN)r)r;r&r�rqrrMrCrZ_compression�__all__ZFTEXTr�r�ror�rHrKrtZ_COMPRESS_LEVEL_TRADEOFFrsrr)r*Z
BaseStreamrZDecompressReaderrIrrr�r8r$r$r$r%�<module>s2 
+)
	&

Zerion Mini Shell 1.0