Vc ^rdZddlZddlZddlZddlZddlZddlZddlZddlZgdZ d\Z Z Z Z Zd\ZZdZdZdZd edddfd Zd ZGd d ZGddeZGddejZdZdZGddejZ ddede fdZ!efdddZ"dZ#dZ$e%dkr e$dSdS)zFunctions 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) BadGzipFileGzipFileopencompress decompress))rr r rbc"d|vrd|vrtd|n3|td|td|td|dd}t|ttt jfrt|||}nBt|d st|d rtd|||}ntd d|vr+tj |}tj ||||S|S) 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). tbzInvalid mode: Nz0Argument 'encoding' not supported in binary modez.Argument 'errors' not supported in binary modez/Argument 'newline' not supported in binary modereadwritez1filename must be a str or bytes object, or a file) ValueErrorreplace isinstancestrbytesosPathLikerhasattr TypeErrorio text_encoding TextIOWrapper)filenamemode compresslevelencodingerrorsnewlinegz_mode binary_files /usr/lib64/python3.11/gzip.pyrrsE( d{ P $; ;*449:: : ;  QOPP P  OMNN N  PNOO Oll3##G(S%566Mx-@@ 6 " "Mgh&@&@MtWmXFF KLLL d{#H-- XvwGGGcV|tjd|dS)Nz>$'' ' :  , ::D JJ$ JJ<TZ0 0:DDJ<&9>>$t|"3D"899: :r+c|j||_n|xjt|zc_dSt|j|_d|_dSr5)r:r6r7r8)r;r=s r*r=z_PaddedFile.prependcsL : "DLL JJ#g,, &JJ F4<((  r+cRd|_d|_|j|Sr@)r:r6r9seek)r;offs r*rDz_PaddedFile.seekls$  y~~c"""r+cdSNTr;s r*seekablez_PaddedFile.seekableqtr+N)r+) __name__ __module__ __qualname____doc__r>rr=rDrJrHr+r*r3r3Kss   : : :### r+r3ceZdZdZdS)rz6Exception raised in some cases for invalid gzip files.N)rLrMrNrOrHr+r*rrus@@@@r+rceZdZdZdZddeddfdZedZedZ dZ dZ dZ d Z dd Zdd Zd ZedZdZejfdZdZdZdZdZdZejfdZddZdS)ra The GzipFile class simulates most of the methods of a file object with the exception of the truncate() method. 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. Nc|r*d|vsd|vr"td||r d|vr|dz }|tj||pdx}|_|0t |dd}t |ttfsd}ntj |}|}|t |d d}| d rzGzipFile.__init__sF  @SD[ @C4K @188>>?? ?  CtO  CKD  M'/}Xt|t'L'L LGdn  +w33Hhe 55 y**H  27FD11D ??3   @DIg&&C,S11DL DII ___ - - @ & L"1 &&& DI   X & & & ,]-1].2n_-1-?-. 00DM !&D  188>>?? ? 9  3  # #M 2 2 2 2 2 3 3r+cddl}|dtd|jtkr|jdddkr |jdzS|jS)Nrzuse the name attributer .gz)rbrcDeprecationWarningr#rerT)r;rbs r*r"zGzipFile.filenames] .0BAFFF 9  %$)BCC.E"9 %9u$ $yr+c$|jjjS)z0Last modification time read from stream, or None)r6rq _last_mtimerIs r*rozGzipFile.mtimes|++r+ct|j}d|ddzdztt|zdzS)Nz)reprrmhexid)r;ss r*__repr__zGzipFile.__repr__s?   !AbD'!C'#bhh--7#==r+c~||_tjd|_d|_g|_d|_d|_dSNr+r)rTrgcrc32crcrAwritebufbufsizeoffset)r;r"s r*rfzGzipFile._init_writes8 :c??    r+c\|jd|jd tj|j}t |ts|d}| dr |dd}n#t$rd}YnwxYwd}|rt}|jt|d|j }|tj}t|jt!||t"krd}n|t$krd }nd }|j||jd |r|j|d zdSdS) Nzlatin-1s.gzrsr+r)rmrrpathbasenamerTrrencodeendswithUnicodeEncodeErrorFNAMEchrrltimer1int_COMPRESS_LEVEL_BEST_COMPRESS_LEVEL_FAST)r;r$fnameflagsroxfls r*rnzGzipFile._write_gzip_headers ;''' 7### G$$TY//EeU++ 0 Y//~~f%% #crc !   EEE   E 3u::,,Y77888!  IKKEs5zz*** 0 0 CC 2 2 CCC 3 7###  0 L  uw / / / / / 0 0sA-B$$ B32B3c||jtkrddl}t |jd|jtdt|ttfrt|}nt|}|j }|dkrq|j|j||xj|z c_t#j||j|_|xj|z c_|S)Nrz$write() on read-only GzipFile objectz!write() on closed GzipFile object)_check_not_closedr#reerrnoOSErrorEBADFrmrrr bytearrayr7 memoryviewnbytesrrrArgrrr)r;datarlengths r*rzGzipFile.writes    9  O LLL%+'MNN N < B@AA A dUI. / / !YYFFd##D[F A: " L  t}55d;; < < < II IIz$11DH KK6 !KK r+ryc||jtkrddl}t |jd|j|S)Nrz$read() on write-only GzipFile object)rr#r_rrrr6rr;rArs r*rz GzipFile.read(sV    9  O LLL%+'MNN N|  &&&r+c||jtkrddl}t |jd|dkr t j}|j |S)zdImplements BufferedIOBase.read1() Reads up to a buffer's worth of data if size is negative.rNz%read1() on write-only GzipFile object) rr#r_rrrrDEFAULT_BUFFER_SIZEr6read1rs r*rzGzipFile.read1/sl    9  P LLL%+'NOO O !8 *)D|!!$'''r+c||jtkrddl}t |jd|j|S)Nrz$peek() on write-only GzipFile object)rr#r_rrrr6peek)r;nrs r*rz GzipFile.peek<sV    9  O LLL%+'MNN N|  ###r+c|jduSr@)rmrIs r*closedzGzipFile.closedCs|t##r+c|j}|dSd|_ |jtkrZ||jt ||jt ||jdzn)|jtkr|j |j }|rd|_ | dSdS#|j }|rd|_ | wwxYw)N) rmr#rerrflushr1rrAr_r6closer[)r;rmr[s r*rzGzipFile.closeGs ,   F  "yE! % dm1133444$(+++$)j"89999d" % ""$$$I "!%!!!!! " "I "!%!!!! "s BC'C6c||jtkrM|j|j||jdSdSr@)rr#rermrrr)r; zlib_modes r*rzGzipFile.flushZsm    9  ! L  t}229== > > > L    ! !r+c4|jS)zInvoke the underlying file object's fileno() method. This will raise AttributeError if the underlying file object doesn't support fileno(). )rmfilenorIs r*rzGzipFile.filenoas |""$$$r+cx|jtkrtd|jddS)z[Return the uncompressed stream file position indicator to the beginning of the filezCan't rewind in write moderN)r#r_rr6rDrIs r*rewindzGzipFile.rewindis> 9  8677 7 !r+c"|jtkSr@)r#r_rIs r*readablezGzipFile.readablepsyD  r+c"|jtkSr@)r#rerIs r*writablezGzipFile.writablessyE!!r+cdSrGrHrIs r*rJzGzipFile.seekablevrKr+c|jtkr|tjkr*|tjkr |j|z}nt d||jkrtd||jz }d}t|dzD]}| || d|dzzn?|jtkr/| |j ||S|jS)NzSeek from end not supportedzNegative seek in write modesir)r#rerSEEK_SETSEEK_CURrrrrangerr_rr6rD)r;rwhencecountchunkis r*rDz GzipFile.seekys  9  5$ DR[(D![61FF$%BCCC # =;<<<T[(E E5D=)) " " 5!!!! JJu - . . . . Y$  5  " " $ $ $<$$VV44 4{r+c^||j|Sr@)rr6readline)r;rAs r*rzGzipFile.readlines*    |$$T***r+ry)rLrMrNrOr[rr>propertyr"rorrfrnrrrrrrrg Z_SYNC_FLUSHrrrrrrJrrrDrrHr+r*rrysI $43TO3O3O3O3bX,,X,>>>000@0'''' ( ( ( ($$$$$X$"""&".!!!!%%%!!!"""#%+(++++++r+rc||}t||krN||t|z }|std||z }t||kN|S)z}Read exactly *n* bytes from `fp` This method is required because fp may be unbuffered, i.e. return short reads. ACompressed file ended before the end-of-stream marker was reached)rr7EOFError)fprrrs r* _read_exactrs 771::D d))a- GGAD M " " ?>?? ?   d))a- Kr+cB|d}|dkrdS|dkrtd|ztjdt |d\}}}|dkrtd|t zr5tjd t |d\}t |||t zr |d }|r|d krn|tzr |d }|r|d krn|tzrt |d|S) zRead a gzip header from `fp` and progress to the end of the header. Returns last mtime if header was present or None otherwise. r r+NrzNot a gzipped file (%r)zr3rg decompressobjrj _new_memberrw)r;r __class__s r*r>z_GzipReader.__init__sP R$*< $  0 0 0 r+cFtjd|_d|_dSr)rgr_crc _stream_sizerIs r* _init_readz_GzipReader._init_readsJsOO r+cDt|j}|dS||_dS)NFT)r_fprw)r;rs r*rz_GzipReader._read_gzip_headers+&tx00  5%tr+ryc8|dkr|S|sdS |jjr2|d|_|jdi|j|_|jr=||s|j |_ dSd|_|j tj}|j||}|jjdkr%|j |jjn4|jjdkr$|j |jj|dkrn|dkrt'dH|||xj t+|z c_ |S)Nrr+TFrrH)readall _decompressoreof _read_eofr_decomp_factory _decomp_argsrr_pos_sizerrrrrunconsumed_tailr= unused_datar_add_read_datar7)r;rAbuf uncompresss r*rz_GzipReader.reads !8 "<<>> ! 3 # C!% )    #' %9T%9&)&)'&)&)" )!!!--//!%DJ3#( (-- 677C+66sDAAJ!1S8 A  !3!CDDDD#/36 A  !3!?@@@S  cz C BCCCE# CJ Z))) S__$ r+c|tj||j|_|jt |z|_dSr@)rgrrrr7)r;rs r*rz_GzipReader._add_read_data s3JtTY//  -D 9r+ctjdt|jd\}}||jkr4t dt |dt |j||jdzkrt dd}|dkr |jd}|dk |r|j |dSdS) Nrrrrrr __classcell__)rs@r*r`r`s     1111f:::   *         r+r`r$returnc |tj}|tkrd}n|tkrd}nd}tjdddddt ||d S) a Write a simple gzip header with no extra fields. :param compresslevel: Compresslevel used to determine the xfl bytes. :param mtime: The mtime (must support conversion to a 32-bit integer). :return: A bytes object representing the gzip header. Nr r rz"1"+=>> V $*\** * 2011 1 c,''*4 5 CABB B##L111~abb!((11#2r+cddlm}|d}|}|ddd|d dd |d d dd |dddgd|}t }|jrt}n|jrt}|j D]}|j r|dkr3tddtjj}tjj}n|dddkrtjd|t%|d}t'j|ddd}nb|dkr4tjj}tddtjj|}n(t'j|d}t%|dzd} |t*j}|sn||8|tjjur||tjjur|dS)Nr)ArgumentParserzeA simple command line interface for the gzip module: act like gzip, but do not delete the input file.) descriptionz--fast store_truezcompress faster)actionhelpz--bestzcompress betterz-dz --decompresszact like gunzip instead of gzipargs*-r9)nargsdefaultmetavarrr)r"r#rmrsrtzfilename doesn't end in .gz: wb)r"r#rmr$)argparseradd_mutually_exclusive_group add_argument parse_args_COMPRESS_LEVEL_TRADEOFFfastrbestrrrrsysstdinbufferstdoutexitrrZrrrrr) rparsergrouprr$argr<grs r*mainr2ks'''''' ^ ,---F  / / 1 1E x ;LMMM x ;LMMM t^L>@@@ cC5&III     D,M y-, -, y ? ,cz 2btSY=MNNNJ%rss8u$FHDSDDEEEdOOM#crc(D11cz ,I$btSZ=N+8:::M#t,,ud++ FF2122E  GGENNN   CJ% %  GGIII CI$ $  GGIII5r+__main__r@)&rOr-r)rrrgrZr _compression__all__FTEXTrrrrr_rerr&rrr1r3rr BaseStreamrrrDecompressReaderr`rrrrrr2rLrHr+r*r9sW%%   G G G(6%ufeX e,@tT++++Z+++ ''''''''TAAAAA'AAAV+V+V+V+V+|&V+V+V+r    """Ja a a a a ,/a a a J(,KKcK05KKKK*"6$2222...` z DFFFFF  r+