AlkantarClanX12

Your IP : 3.144.29.213


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/gzip.cpython-34.pyo

�
i f�^�@s6dZddlZddlZddlZddlZddlZddlZddlZddddgZddd	d
df\Z	Z
ZZZ
ddf\ZZdd
ddddd�Zdd�ZGdd�d�ZGdd�dej�Zd
dd�Zdd�Zdd�Zedkr2e�ndS)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������rb�	cCs*d|kr1d|kr�td|f��q�nQ|dk	rLtd��n|dk	rgtd��n|dk	r�td��n|jdd�}t|ttf�r�t|||�}nBt|d	�s�t|d
�r�td|||�}ntd��d|kr"tj	||||�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�bytesr�hasattr�	TypeError�io�
TextIOWrapper)�filename�mode�
compresslevel�encoding�errors�newlineZgz_modeZbinary_file�r!�)/opt/alt/python34/lib64/python3.4/gzip.pyrs$cCs|jtjd|��dS)Nz<L)r�structZpack)�output�valuer!r!r"�write32u?sr&c@sjeZdZdZddd�Zdd�Zdddd	�Zd
d�Zdd
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�prependr!r!r"�__init__Is		z_PaddedFile.__init__cCs�|jdkr|jj|�S|j||jkra|j}|j|7_|j||j�S|j}d|_|j|d�|jj||j|�SdS)N)r-r,rr+r))r.�sizerr!r!r"rOs			z_PaddedFile.readFcCs�|jdkr||_nQ|rOt|�|jkrO|jt|�8_dS|j|jd�||_t|j�|_d|_dS)Nr)r-r)r*r+)r.r0Zreadpreviousr!r!r"r0\sz_PaddedFile.prependcCs'|jdkrdS|j|jd�S)Nr()r-r))r.r!r!r"�unusedgsz_PaddedFile.unusedrcCs�|dkrk|jdk	rkd||jko<|jknrT|j|7_dS||j|j7}nd|_d|_|jj||�S)Nrr)r-r+r)r,�seek)r.�offset�whencer!r!r"r4ls&		z_PaddedFile.seekcCst|j|�S)N)�getattrr,)r.�namer!r!r"�__getattr__xsz_PaddedFile.__getattr__N)
�__name__�
__module__�__qualname__�__doc__r1rr0r3r4r9r!r!r!r"r'Ds
r'c@s�eZdZdZdZd?Zddddddd�Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd@dd�ZdAdd�Zdd �Zd!d"�Zdd#d$�Zd%d&�Zd'd(�Zed)d*��Zd+d,�Zejd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!d9d:d;�Z"dBd<d=�Z#dS)CraThe 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.

    N�
ircCs�|r6d|ksd|kr6tdj|���n|rUd|krU|d7}n|dkr�tj||psd�}|_n|dkr�t|dd�}t|ttf�s�d}q�n|dkr�t|d	d�}n|j	d
�r@t
|_d|_d|_
d
|_d
|_||_d|_t|�}ne|j	d�r�t|_|j|�tj|tjtjtjd
�|_ntdj|���||_d
|_||_|jtkr�|j�ndS)a�Constructor 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', '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 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().

        r
�UzInvalid mode: {!r}rNrr8rr�rTr(r�d�w�a�x)rBrCrD)r�format�builtinsr�	myfileobjr7rrr�
startswith�READr�_new_member�extrabuf�	extrasize�
extrastartr8�min_readsizer'�WRITE�_init_write�zlibZcompressobjZDEFLATED�	MAX_WBITSZ
DEF_MEM_LEVELr�fileobjr5�mtime�_write_gzip_header)r.rrrrSrTr!r!r"r1�sF(
"								
				zGzipFile.__init__cCsYddl}|jdtd�|jtkrR|jdd�dkrR|jdS|jS)Nrzuse the name attributer�z.gz���)�warnings�warn�DeprecationWarningrrOr8)r.rXr!r!r"r�s
(zGzipFile.filenamecCsZ|j}t|t�r$|j}nt|�}d|dd�dtt|��dS)Nz<gzip r� �>���)rSrr'r,�repr�hex�id)r.rS�sr!r!r"�__repr__�s
	zGzipFile.__repr__cCs|jrtd��ndS)zLRaises a ValueError if the underlying file object has been closed.

        zI/O operation on closed file.N)�closedr)r.r!r!r"�
_check_closed�s	zGzipFile._check_closedcCs>||_tjd�d@|_d|_g|_d|_dS)Nr(l��r)r8rQ�crc32�crcr2Zwritebuf�bufsize)r.rr!r!r"rP�s
			zGzipFile._init_writecCsF|jjd�|jjd�y\tjj|j�}t|t�sY|jd�}n|j	d�r{|dd�}nWnt
