Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/python/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyc


&Mc@sdZddlZddlZddlZddlZddlZejejZ	dej
fdYZdefdYZ
de
fdYZd	e
fd
YZddd
ZdZddedZdZdZdZddddZdS(s
An incremental approach to unzipping files.  This allows you to unzip a little
bit of a file at a time, which means you can report progress as a file unzips.
iNtChunkingZipFilecBseZdZdZRS(sq
    A ZipFile object which, with readfile(), also gives you access to a
    filelike object for each entry.
    cCs||jdkrtdn|js6tdn|j|}|jj|jd|jjt}|dd!tj	krtj
dntjtj
|}|jj|tj}|tjr|jj|tjn||jkrtj
d|j|fn|jtjkr:t||jS|jtjkr\t||jStj
d	|j|fd
S(s3
        Return file-like object for name.
        trtasread() requires mode "r" or "a"s3Attempt to read ZIP archive that was already closediis Bad magic number for file headers3File name in directory "%s" and header "%s" differ.s-Unsupported compression method %d for file %sN(RR(tmodetRuntimeErrortfptgetinfotseekt
header_offsettreadt_fileHeaderSizetzipfiletstringFileHeadert
BadZipfiletstructtunpacktstructFileHeadert_FH_FILENAME_LENGTHt_FH_EXTRA_FIELD_LENGTHt
orig_filenamet
compress_typet
ZIP_STOREDtZipFileEntryt
compress_sizetZIP_DEFLATEDtDeflatedZipFileEntry(tselftnametzinfotfheadertfname((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytreadfiles2	
(t__name__t
__module__t__doc__R(((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyRst
_FileEntrycBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s!
    Abstract superclass of both compressed and uncompressed variants of
    file-like objects within a zip archive.

    @ivar chunkingZipFile: a chunking zip file.
    @type chunkingZipFile: L{ChunkingZipFile}

    @ivar length: The number of bytes within the zip file that represent this
    file.  (This is the size on disk, not the number of decompressed bytes
    which will result from reading it.)

    @ivar fp: the underlying file object (that contains pkzip data).  Do not
    touch this, please.  It will quite likely move or go away.

    @ivar closed: File-like 'closed' attribute; True before this file has been
    closed, False after.
    @type closed: L{bool}

    @ivar finished: An older, broken synonym for 'closed'.  Do not touch this,
    please.
    @type finished: L{int}
    cCs7||_|jj|_||_d|_t|_dS(sC
        Create a L{_FileEntry} from a L{ChunkingZipFile}.
        iN(tchunkingZipFileRtlengthtfinishedtFalsetclosed(RR$R%((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyt__init__Vs
			cCstS(sD
        Returns false because zip files should not be ttys
        (R'(R((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytisattyascCst|_d|_|`dS(s/
        Close self (file-like object)
        iN(tTrueR(R&R(R((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytclosehs		csGd}x:tfddD] }||7}|dkrPqqW|S(s
        Read a line.
        tcs
jdS(Ni(R	((R(s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyt<lambda>vss
(titer(Rtbytestbyte((Rs</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytreadlineqs
cCs#|j}|r|StdS(si
        Implement next as file does (like readline, except raises StopIteration
        at EOF)
        N(R2t
StopIteration(Rtnextline((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytnext}scCs
t|S(s1
        Returns a list of all the lines
        (tlist(R((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyt	readlinesscCs|S(s/
        Returns an iterator (so self)
        ((R((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyt
xreadlinesscCs|S(s/
        Returns an iterator (so self)
        ((R((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyt__iter__s(R R!R"R)R*R,R2R5R7R8R9(((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyR#?s								RcBs,eZdZdZdZddZRS(sJ
    File-like object used to read an uncompressed entry in a ZipFile
    cCs tj|||d|_dS(Ni(R#R)t	readBytes(RR$R%((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyR)scCs|jS(N(R:(R((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyttellscCs|dkr|j|j}n|dks4|jr8dS|jjjt||j|j}|jt|7_|j|jkst||krd|_n|S(NiR-i(	tNoneR%R:R&R$RR	tmintlen(Rtntdata((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyR	s$N(R R!R"R)R;R<R	(((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyRs		RcBs,eZdZdZdZddZRS(sE
    File-like object used to read a deflated entry in a ZipFile
    cCsDtj|||d|_d|_tjd|_d|_dS(NiiR-(R#R)t
returnedBytesR:tzlibt
decompressobjtdecomptbuffer(RR$R%((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyR)s
		cCs|jS(N(RA(R((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyR;scCs|jr
dS|dkr|jg}|j|jj|jjj|j	|j
|j|jjd|j|jjd|_d|_dj|}|j
t|7_
|Sxt|j|kr|jjjt|d|j	|j
}|j
t|7_
|so|j|jjd|jj}d|_d|_|j
t|7_
|S|j|jj|7_qW|j| }|j||_|j
t|7_
|SdS(NR-tZii(R&R<REtappendRDt
decompressR$RR	R%R:tflushtjoinRAR>R=(RR?tresultR@((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyR	s<				&		
N(R R!R"R)R;R<R	(((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyRs		t.icCsDtjdddtddx t|||dtD]}q6WdS(sG
    Unzip the file

    @param filename: the name of the zip file
    @param directory: the directory into which the files will be
    extracted
    @param overwrite: if on, overwrite files when they exist.  You can
    still get an error if you try to create a directory over a file
    with the same name or vice-versa.
    s7zipstream.unzip is deprecated since Twisted 11.0.0 for s0security reasons.  Use Python's zipfile instead.tcategoryt
stacklevelitsuppressWarningN(twarningstwarntDeprecationWarningt	unzipIterR+(tfilenamet	directoryt	overwriteti((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytunzips
	
iccsy|s*tjddddtddntj|d}|j}tjj|sjtj	|nt
|j}x|D]}|d8}|j|jt
@}tjj||}	|rtjj|	sltj	|	qlntjj|	d	}
tjj|
s!tj	|
n|s:tjj|	rlt|	d
}|j|j||jn|VqWdS(s
    Return a generator for the zipfile.  This implementation will yield
    after every file.

    The value it yields is the number of files left to unzip.
    s0zipstream.unzipIter is deprecated since Twisted s+11.0.0 for security reasons.  Use Python's szipfile instead.RMRNiRiitwbN(RPRQRRRtZipFiletnamelisttostpathtexiststmakedirsR>Rt
external_attrtDIR_BITRJtsplittfiletwriteR	R,(RTRURVROtzftnamest	remainingtentrytisdirtftfdirtoutfile((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyRSs2


cCs@d}t|}x'|jD]}|t||7}qW|S(sr
    Predict the number of chunks that will be extracted from the entire
    zipfile, given chunksize blocks.
    i(RtinfolisttcountFileChunks(RTt	chunksizettotalchunksRetinfo((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytcountZipFileChunks,s
cCs;t|j|\}}|dkr1|d7}n|p:dS(s9
    Count the number of chunks that will result from the given L{ZipInfo}.

    @param zipinfo: a L{zipfile.ZipInfo} instance describing an entry in a zip
    archive to be counted.

    @return: the number of chunks present in the zip file.  (Even an empty file
    counts as one chunk.)
    @rtype: L{int}
    ii(tdivmodt	file_size(tzipinfoRotcounttextra((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyRn8s
cCs2tjdtdtj|}t|jS(s
    Count the number of entries in a zip archive.  (Don't use this function.)

    @param filename: The filename of a zip archive.
    @type filename: L{str}
    s"countZipFileEntries is deprecated.i(RPRQRRRRZR>R[(RTRe((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytcountZipFileEntriesIs	
iccst|d}tjj|s1tj|nt||}|j}|j}xut||D]d\}}	|	j	t
@}
tjj||}|
rtjj|stj|n|d8}|Vqhtjj|d}tjj|stj|n|s!tjj|rt
|d}
|j|}|	jdkr`|d8}|VnxD|j|	jkr|j|}|
j||d8}|VqcW|
jqh|t|	|8}|VqhWdS(s
    Return a generator for the zipfile.  This implementation will yield after
    every chunksize uncompressed bytes, or at the end of a file, whichever
    comes first.

    The value it yields is the number of chunks left to unzip.
    RiiRYN(RR\R]R^R_RrR[RmtzipR`RaRJRbRcRRtR;R	RdR,Rn(RTRURVRotczfRgRftinfosRhRqRiRjRkRlRthunk((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pytunzipIterChunkyVs>	




	
(R"RPRtos.pathR\RBRtcalcsizeRR
RZRtobjectR#RRRXRaR'RSRrRnRxR}(((s</usr/lib/python2.7/dist-packages/twisted/python/zipstream.pyt<module>s$-_7'