o ?OgYU@sdZddlZddlZddlZddlZddlZddlZddlZddlZgdZ d\Z Z Z Z Zd\ZZdZdZdZd edddfd d Zd d ZGdddZGdddeZGdddejZGdddejZefddddZddZddZe dkredSdS)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))rrr rbcCsd|vrd|vrtd|fn|durtd|dur td|dur(td|dd}t|tttjfr>t|||}nt|d sHt|d rPtd|||}nt d d|vret |}t ||||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: %rNz0Argument '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 compresslevelencodingerrorsnewlineZgz_modeZ binary_filer&+/opt/alt/python310/lib64/python3.10/gzip.pyrs(  rcCs|td|dS)Nz|jdur ||_n |jt|8_dSt|j|_d|_dSr.)r3r/r0r1)r4r6r&r&r'r6cs   z_PaddedFile.prependcCsd|_d|_|j|Sr8)r3r/r2seek)r4Zoffr&r&r'r:ls z_PaddedFile.seekcCdSNTr&r4r&r&r'seekableqz_PaddedFile.seekableN)r-) __name__ __module__ __qualname____doc__r7rr6r:r>r&r&r&r'r,Ks   r,c@seZdZdZdS)rz6Exception raised in some cases for invalid gzip files.N)r@rArBrCr&r&r&r'rusrc@seZdZdZdZddeddfddZeddZeddZ d d Z d d Z d dZ ddZ d,ddZd,ddZddZeddZddZejfddZddZd d!Zd"d#Zd$d%Zd&d'Zejfd(d)Zd,d*d+ZdS)-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 CsV|rd|vs d|vrtd||rd|vr|d7}|dur*t||p%d}|_|dur>t|dd}t|ttfs=d}nt |}|}|durOt|d d}| d ret |_ t|}t||_||_n5| d r|duryd dl}|d tdt|_ ||t|tjtj tjd |_||_ntd|||_|j tkr| |dSdS)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)!rformatbuiltinsr myfileobjgetattrrrrrfspath startswithREADr! _GzipReaderrBufferedReaderr/rEwarningswarn FutureWarningWRITE _init_writezlibZ compressobjZDEFLATED MAX_WBITSZ DEF_MEM_LEVELr _write_mtimefileobj_write_gzip_header) r4r r!r"r[mtimeZorigmoderawrSr&r&r'r7sR#         zGzipFile.__init__cCsBddl}|dtd|jtkr|jdddkr|jdS|jS)Nrzuse the name attributer.gz)rSrTDeprecationWarningr!rVrE)r4rSr&r&r'r s  zGzipFile.filenamecCs |jjjS)z0Last modification time read from stream, or None)r/r^ _last_mtimer=r&r&r'r]s zGzipFile.mtimecCs.t|j}d|dddtt|dS)Nz)reprr[hexid)r4sr&r&r'__repr__s $zGzipFile.__repr__cCs.||_td|_d|_g|_d|_d|_dSNr-r)rErXcrc32crcr9Zwritebufbufsizeoffset)r4r r&r&r'rWs   zGzipFile._init_writecCs|jd|jdztj|j}t|ts|d}| dr)|dd}Wn t y5d}Ynwd}|rvr?zGzipFile.seekablecCs|jtkrC|tjkr|tjkr|j|}ntd||jkr"td||j}d}t|dD]}| |q/| d|d|jS|jt krS| |j ||S|jS)NzSeek from end not supportedzNegative seek in write modesirt)r!rVrSEEK_SETSEEK_CURrorrrangerrPrr/r:)r4rowhencecountchunkir&r&r'r:ys"        z GzipFile.seekcCs||j|Sr8)rr/readline)r4r9r&r&r'rs zGzipFile.readlinerc)r@rArBrCrLrr7propertyr r]rjrWr\rrrrrrrXZ Z_SYNC_FLUSHrrrrrr>rrr:rr&r&r&r'rys8  Q      rcsZeZdZfddZddZddZddZdd d Zd d ZddZ fddZ Z S)rQcs,tjt|tjtj dd|_d|_dS)N)ZwbitsT)superr7r,rXZ decompressobjrY _new_memberrb)r4fp __class__r&r'r7s  z_GzipReader.__init__cCstd|_d|_dSrk)rXrl_crc _stream_sizer=r&r&r' _init_reads  z_GzipReader._init_readcCsP|j|}t||kr&|j|t|}|std||7}t||ks |S)zRead exactly *n* bytes from `self._fp` This method is required because self._fp may be unbuffered, i.e. return short reads. ACompressed file ended before the end-of-stream marker was reached)_fprr0EOFError)r4rrrr&r&r' _read_exacts   z_GzipReader._read_exactcCs|jd}|dkr dS|dkrtd|td|d\}}|_|dkr+td|t@r>td |d\}|||t@rQ |jd }|rO|d krPnqC|t @rd |jd }|rb|d krcnqV|t @rm|dd S) Nrr-FrpzNot a gzipped file (%r)z   %z_GzipReader.readcCs$t||j|_|jt||_dSr8)rXrlrrr0)r4rr&r&r'rsz_GzipReader._add_read_datacCstd|d\}}||jkrtdt|t|jf||jd@kr(tdd}|dkr8|jd}|dks.|rB|j |dSdS)Nzt}n|jrCt }|j D]{}|j r}|dkr]t ddt jjd}t jj}n@|dddkrmt d|t|d}t|ddd}n |dkrt jj}t ddt jj|d}n t|d}t|dd} |tj}|sn||q|t jjur||t jjur|qFdS)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*-r2)nargsdefaultmetavarrr)r r!r[r_r`zfilename doesn't end in .gz: r)r r!r[r")argparserZadd_mutually_exclusive_group add_argument parse_args_COMPRESS_LEVEL_TRADEOFFZfastrZbestrrrrsysstdinbufferstdoutexitrrKrrrrr) rparsergrouprr"argr5grr&r&r'main0sZ           r__main__)!rCr(rr}rrXrKrZ _compression__all__ZFTEXTrrr{rrPrVrrrrr+r,rrZ BaseStreamrZDecompressReaderrQrrrr@r&r&r&r's:  -* 0