k
r�d}YnXd}|r�t}n|jjt|�jd��|j
}|dkr�tj�}nt|jt|��|jjd�|jjd	�|rB|jj|d
�ndS)Ns�szlatin-1s.gzrVr(rss�srW)rSr�os�path�basenamer8rr�encode�endswith�UnicodeEncodeError�FNAME�chrrT�timer&�int)r.Zfname�flagsrTr!r!r"rU�s,
		zGzipFile._write_gzip_headercCs#tjd�d@|_d|_dS)Nr(l��r)rQrerfr2)r.r!r!r"�
_init_readszGzipFile._init_readcCsj|jj|�}xQt|�|kre|jj|t|��}|sXtd��n||7}qW|S)NzACompressed file ended before the end-of-stream marker was reached)rSrr*�EOFError)r.�n�datarr!r!r"�_read_exactszGzipFile._read_exactcCs�|jjd�}|dkr"dS|dkr=td��ntjd|jd��\}}|_|dkrtd��n|t@r�tjd	|jd��\}|j|�n|t@r�x0|jjd
�}|s�|dkr�Pq�q�Wn|t	@r1x0|jjd
�}|s&|dkrPqqWn|t
@rK|jd�n|jj�}|r�|jj|�}|j
|�ndS)
Nrr(Fs�zNot a gzipped filez<BBIxxr	zUnknown compression methodz<HrsT)rSr�OSErrorr#�unpackrwrT�FEXTRArn�FCOMMENT�FHCRCr3r�_add_read_data)r.�magic�methodZflagZ	extra_lenrar3�
uncompressr!r!r"�_read_gzip_header#s8'



zGzipFile._read_gzip_headercCs�|j�|jtkr:ddl}t|jd��n|jdkrXtd��nt|t	�rv|j
�}nt|�dkr�|jj|j
j
|��|jt|�7_tj||j�d@|_|jt|�7_nt|�S)Nrz$write() on read-only GzipFile objectz!write() on closed GzipFile objectl��)rdrrO�errnorx�EBADFrSrr�
memoryview�tobytesr*rrr2rQrerfr5)r.rvr�r!r!r"rHs
zGzipFile.writercCsJ|j�|jtkr:ddl}t|jd��n|jdkr\|jdkr\dSd}|dkr�x)|j|�r�t	|j
|d�}qqW|j}nZxW||jkr�|j|�s�||jkr�|j}nPnt	|j
|d�}q�W|j|j}|j
|||�}|j||_|j|7_|S)Nrz$read() on write-only GzipFile objectr(ir)rdrrIr�rxr�rLrSr-�min�max_read_chunkr5rMrK)r.r2r��readsizer5�chunkr!r!r"r]s,
z
GzipFile.readcCs�|j�|jtkr:ddl}t|jd��n|jdkr\|jdkr\dSx|jdkr}|j�r}q_W|dks�||jkr�|j}n|j	|j
}|j|||�}|j|8_|j	|7_	|S)Nrz%read1() on write-only GzipFile objectr()rdrrIr�rxr�rLrSr-r5rMrK)r.r2r�r5r�r!r!r"�read1zs
zGzipFile.read1cCs�|jtkr0ddl}t|jd��n|dkrEd}n|jdkr�|jdkrgdSx.|jdkr�|jt|d��r�qjWn|j	|j
}|j}|j|||�S)Nrz$peek() on write-only GzipFile objectrAr(i)rrIr�rxr�rLrSr-�maxr5rMrK)r.rur�r5Z	remainingr!r!r"�peek�s	*	z
GzipFile.peekcCs/t|�|j|_|jt|�8_dS)N)r*rLr5)r.�bufr!r!r"�_unread�szGzipFile._unreadcCs|jdkrdS|jrX|j�|j�s6dStjtj�|_d|_n|jj|�}|dkr�|jj	�}|jj
|jjd�|j�|j
|�dS|jj|�}|j
|�|jjdkr|jj
|jjd�|j�d|_ndS)NFr(T)rSrJrsr�rQZ
decompressobjrRrr�flushr0Zunused_data�	_read_eofr})r.r2r�r�r!r!r"r-�s,	




