Your IP : 3.149.242.223


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/gzip.cpython-35.opt-2.pyc



���]$O�@sRddlZddlZddlZddlZddlZddlZddlZddlZddddgZdddd	d
f\Z	Z
ZZZ
ddf\ZZdddddd
d�Zdd�ZGdd�d�ZGdd�dej�ZGdd�dej�Zddd�Zdd�Zdd�ZedkrNe�dS)�N�GzipFile�open�compress�
decompress������rb�	cCsd|kr.d|krvtd|f��nH|dk	rFtd��|dk	r^td��|dk	rvtd��|jdd�}t|ttf�r�t|||�}nBt|d�s�t|d	�r�td|||�}ntd
��d|krtj	||||�S|SdS)N�t�bzInvalid mode: %rz0Argument '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_mode�binary_file�r"�)/opt/alt/python35/lib64/python3.5/gzip.pyrs$cCs|jtjd|��dS)Nz<L)r�struct�pack)�output�valuer"r"r#�write32u@sr(c@sReZdZddd�Zdd�Zddd�Zdd	�Zd
d�ZdS)
�_PaddedFile�cCs.||_t|�|_||_d|_dS)Nr)�_buffer�len�_length�file�_read)�self�f�prependr"r"r#�__init__Js		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+)r0�sizerr"r"r#rPs			z_PaddedFile.readcCsS|jdkr||_n|jt|�8_dSt|j�|_d|_dS)Nr)r/r+r,r-)r0r2r"r"r#r2]sz_PaddedFile.prependcCs"d|_d|_|jj|�S)N)r/r+r.�seek)r0Zoffr"r"r#r5fs		z_PaddedFile.seekcCsdS)NTr")r0r"r"r#�seekableksz_PaddedFile.seekableN)�__name__�
__module__�__qualname__r3rr2r5r6r"r"r"r#r)Es

	r)c@s<eZdZdZddddddd�Zedd��Zedd��Zd	d
�Zdd�Z	d
d�Z
dd�Zd,dd�Zd-dd�Z
dd�Zedd��Zdd�Zejdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zejd(d)�Zd.d*d+�ZdS)/rNrcCs�|r3d|ksd|kr3tdj|���|rOd|krO|d7}|dkrztj||pmd�}|_|dkr�t|dd�}t|ttf�s�d}|dkr�t|dd�}|j	d	�rt
|_t|�}t
j|�|_||_nn|j	d�rlt|_|j|�tj|tjtjtjd
�|_||_ntdj|���||_|jtkr�|j�dS)Nr
�UzInvalid mode: {!r}rr�namerr�r�w�a�xr)r=r>r?)r�format�builtinsr�	myfileobj�getattrrrr�
startswith�READr�_GzipReaderr�BufferedReaderr+r;�WRITE�_init_write�zlib�compressobj�DEFLATED�	MAX_WBITS�
DEF_MEM_LEVELr�_write_mtime�fileobj�_write_gzip_header)r0rrrrP�mtime�rawr"r"r#r3{s<#
		
		zGzipFile.__init__cCsYddl}|jdtd�|jtkrR|jdd�dkrR|jdS|jS)Nrzuse the name attributer�z.gz���)�warnings�warn�DeprecationWarningrrHr;)r0rVr"r"r#r�s
(zGzipFile.filenamecCs
|jjjS)N)r+rS�_last_mtime)r0r"r"r#rR�szGzipFile.mtimecCs9t|j�}d|dd�dtt|��dS)Nz<gzip r� �>���)�reprrP�hex�id)r0�sr"r"r#�__repr__�szGzipFile.__repr__cCsC||_tjd�|_d|_g|_d|_d|_dS)Nr*r)r;rJ�crc32�crcr4Zwritebuf�bufsize�offset)r0rr"r"r#rI�s				zGzipFile._init_writecCs7|jjd�|jjd�yVtjj|j�}t|t�sV|jd�}|j	d�ru|dd�}Wnt
k
r�d}YnXd}|r�t}|jjt|�jd��|j
}|dkr�tj�}t|jt|��|jjd�|jjd	�|r3|jj|d
�dS)Ns�szlatin-1s.gzrTr*rss�srU)rPr�os�path�basenamer;rr�encode�endswith�UnicodeEncodeError�FNAME�chrrO�timer(�int)r0Zfname�flagsrRr"r"r#rQ�s,
	zGzipFile._write_gzip_headercCs�|j�|jtkr7ddl}t|jd��|jdkrRtd��t|t	�rpt
