Ϫf%dZddlZddlZddlZddlZGddej ZGddZGddeZ Gd d eZ d Z d Z d Z ddZy)z 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. NceZdZdZdZy)ChunkingZipFilez~ A L{zipfile.ZipFile} object which, with L{readfile}, also gives you access to a file-like object for each entry. cx|jdvr td|js td|j|}|jj |j d|jj tj}|ddtjk7rtjdtjtj|}|jj |tj}|tjr,|jj |tj|j dzr|j#d}n|j#d }||j$k7r&tjd |j$d |d |j&tj(k(rt+||j,S|j&tj.k(rt1||j,Stjd |j&|fz)z3 Return file-like object for name. )razread() requires mode "r" or "a"z3Attempt to read ZIP archive that was already closedrz Bad magic number for file headerizutf-8cp437zFile name in directory "z" and header "z " differ.z-Unsupported compression method %d for file %s)mode RuntimeErrorfpgetinfoseek header_offsetreadzipfilesizeFileHeaderstringFileHeader BadZipFilestructunpackstructFileHeader_FH_FILENAME_LENGTH_FH_EXTRA_FIELD_LENGTH flag_bitsdecode orig_filename compress_type ZIP_STORED ZipFileEntry compress_size ZIP_DEFLATEDDeflatedZipFileEntry)selfnamezinfofheaderfname fname_strs :/usr/lib/python3/dist-packages/twisted/python/zipstream.pyreadfilezChunkingZipFile.readfiles 99J &@A AwwTU U T"  U((!,'',,w556 1Q<733 3$$%GH H-- 8 8'B WW%@%@AB 711 2 GGLL!?!?@ A ??U " W-I W-I ++ +$$&& 3    '"4"4 4e&9&9: :  G$8$8 8'e.A.AB B$$?&&-. N)__name__ __module__ __qualname____doc__r*r+r)rrs  *r+rcPeZdZdZdZdZdZdZdZeZ dZ dZ d Z d Z d Zy ) _FileEntrya! 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} cr||_|jj|_||_d|_d|_y)zC Create a L{_FileEntry} from a L{ChunkingZipFile}. rFN)chunkingZipFiler lengthfinishedclosedr#r4r5s r)__init__z_FileEntry.__init__[s4 /&&))   r+cy)zD Returns false because zip files should not be ttys Fr0r#s r)isattyz_FileEntry.isattyesr+c$d|_d|_|`y)z/ Close self (file-like object) TN)r7r6r r;s r)closez_FileEntry.closeks  Gr+cNd}tfddD]}||z }|dk(s|S|S)z Read a line. r+c&jdS)Nr>)rr;sr)z%_FileEntry.readline..xs1r+ )iter)r#linebytes` r)readlinez_FileEntry.readliness@-s3 D DLDu}   r+c>|j}|r|St)zi Implement next as file does (like readline, except raises StopIteration at EOF) )rG StopIteration)r#nextlines r)__next__z_FileEntry.__next__~s ==? Oor+ct|S)z1 Returns a list of all the lines )listr;s r) readlinesz_FileEntry.readlinessDzr+c|Sz/ Returns an iterator (so self) r0r;s r) xreadlinesz_FileEntry.xreadlines  r+c|SrPr0r;s r)__iter__z_FileEntry.__iter__rRr+c|SNr0r;s r) __enter__z_FileEntry.__enter__s r+c$|jyrV)r?)r#exc_type exc_value tracebacks r)__exit__z_FileEntry.__exit__s  r+N)r,r-r.r/r9r<r?rGrKnextrNrQrTrWr\r0r+r)r2r2Cs@.   D   r+r2c$eZdZdZdZdZddZy)rzJ File-like object used to read an uncompressed entry in a ZipFile c@tj|||d|_y)Nr)r2r9 readBytesr8s r)r9zZipFileEntry.__init__sD/6:r+c|jSrV)r`r;s r)tellzZipFileEntry.tells ~~r+Nc||j|jz }|dk(s |jry|jjj t ||j|jz }|xjt|z c_|j|jk(st||krd|_|S)Nrr+r>)r5r`r6r4r rminlen)r#ndatas r)rzZipFileEntry.reads 9 dnn,A 6T]]##&&++C4;;3O,PQ #d)# >>T[[ (CIMDM r+rVr,r-r.r/r9rbrr0r+r)rrs r+rc$eZdZdZdZdZddZy)r"zE File-like object used to read a deflated entry in a ZipFile ctj|||d|_d|_t j d|_d|_y)Nrir+)r2r9 returnedBytesr`zlib decompressobjdecompbufferr8s r)r9zDeflatedZipFileEntry.__init__s<D/6:((-  r+c|jSrV)rkr;s r)rbzDeflatedZipFileEntry.tells!!!r+Nc |jry||jg}|j|jj |j j j|j|jz |j|jj d|j|jjd|_d|_dj|}|xjt|z c_ |St|j|kr |j j jt|d|j|jz }|xjt|z c_ |sq|j|jj dz|jjz}d|_d|_|xjt|z c_ |S|xj|jj |z c_t|j|kr |jd|}|j|d|_|xjt|z c_ |S)Nr+Zr>i)r6roappendrn decompressr4r rr5r`flushjoinrkrerd)r#rfresultrgs r)rzDeflatedZipFileEntry.reads == 9 F MM &&((++00t~~1MN  MM$++006 7 MM$++++- .DKDMXXf%F   #f+ - Mdkk"Q&++..334t~~!=>#d)+ dkk&<&)divmod file_size)zipinfor}countextras r)r{r{s4'++Y7LE5 qy   :Ar+c#pKt|d}tjj|stj|t ||}|j }|j}t||D]\}} | jtz} tjj||} | r>tjj| stj| |dz}|ztjj| d} tjj| stj| |stjj| s|j|} | jdk(r |dz}|t| d5}| j!| jkrI| j#|}|j%||dz}|| j!| jkrIddd|t'| |z}|y#1swYxYww)z 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. rr>rwbN)rospathexistsmakedirsrnamelistrzzip external_attrDIR_BITrvsplitr*ropenrbrwriter{)r| directory overwriter}czf remainingnamesinfosentryrisdirffdirr outfilehunks r)unzipIterChunkyrs (C (C 77>>) $ I"8Y7I LLNE LLNE5%( t""W, GGLLE * 77>>!$ A NIO77==#A&D77>>$' D!q 1\\%(>>Q&NI#O!T](g'')dnn4!wwy1 d+!Q ' '')dnn4((_T9== 9 (((sFH6!A&H)!H6)H3 .H6).ri)r/os.pathrrrrlZipFilerr2rr"rrr{rr0r+r)rse    0goo0f^^B:05:5p  "+ r+