zGzipFile._readcCs�tj||j�d@|_|j|j}|j|d�||_|jt|�|_|j|_|jt|�|_dS)Nl��)	rQrerfr5rMrKrLr*r2)r.rvr5r!r!r"r}�szGzipFile._add_read_datacCs�tjd|jd��\}}||jkrXtdt|�t|j�f��n"||jd@krztd��nd}x"|dkr�|jjd�}q�W|r�|jj	|d�ndS)	Nz<IIr	zCRC check failed %s != %sl��z!Incorrect length of data producedsrT)
r#ryrwrfrxr_r2rSrr0)r.reZisize�cr!r!r"r��s!zGzipFile._read_eofcCs
|jdkS)N)rS)r.r!r!r"rc�szGzipFile.closedcCs�|j}|dkrdSd|_zP|jtkrq|j|jj��t||j�t||jd@�nWd|j	}|r�d|_	|j
�nXdS)Nl��)rSrrOrrr�r&rfr2rG�close)r.rSrGr!r!r"r��s				zGzipFile.closecCsI|j�|jtkrE|jj|jj|��|jj�ndS)N)rdrrOrSrrr�)r.Z	zlib_moder!r!r"r�s
zGzipFile.flushcCs
|jj�S)z�Invoke the underlying file object's fileno() method.

        This will raise AttributeError if the underlying file object
        doesn't support fileno().
        )rS�fileno)r.r!r!r"r�szGzipFile.filenocCs_|jtkrtd��n|jjd�d|_d|_d|_d|_d|_	dS)z[Return the uncompressed stream file position indicator to the
        beginning of the filezCan't rewind in write moderTr(N)
rrIrxrSr4rJrKrLrMr5)r.r!r!r"�rewinds				zGzipFile.rewindcCs
|jtkS)N)rrI)r.r!r!r"�readable"szGzipFile.readablecCs
|jtkS)N)rrO)r.r!r!r"�writable%szGzipFile.writablecCsdS)NTr!)r.r!r!r"�seekable(szGzipFile.seekablercCs4|r1|dkr"|j|}q1td��n|jtkr�||jkr^td��n||j}td�}x%t|d�D]}|j|�q�W|jt|d��nt|jtkr-||jkr�|j	�n||j}x%t|d�D]}|j
d�qW|j
|d�n|jS)NrzSeek from end not supportedzNegative seek in write modei)r5rrrOrxr�rangerrIr�r)r.r5r6�countr��ir!r!r"r4+s(


z
GzipFile.seekcCs�|dkr�|j|j}|jjd|�d}|dkrx|j||8_|j||7_|j||�Stj}|j}n|}g}x�|dkr�|j|�}|jd�}||ks�|dkr�t	|�|kr�|d}n|dks|dkrO|j
|d|d��|j||dd��Pn|j
|�|t	|�}t||d�}q�W||jkr�t||jdd�|_ndj
|�S)Nrs
rr(rir])r5rMrK�findrL�sys�maxsizerNrr*�appendr�r��join)r.r2r5r�r�Zbufsr�r!r!r"�readlineDs4	*

zGzipFile.readlinei(i�r]r]r])$r:r;r<r=rGr�r1�propertyrrbrdrPrUrsrwr�rrr�r�r�r-r}r�rcr�rQZZ_SYNC_FLUSHr�r�r�r�r�r�r4r�r!r!r!r"r|s>U
%,c	CsGtj�}td|ddd|��}|j|�WdQX|j�S)z�Compress data in one shot and return the compressed string.
    Optional argument is the compression level, in range of 0-9.
    rSr�wbrN)r�BytesIOrr�getvalue)rvrr�r/r!r!r"rlscCs/tdtj|���}|j�SWdQXdS)zYDecompress a gzip compressed string in one shot.
    Return the decompressed string.
    rSN)rrr�r)rvr/r!r!r"ruscCs�tjdd�}|o&|ddk}|rB|dd�}n|sTdg}nxy|D]q}|r|dkr�tddddd	tjj�}tjj}qa|dd�dkr�tdt|��q[nt|d�}t	j|dd�d
�}na|dkr<tjj}tdddd
d	tjj�}n%t	j|d�}t|dd
�}x*|j
d�}|s}Pn|j|�qdW|tjjk	r�|j�n|tjjk	r[|j�q[q[WdS)Nrrz-d�-rrrrrSrVz.gzzfilename doesn't end in .gz:r�irWrW)
r��argvr�stdin�buffer�stdout�printr^rrFrrr�)�argsr�argr/�gr�r!r!r"�_test}s<
!$
r��__main__)r=r#r�rprhrQrFr�__all__ZFTEXTr|rzrnr{rIrOrr&r'�BufferedIOBaserrrr�r:r!r!r!r"�<module>s$0$+8��	&