|�}nt|�}|j}|dkr�|jj
|jj|��|j|7_tj||j�|_|j|7_|S)Nrz$write() on read-only GzipFile objectz!write() on closed GzipFile object)�_check_not_closedrrH�errno�OSError�EBADFrPrrrr,�
memoryview�nbytesrrr4rJrbrcre)r0�datarr�lengthr"r"r#r�s 
	zGzipFile.writercCsG|j�|jtkr7ddl}t|jd��|jj|�S)Nrz$read() on write-only GzipFile object)rqrrErrrsrtr+r)r0r4rrr"r"r#r
s

z
GzipFile.readcCs\|j�|jtkr7ddl}t|jd��|dkrLtj}|jj	|�S)Nrz%read1() on write-only GzipFile object)
rqrrErrrsrtr�DEFAULT_BUFFER_SIZEr+�read1)r0r4rrr"r"r#rzs
	zGzipFile.read1cCsG|j�|jtkr7ddl}t|jd��|jj|�S)Nrz$peek() on write-only GzipFile object)rqrrErrrsrtr+�peek)r0�nrrr"r"r#r{!s

z
GzipFile.peekcCs
|jdkS)N)rP)r0r"r"r#�closed(szGzipFile.closedcCs�|j}|dkrdSd|_zl|jtkrq|j|jj��t||j�t||jd@�n|jt	kr�|j
j�Wd|j}|r�d|_|j�XdS)Nl��)
rPrrHrr�flushr(rcr4rEr+�closerB)r0rPrBr"r"r#r,s				zGzipFile.closecCsF|j�|jtkrB|jj|jj|��|jj�dS)N)rqrrHrPrrr~)r0Z	zlib_moder"r"r#r~?s
zGzipFile.flushcCs
|jj�S)N)rP�fileno)r0r"r"r#r�FszGzipFile.filenocCs/|jtkrtd��|jjd�dS)NzCan't rewind in write moder)rrErsr+r5)r0r"r"r#�rewindNszGzipFile.rewindcCs
|jtkS)N)rrE)r0r"r"r#�readableUszGzipFile.readablecCs
|jtkS)N)rrH)r0r"r"r#�writableXszGzipFile.writablecCsdS)NTr")r0r"r"r#r6[szGzipFile.seekablecCs�|jtkr�|tjkrI|tjkr=|j|}ntd��||jkrdtd��||j}td�}x%t	|d�D]}|j
|�q�W|j
t|d��n,|jtkr�|j�|j
j||�S|jS)NzSeek from end not supportedzNegative seek in write modei)rrHr�SEEK_SET�SEEK_CURrerrsr�rangerrErqr+r5)r0re�whence�count�chunk�ir"r"r#r5^s 

