Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/
Upload File :
Current File : //usr/lib/python2.7/gzip.pyc


|_c@sdZddlZddlZddlZddlZddlZddlZddlZddgZddddd	f\Z	Z
ZZZ
ddf\ZZd
ZdZdd
dZdejfdYZdZedkrendS(sFunctions 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.iNtGzipFiletopeniiiiicCs|jtjd|dS(Ns<L(twritetstructtpack(toutputtvalue((s/usr/lib/python2.7/gzip.pytwrite32uscCstjd|jddS(Ns<Iii(Rtunpacktread(tinput((s/usr/lib/python2.7/gzip.pytread32strbi	cCst|||S(sShorthand for GzipFile(filename, mode, compresslevel).

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

    (R(tfilenametmodet
compresslevel((s/usr/lib/python2.7/gzip.pyRscBseZdZdZd ZddddddZedZdZ	dZ
dZd	Zd
Z
dZdZd
dZdZddZdZdZedZdZejdZdZdZdZdZdZddZd
dZ RS(!sThe GzipFile class simulates most of the methods of a file object with
    the exception of the readinto() and truncate() methods.

    i
ii	c
Cs|rd|kr|d7}n|dkrMtj||p=d}|_n|dkrt|dr|jdkr|j}qd}n|dkrt|dr|j}qd}n|dd!d	krt|_t|_	d|_
d|_d|_||_d
|_
nx|dd!dks7|dd!dkrxt|_|j|tj|tjtjtjd|_ntd
|d||_d|_||_|jtkr|jndS(sXConstructor 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, a StringIO 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'.
        Be aware that only the 'rb', 'ab', and 'wb' values should be used
        for cross-platform portability.

        The compresslevel argument is an integer from 1 to 9 controlling the
        level of compression; 1 is fastest and produces the least compression,
        and 9 is slowest and produces the most compression.  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().

        tbRtnames<fdopen>tRiitridtwtasMode s not supportedN(tNonet__builtin__Rt	myfileobjthasattrRRtREADtTruet_new_membertextrabuft	extrasizet
extrastarttmin_readsizetWRITEt_init_writetzlibtcompressobjtDEFLATEDt	MAX_WBITSt
DEF_MEM_LEVELtcompresstIOErrortfileobjtoffsettmtimet_write_gzip_header(tselfR
RRR*R,((s/usr/lib/python2.7/gzip.pyt__init__-sD)
"								&	
				cCsSddl}|jdtd|jtkrL|jddkrL|jdS|jS(Nisuse the name attributeiis.gz(twarningstwarntDeprecationWarningRR!R(R.R0((s/usr/lib/python2.7/gzip.pyR
s
"cCs6t|j}d|dd!dtt|dS(Ns<gzip iit t>(treprR*thextid(R.ts((s/usr/lib/python2.7/gzip.pyt__repr__scCs|jrtdndS(sLRaises a ValueError if the underlying file object has been closed.

        sI/O operation on closed file.N(tclosedt
ValueError(R.((s/usr/lib/python2.7/gzip.pyt
_check_closeds	cCs>||_tjdd@|_d|_g|_d|_dS(NRli(RR#tcrc32tcrctsizetwritebuftbufsize(R.R
((s/usr/lib/python2.7/gzip.pyR"s
			cCs|jjd|jjdtjj|j}|jdrQ|d }nd}|rft}n|jjt||j	}|dkrtj}nt|jt
||jjd|jjd|r|jj|dndS(	Nsss.gziisst(R*RtostpathtbasenameRtendswithtFNAMEtchrR,RttimeRtlong(R.tfnametflagsR,((s/usr/lib/python2.7/gzip.pyR-s"
		cCs#tjdd@|_d|_dS(NRli(R#R=R>R?(R.((s/usr/lib/python2.7/gzip.pyt
_init_readscCs|jjd}|dkr*tdnt|jjd}|dkrZtdnt|jjd}t|j|_|jjd|t@rt|jjd}|dt|jjd}|jj|n|t@r,x6tr(|jjd}|s!|dkrPqqWn|t	@rox6trk|jjd}|sd|dkr9Pq9q9Wn|t
@r|jjdndS(	NissNot a gzipped fileiisUnknown compression methodiRB(R*R	R)tordRR,tFEXTRARGRtFCOMMENTtFHCRC(R.tmagictmethodtflagtxlenR8((s/usr/lib/python2.7/gzip.pyt_read_gzip_headers2
 
	
	
cCs|j|jtkr:ddl}t|jdn|jdkrUtdnt	|t
rs|j}nt|dkr|j
t||_
tj||jd@|_|jj|jj||jt|7_nt|S(Nis$write() on read-only GzipFile objects!write() on closed GzipFile objectil(R<RR!terrnoR)tEBADFR*RR;t
isinstancet
memoryviewttobytestlenR?R#R=R>RR(R+(R.tdataRW((s/usr/lib/python2.7/gzip.pyRs
icCsu|j|jtkr:ddl}t|jdn|jdkr\|jdkr\dSd}|dkry4x-t	r|j
|t|j|d}qtWWq.t
k
r|j}q.Xnly=x6||jkr|j
|t|j|d}qWWn,t
k
r-||jkr.|j}q.nX|j|j}|j|||!}|j||_|j|7_|S(Nis$read() on write-only GzipFile objectiRii(R<RRRWR)RXRR*RRt_readtmintmax_read_chunktEOFErrorR+RR(R.R?RWtreadsizeR+tchunk((s/usr/lib/python2.7/gzip.pyR	s4
	



cCs/t||j|_|jt|8_dS(N(R\RR+(R.tbuf((s/usr/lib/python2.7/gzip.pyt_unread
scCsl|jdkrtdn|jr|jj}|jjdd||jjkrgtdn|jj||j|jtj	tj
|_t|_n|jj
|}|dkr|jj}|j|j|tdn|jj|}|j||jjdkrh|jjt|jjdd|jt|_ndS(NsReached EOFiiRii(R*RRaRttelltseekRMRVR#t
decompressobjR&t
decompresstFalseR	tflusht	_read_eoft_add_read_datatunused_dataR\R(R.R?tposRdt
uncompress((s/usr/lib/python2.7/gzip.pyR^s0	




$
cCs|tj||jd@|_|j|j}|j|||_|jt||_|j|_|jt||_dS(Nl(	R#R=R>R+RRRR\R?(R.R]R+((s/usr/lib/python2.7/gzip.pyRmCscCs|jjddt|j}t|j}||jkrhtdt|t|jfn||jd@krtdnd}x"|dkr|jjd}qW|r|jjddndS(NiisCRC check failed %s != %sls!Incorrect length of data producedRBi(R*RgRR>R)R6R?R	(R.R=tisizetc((s/usr/lib/python2.7/gzip.pyRlKscCs
|jdkS(N(R*R(R.((s/usr/lib/python2.7/gzip.pyR:cscCs|jdkrdS|jtkrq|jj|jjt|j|jt|j|j	d@d|_n|jt
krd|_n|jr|jjd|_ndS(Nl(
R*RRR!RR(RkRR>R?RRtclose(R.((s/usr/lib/python2.7/gzip.pyRsgs	
cCsI|j|jtkrE|jj|jj||jjndS(N(R<RR!R*RR(Rk(R.t	zlib_mode((s/usr/lib/python2.7/gzip.pyRkvs
cCs
|jjS(sInvoke the underlying file object's fileno() method.

        This will raise AttributeError if the underlying file object
        doesn't support fileno().
        (R*tfileno(R.((s/usr/lib/python2.7/gzip.pyRu}scCs_|jtkrtdn|jjdt|_d|_d|_d|_	d|_
dS(s[Return the uncompressed stream file position indicator to the
        beginning of the filesCan't rewind in write modeiRN(RRR)R*RgRRRRRR+(R.((s/usr/lib/python2.7/gzip.pytrewinds				cCs
|jtkS(N(RR(R.((s/usr/lib/python2.7/gzip.pytreadablescCs
|jtkS(N(RR!(R.((s/usr/lib/python2.7/gzip.pytwritablescCstS(N(R(R.((s/usr/lib/python2.7/gzip.pytseekablesicCs*|r1|dkr"|j|}q1tdn|jtkr||jkr^tdn||j}x)t|dD]}|jddq|W|j|ddnt|jtkr#||jkr|jn||j}x%t|dD]}|j	dqW|j	|dn|jS(NisSeek from end not supportedsNegative seek in write modeiRB(
R+R;RR!R)trangeRRRvR	(R.R+twhencetcountti((s/usr/lib/python2.7/gzip.pyRgs&


cCs|dkr|j|j}|jjd|d}|dkru|j||8_|j||7_|j||!Stj}|j}n|}g}x|dkrs|j|}|jd}||ks|dkrt	||kr|d}n|dks|dkr@|j
||d |j||dPn|j
||t	|}t||d}qW||jkrt||jdd|_ndj
|S(Nis
iiRii(R+RRtfindRtsystmaxintR R	R\tappendReR_tjoin(R.R?R+R}RbtbufsRr((s/usr/lib/python2.7/gzip.pytreadlines4	*

Ni(i(!t__name__t
__module__t__doc__RRR`R/tpropertyR
R9R<R"R-RMRVRR	ReR^RmRlR:RsR#tZ_SYNC_FLUSHRkRuRvRwRxRyRgR(((s/usr/lib/python2.7/gzip.pyR$s8W						!	!	2								c	Cstjd}|o |ddk}|r6|d}n|sHdg}nx]|D]U}|r|dkrtddddd	tj}tj}q9|d
dkrdGt|GHqOnt|d}tj|d
 d
}n[|dkrtj}tdddd
d	tj}n%tj|d}t|dd
}x0trk|j	d}|s[Pn|j
|q<W|tjk	r|jn|tjk	rO|jqOqOWdS(Niis-dt-R
RRRR*is.gzsfilename doesn't end in .gz:twbi(RtargvRtstdintstdoutR5RRRR	RRs(targsRitargtftgRc((s/usr/lib/python2.7/gzip.pyt_tests<


	!	
t__main__(RRRRIRCR#tioRt__all__tFTEXTRQRORGRPRR!RRRtBufferedIOBaseRRR(((s/usr/lib/python2.7/gzip.pyt<module>s0$				&