a DOg U@sddlZddlZddlZddlZddlZddlZddlZddlZgdZd\Z Z Z Z Z d\ZZdZdZdZdedddfd d Zd d ZGd ddZGdddeZGdddejZGdddejZefddddZddZddZedkredS)N) BadGzipFileGzipFileopencompress decompress))rrr rbcCsd|vr d|vrPtd|fn0|dur0td|dur@td|durPtd|dd}t|tttjfr|t|||}n,t|dst|d rtd|||}nt d d|vrt ||||S|SdS) NtbzInvalid mode: %rz0Argument '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 TextIOWrapper)filenamemode compresslevelencodingerrorsnewlineZgz_mode binary_filer&/usr/lib64/python3.9/gzip.pyrs$ rcCs|td|dS)Nz|jdur||_n|jt|8_dSt|j|_d|_dSr/)r4r0r1r2)r5r7r&r&r'r7bs   z_PaddedFile.prependcCsd|_d|_|j|Sr9)r4r0r3seek)r5Zoffr&r&r'r;ksz_PaddedFile.seekcCsdSNTr&r5r&r&r'seekablepsz_PaddedFile.seekableN)r.)r.)__name__ __module__ __qualname__r8rr7r;r>r&r&r&r'r-Js   r-c@s eZdZdS)rN)r?r@rAr&r&r&r'rtsrc@seZdZdZddeddfddZeddZeddZdd Z d d Z d d Z ddZ d+ddZ d,ddZddZeddZddZejfddZddZdd Zd!d"Zd#d$Zd%d&Zejfd'd(Zd-d)d*ZdS).rNc CsV|r"d|vsd|vr"td||r6d|vr6|d7}|durTt||pJd}|_|dur|t|dd}t|ttfsd}n t |}|}|durt|dd}| d rt |_ t|}t||_||_nl| d r(|durd dl}|d td t|_ ||t|tjtj tjd |_||_ntd|||_|j tkrR| |dS)NrUzInvalid mode: {!r}rrnamerr 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 _GzipReaderrBufferedReaderr0rCwarningswarn FutureWarningWRITE _init_writezlib compressobjDEFLATED MAX_WBITS DEF_MEM_LEVELr _write_mtimefileobj_write_gzip_header) r5rr r!r\mtimeZorigmoderawrQr&r&r'r8sN#         zGzipFile.__init__cCsBddl}|dtd|jtkr<|jdddkr<|jdS|jS)Nrzuse the name attributer.gz)rQrRDeprecationWarningr rTrC)r5rQr&r&r'rs  zGzipFile.filenamecCs |jjjSr9)r0r_ _last_mtimer=r&r&r'r^szGzipFile.mtimecCs.t|j}d|dddtt|dS)Nz)reprr\hexid)r5sr&r&r'__repr__s zGzipFile.__repr__cCs.||_td|_d|_g|_d|_d|_dSNr.r)rCrVcrc32crcr:Zwritebufbufsizeoffset)r5rr&r&r'rUs  zGzipFile._init_writecCs|jd|jdzuszGzipFile.seekablecCs|jtkr|tjkr2|tjkr*|j|}ntd||jkrDtd||j}d}t|dD]}| |q^| d|dn |jt kr| |j ||S|jS)NzSeek from end not supportedzNegative seek in write modesru)r rTrSEEK_SETSEEK_CURrprrrangerrNrr0r;)r5rpwhencecountchunkir&r&r'r;xs         z GzipFile.seekcCs||j|Sr9)rr0readline)r5r:r&r&r'rszGzipFile.readline)rd)rd)rd)r?r@rArJrr8propertyrr^rkrUr]rrrrrrrV Z_SYNC_FLUSHrrrrrr>rrr;rr&r&r&r'rxs4  Q      rcsZeZdZfddZddZddZddZdd d Zd d ZddZ fddZ Z S)rOcs,tjt|tjtj dd|_d|_dS)N)ZwbitsT)superr8r-rV decompressobjrY _new_memberrc)r5fp __class__r&r'r8s z_GzipReader.__init__cCstd|_d|_dSrl)rVrm_crc _stream_sizer=r&r&r' _init_reads z_GzipReader._init_readcCsF|j|}t||krB|j|t|}|s8td||7}q |S)NACompressed file ended before the end-of-stream marker was reached)_fprr1EOFError)r5rrrr&r&r' _read_exacts   z_GzipReader._read_exactcCs|jd}|dkrdS|dkr,td|td|d\}}|_|dkrVtd|t@r|td |d\}|||t@r|jd }|r|d krqq|t @r|jd }|r|d krqq|t @r|dd S) Nrr.FrqzNot a gzipped file (%r)z|dddkrt d|t|d}t|ddd}nB|dkr"t jj}t ddt jj|d}nt|d}t|dd}|d}|sPq^||q<|t jjurt||t jjur|qdS)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*-r3)nargsdefaultmetavarrr)rr r\r`razfilename doesn't end in .gz: r)rr r\r!r)argparseradd_mutually_exclusive_group add_argument parse_args_COMPRESS_LEVEL_TRADEOFFfastrZbestrrrrsysstdinbufferstdoutexitrrIrrr) rparsergrouprr!argr6grr&r&r'main/sR          r__main__) r(rr~rrVrIr _compression__all__ZFTEXTrrr|rrNrTrrrrr,r-rr BaseStreamrDecompressReaderrOrrrr?r&r&r&r's4  ,* 0