z
GzipFile.seekcCs|j�|jj|�S)N)rqr+�readline)r0r4r"r"r#r�rs
zGzipFile.readliner\r\r\)r7r8r9rBr3�propertyrrRrarIrQrrrzr{r}rrJ�Z_SYNC_FLUSHr~r�r�r�r�r6rr�r5r�r"r"r"r#rns,F
cseZdZ�fdd�Zdd�Zdd�Zdd�Zdd
d�Zdd
�Zdd�Z	�fdd�Z
�S)rFcs<t�jt|�tjdtj�d|_d|_dS)NZwbitsT)�superr3r)rJ�
decompressobjrM�_new_memberrY)r0�fp)�	__class__r"r#r3xs	z_GzipReader.__init__cCstjd�|_d|_dS)Nr*r)rJrb�_crc�_stream_size)r0r"r"r#�
_init_readsz_GzipReader._init_readcCsg|jj|�}xNt|�|krb|jj|t|��}|sUtd��||7}qW|S)NzACompressed file ended before the end-of-stream marker was reached)�_fprr,�EOFError)r0r|rwrr"r"r#�_read_exact�sz_GzipReader._read_exactcCs;|jjd�}|dkr"dS|dkr>td|��tjd|jd��\}}|_|dkr}td��|t@r�tjd	|jd��\}|j|�|t@r�x*|jjd
�}|s�|dkr�Pq�W|t	@r x*|jjd
�}|s|dkr�Pq�W|t
@r7|jd�dS)
Nrr*Fs�zNot a gzipped file (%r)z<BBIxxr	zUnknown compression methodz<HrsT)r�rrsr$�unpackr�rY�FEXTRArl�FCOMMENT�FHCRC)r0�magic�method�flagZ	extra_lenr`r"r"r#�_read_gzip_header�s0'





z_GzipReader._read_gzip_headerrcCs[|dkr|j�S|s dSx|jjrW|j�d|_|j|j�|_|jr�|j�|j�s�|j	|_
dSd|_|jjt
j�}|jj||�}|jjdkr�|jj|jj�n(|jjdkr|jj|jj�|dkrP|dkr#td��q#W|j|�|j	t|�7_	|S)Nrr*TFzACompressed file ended before the end-of-stream marker was reached)�readall�
_decompressor�eof�	_read_eofr��_decomp_factory�_decomp_argsr�r��_pos�_sizer�rrryr�unconsumed_tailr2�unused_datar��_add_read_datar,)r0r4�bufZ
uncompressr"r"r#r�s:

		
	
z_GzipReader.readcCs2tj||j�|_|jt|�|_dS)N)rJrbr�r�r,)r0rwr"r"r#r��sz_GzipReader._add_read_datacCs�tjd|jd��\}}||jkrXtdt|�t|j�f��n||jd@krwtd��d}x"|dkr�|jjd�}q�W|r�|jj	|�dS)Nz<IIr	zCRC check failed %s != %sl��z!Incorrect length of data producedsr)
r$r�r�r�rsr^r�r�rr2)r0rbZisize�cr"r"r#r��s!z_GzipReader._read_eofcst�j�d|_dS)NT)r��_rewindr�)r0)r�r"r#r�s
z_GzipReader._rewindr\)r7r8r9r3r�r�r�rr�r�r�r"r")r�r#rFws!3rFc	CsHtj�}td|ddd|��}|j|�WdQRX|j�S)NrPr�wbr)r�BytesIOrr�getvalue)rwrr�r1r"r"r#rsc	Cs0tdtj|���}|j�SWdQRXdS)NrP)rrr�r)rwr1r"r"r#r
scCs�tjdd�}|o&|ddk}|r?|dd�}|sNdg}xm|D]e}|r�|dkr�tddddd	tjj�}tjj}qX|dd�dkr�tdt|��qUt|d�}t	j|dd�d
�}na|dkr3tjj}tdddd
d	tjj�}n%t	j|d�}t|dd
�}x'|j
d�}|sqP|j|�q[W|tjjk	r�|j�|tjjk	rU|j�qUWdS)Nrrz-d�-rrrrrPrTz.gzzfilename doesn't end in .gz:r�irUrU)
�sys�argvr�stdin�buffer�stdout�printr]rrArrr)�argsr�argr1�gr�r"r"r#�_tests<	
!$
r��__main__)r$r�rnrfrJrAr�_compression�__all__ZFTEXTr�r�rlr�rErHrr(r)�
BaseStreamr�DecompressReaderrFrrr�r7r"r"r"r#�<module>s&0$+)�
�	&

?>