QfadZddlZddlZddlZddlZddlZddlZddlZddlZgdZ d\Z Z Z Z Zd\ZZdZdZdZd Zd ej*zZd edddfd Zd ZGddZGddeZGddej8ZGddej<ZdZ dZ!GddejDZ# d"de$de%fdZ&efdddZ'dZ(d Z)e*d!k(re)yy)#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 ir rbcd|vrd|vr5td|| td| td| td|jdd}t|ttt j frt|||}n2t|d s t|d rtd|||}n td 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 +/opt/alt/python312/lib64/python3.12/gzip.pyrrs( d{ $;49: :  OP P  MN N  NO Oll3#G(S%56x-@ 6 "gh&@tWmXF KLL d{##H- XvwGGcN|jtjd|y)Nz>$' ' ::  ,::D JJ$ J<<TZZ0 0::DDJ<<&99>>$t||"3D"89: :r+c|j||_n|xjt|zc_yt|j|_d|_yr5)r:r6r7r8)r;r=s r*r=z_PaddedFile.prependfs? :: "DL JJ#g, &J 4<<(  r+cTd|_d|_|jj|Sr@)r:r6r9seek)r;offs r*rDz_PaddedFile.seekos#  yy~~c""r+cyNTr;s r*seekablez_PaddedFile.seekabletr+N)r+) __name__ __module__ __qualname____doc__r>rr=rDrJrHr+r*r3r3Ns   :# r+r3ceZdZdZy)rz6Exception raised in some cases for invalid gzip files.N)rLrMrNrOrHr+r*rrxs@r+rc(eZdZdZdZdZdZdZy)_WriteBufferStreamz8Minimal object to pass WriteBuffer flushes into GzipFilec||_yr@) gzip_file)r;rTs r*r>z_WriteBufferStream.__init__~s "r+c8|jj|Sr@)rT _write_raw)r;datas r*rz_WriteBufferStream.writes~~((..r+cy)NFrHrIs r*rJz_WriteBufferStream.seekablesr+cyrGrHrIs r*writablez_WriteBufferStream.writablerKr+N)rLrMrNrOr>rrJrZrHr+r*rRrR|sB#/r+rRceZdZdZdZddeddfdZedZdZ dZ fdZ dZ d Z d Zdd Zdd Zd ZedZdZej*fdZdZdZdZdZdZej:fdZddZxZ S)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|vrtdj||r d|vr|dz }|!tj||xsdx}|_|&t |dd}t |ttfsd}ntj|}|}| t |d d}|jd r8t|_ t|}tj ||_||_n|jd r|d dl}|j)d t*dt,|_ |j/|t1j2|t0j4t0j6 t0j8d |_||_t>|_ tjBtE||j@|_ntdj|||_#|jt,k(r|jI|yy)aGConstructor 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, an io.BytesIO 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 include 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', 'wb', 'x', or 'xb' depending on whether the file will be read or written. The default is the mode of fileobj if discernible; otherwise, the default is 'rb'. A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and 'wb', 'a' and 'ab', and 'x' and 'xb'. The compresslevel argument is an integer from 0 to 9 controlling the level of compression; 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression. 0 is no compression at all. The default is 9. The mtime argument is an optional numeric timestamp to be written to the last modification time field in the stream when compressing. If omitted or None, the current time is used. rUzInvalid mode: {!r}rNrnamerr#r)waxrzGzipFile was opened for writing, but this will change in future Python releases. Specify the mode argument for opening it for writing.r ) buffer_size)%rformatbuiltinsr myfileobjgetattrrrrrfspath startswithREADr# _GzipReaderrBufferedReaderr6r^warningswarn FutureWarningWRITE _init_writezlib compressobjDEFLATED MAX_WBITS DEF_MEM_LEVELr _write_mtime_WRITE_BUFFER_SIZE _buffer_sizeBufferedWriterrRfileobj_write_gzip_header) r;r"r#r$r{mtimeorigmoderawrms r*r>zGzipFile.__init__sF SD[C4K188>? ? CtO CKD ?'/}}Xt|t'L LGdn  w3Hhe 5yy*H <7FD1D ??3 DIg&C,,S1DL DI ___ - L"1 & DI   X & ,,]-1]].2nn_-1-?-?-. 0DM !&D  2D ,,-?-E9=9J9JLDL188>? ? 99   # #M 2 r+cB|jjjS)z0Last modification time read from stream, or None)r6r _last_mtimerIs r*r}zGzipFile.mtimes||+++r+crt|j}d|ddzdztt|zdzS)Nz)reprr{hexid)r;ss r*__repr__zGzipFile.__repr__s8  !Ab'!C'#bh-7#==r+c~||_tjd|_d|_g|_d|_d|_yNr+r)r^rrcrc32crcrAwritebufbufsizeoffset)r;r"s r*rqzGzipFile._init_writes4 ::c?    r+ct|j|jjt|Sr@)_check_not_closedr6flushsupertellr; __class__s r*rz GzipFile.tells+   w|~r+c2|jjd|jjd tjj |j }t |ts|jd}|jdr|dd}d}|rt}|jjt|jd|j}|tj}t|jt!||t"k(rd}n|t$k(rd }nd }|jj||jjd |r|jj|d zyy#t$rd}YwxYw) Nzlatin-1s.gzr+r)r{rrpathbasenamer^rrencodeendswithUnicodeEncodeErrorFNAMEchrrwtimer1int_COMPRESS_LEVEL_BEST_COMPRESS_LEVEL_FAST)r;r$fnameflagsr}xfls r*r|zGzipFile._write_gzip_headersJ ;' 7# GG$$TYY/EeU+ Y/~~f%cr  E 3u:,,Y78!! =IIKEs5z* 0 0C 2 2CC 3 7#  LL  uw / %" E sA F FFc|j|jtk7rddl}t |j d|j td|jj|S)Nrz$write() on read-only GzipFile objectz!write() on closed GzipFile object) rr#rperrnoOSErrorEBADFr{rr6r)r;rWrs r*rzGzipFile.write#sZ  99  %++'MN N << @A A||!!$''r+ct|ttfr t|}nt |}|j }|dkDr|j j|jj||xj|z c_ tj||j|_ |xj|z c_ |Sr5)rr bytearrayr7 memoryviewnbytesr{rrrArrrrr)r;rWlengths r*rVzGzipFile._write_raw.s dUI. /YFd#D[[F A: LL  t}}55d; < II Izz$1DH KK6 !K r+c|j|jtk7rddl}t |j d|j j|S)Nrz$read() on write-only GzipFile object)rr#rjrrrr6rr;rArs r*rz GzipFile.read?sD  99  %++'MN N||  &&r+c|j|jtk7rddl}t |j d|dkrt j}|jj|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#rjrrrrDEFAULT_BUFFER_SIZEr6read1rs r*rzGzipFile.read1FsX  99  %++'NO O !8))D||!!$''r+c|j|jtk7rddl}t |j d|j j|S)Nrz$peek() on write-only GzipFile object)rr#rjrrrr6peek)r;nrs r*rz GzipFile.peekSsD  99  %++'MN N||  ##r+c|jduSr@)r{rIs r*closedzGzipFile.closedZs||t##r+cH|j}|y |jtk(rs|jj |j |j j t||jt||jdzn-|jtk(r|jjd|_|j}|rd|_ |jyy#d|_|j}|rd|_ |jwwxYw)N) r{r#rpr6rrrr1rrArjcloserf)r;r{rfs r*rzGzipFile.close^s,, ?  "yyE! ""$ dmm1134$((+$))j"89d" ""$DLI!%! DLI!%!s B3C22/D!c|j|jtk(ri|jj |j j |jj ||j j yyr@)rr#rpr6rr{rr)r; zlib_modes r*rzGzipFile.flushrs`  99  LL   LL  t}}229= > LL   r+c6|jjS)zInvoke the underlying file object's fileno() method. This will raise AttributeError if the underlying file object doesn't support fileno(). )r{filenorIs r*rzGzipFile.filenozs ||""$$r+cv|jtk7r td|jj dy)z[Return the uncompressed stream file position indicator to the beginning of the filezCan't rewind in write moderN)r#rjrr6rDrIs r*rewindzGzipFile.rewinds. 99 67 7 !r+c(|jtk(Sr@)r#rjrIs r*readablezGzipFile.readablesyyD  r+c(|jtk(Sr@)r#rprIs r*rZzGzipFile.writablesyyE!!r+cyrGrHrIs r*rJzGzipFile.seekablerKr+c|jtk(r|j|jj |t j k7r.|t jk(r|j|z}n td||jkr td||jz }d|jz}t||jzD]}|j||jd||jzz|jS|jtk(r,|j|jj||S|jS)NzSeek from end not supportedzNegative seek in write moder)r#rprr6rrSEEK_SETSEEK_CURrrrryrangerrjrD)r;rwhencecountchunkis r*rDz GzipFile.seeks 99   " " $ LL   $R[[(![[61F$%BCC #;<<T[[(ED---E5D$5$556 5!7 JJu(9(9 9: ; {{ YY$   " " $<<$$VV4 4{{r+cX|j|jj|Sr@)rr6readline)r;rAs r*rzGzipFile.readlines#  ||$$T**r+r)!rLrMrNrOrfrr>propertyr}rrqrr|rrVrrrrrrr Z_SYNC_FLUSHrrrrrZrJrrrDr __classcell__rs@r*rrsI $43TS3j,,> 0@ ("' ($$$"("..!%!"#%++.+r+rc|j|}t||kr>|j|t|z }|s td||z }t||kr>|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)fprrWrs r* _read_exactrsd 771:D d)a- GGAD M ">? ?   d)a- Kr+c|jd}|dk(ry|dk7rtd|ztjdt |d\}}}|dk7r td|t zr.tjd t |d\}t |||t zr |jd }|r|d k(rn|tzr |jd }|r|d k(rn|tzr t |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)zr3rr_ZlibDecompressorru _new_memberr)r;rrs r*r>z_GzipReader.__init__s> R$*@*@ $  0 r+cFtjd|_d|_yr)rrr_crc _stream_sizerIs r* _init_readz_GzipReader._init_readsJJsO r+cBt|j}|y||_y)NFT)r_fpr)r;rs r*rz_GzipReader._read_gzip_headers$&txx0  %r+c|dkr|jS|sy |jjr8|jd|_|j di|j |_|jr9|j|js|j|_ yd|_|jjr<|jjt}|jj||}n|jjd|}|jj dk7r/|jj#|jj |dk7rndk(r t%dat'j(||j*|_|xj,t/|z c_|xjt/|z c_ |S)Nrr+TFrrH)readall _decompressoreof _read_eofr_decomp_factory _decomp_argsrr_pos_size needs_inputrrREAD_BUFFER_SIZEr unused_datar=rrrrrrr7)r;rAbuf uncompresss r*rz_GzipReader.reads !8<<> ! !!%%  #' %9T%9%9&)''&)"!--/!%DJ#( !!--hhmm$45!//::3E !//::3E !!--4  !3!3!?!?@S cz BCCGLJJz4995  S_, S_$ r+ctjdt|jd\}}||jk7r-t dt |dt |j||jdzk7r t dd}|dk(r!|jjd}|dk(r!|r|jj|yy) Nrrrrrrrs@r*rkrks' 3j *  r+rkr$returnc |tj}|tk(rd}n|tk(rd}nd}tjdddddt ||dS) 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. r r rz>"1+=> V $**\* *01 1 c,'*4 5AB B##L1~~ab!((1# r+cddlm}|d}|j}|jddd|jd dd |jd d dd |jdddgd|j }t }|j rt}n|jrt}|jD]}|jr|dk(rAtddtjj}tj j}n|dddk7rtj"d|t%|d}t'j$|ddd}nl|dk(rBtjj}tddtj j|}n%t'j$|d}t%|dzd} |j)t*}|sn|j-|*|tj jur|j/|tjjus}|j/y)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#r{rz.gzzfilename doesn't end in .gz: wb)r"r#r{r$)argparser#add_mutually_exclusive_group add_argument parse_args_COMPRESS_LEVEL_TRADEOFFfastrbestrr(rrsysstdinbufferstdoutexitrrerrrr) r#parsergroupr(r$argr<grs r*mainr?s'  ,-F  / / 1E x ;LM x ;LM t^L>@ cC5&I    D,M yy, , yy ??czbtSYY=M=MNJJ%%rs8u$HHrGs)%   G(6%ufeX e///,@tT+Z+ ''TA'A  `+|&&`+F  "J_ ,//_ F(,KcK05K*"6$22.` zFr+