U e5dS@sddlZddlZddlZddlZddlZddlZddlZddlZdddddgZd\Z Z Z Z Z d\ZZd Zd Zd Zd edddfd dZddZGdddZGdddeZGdddejZGdddejZefddddZddZddZedkredS)N BadGzipFileGzipFileopencompress decompress))rrr rbcCsd|kr d|krPtd|fn0|dk r0td|dk r@td|dk rPtd|dd}t|tttjfr|t|||}n,t|dst|d rtd|||}nt d d|krt ||||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_modeZ binary_filer%/usr/lib64/python3.8/gzip.pyrs$ cCs|td|dS)Nz|jdkr||_n|jt|8_dSt|j|_d|_dSr-)r2r.r/r0)r3r5r%r%r&r5bs   z_PaddedFile.prependcCsd|_d|_|j|Sr7)r2r.r1seek)r3Zoffr%r%r&r9ksz_PaddedFile.seekcCsdSNTr%r3r%r%r&seekablepsz_PaddedFile.seekableN)r,)r,)__name__ __module__ __qualname__r6rr5r9r<r%r%r%r&r+Js   r+c@s eZdZdS)rN)r=r>r?r%r%r%r&rtsc@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).rNcCs4|r"d|ksd|kr"td||r6d|kr6|d7}|dkrTt||pJd}|_|dkr|t|dd}t|ttfsd}n t |}|dkrt|dd}| d rt |_ t|}t||_||_nN| d rt|_ ||t|tjtj tjd |_||_ntd|||_|j tkr0||dS) NrUzInvalid mode: {!r}rrnamerr r)waxr)rformatbuiltinsr myfileobjgetattrrrrrfspath startswithREADr _GzipReaderrBufferedReaderr.rAWRITE _init_writezlibZ compressobjZDEFLATED MAX_WBITSZ DEF_MEM_LEVELr _write_mtimefileobj_write_gzip_header)r3rr r!rTmtimerawr%r%r&r6s@#         zGzipFile.__init__cCsBddl}|dtd|jtkr<|jdddkr<|jdS|jS)Nrzuse the name attributer.gz)warningswarnDeprecationWarningr rOrA)r3rZr%r%r&rs  zGzipFile.filenamecCs |jjjSr7)r.rW _last_mtimer;r%r%r&rVszGzipFile.mtimecCs.t|j}d|dddtt|dS)Nz)reprrThexid)r3sr%r%r&__repr__s zGzipFile.__repr__cCs.||_td|_d|_g|_d|_d|_dSNr,r)rArQcrc32crcr8Zwritebufbufsizeoffset)r3rr%r%r&rPs  zGzipFile._init_writecCs|jd|jdzs   zGzipFile.closecCs4||jtkr0|j|j||jdSr7)r}r rOrTrrr)r3Z zlib_moder%r%r&rQs zGzipFile.flushcCs |jSr7)rTfilenor;r%r%r&rXszGzipFile.filenocCs"|jtkrtd|jddS)NzCan't rewind in write moder)r rLrr.r9r;r%r%r&rewind`s zGzipFile.rewindcCs |jtkSr7)r rLr;r%r%r&readablegszGzipFile.readablecCs |jtkSr7)r rOr;r%r%r&writablejszGzipFile.writablecCsdSr:r%r;r%r%r&r<mszGzipFile.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 modesro)r rOrSEEK_SETSEEK_CURrjrrrangerrLr}r.r9)r3rjwhencecountchunkir%r%r&r9ps         z GzipFile.seekcCs||j|Sr7)r}r.readline)r3r8r%r%r&rszGzipFile.readline)r^)r^)r^)r=r>r?rHrzr6propertyrrVrerPrUrrrrrrrQZ Z_SYNC_FLUSHrrrrrr<rrr9rr%r%r%r&rxs8  I      csZeZdZfddZddZddZddZdd d Zd d ZddZ fddZ Z S)rMcs,tjt|tjtj dd|_d|_dS)N)ZwbitsT)superr6r+rQZ decompressobjrR _new_memberr])r3fp __class__r%r&r6s z_GzipReader.__init__cCstd|_d|_dSrf)rQrg_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)_fprr/EOFError)r3rrrr%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,FrkzNot a gzipped file (%r)z|d|_|jf|j|_|jrf||s`|j |_ dSd|_|j t j}|j||}|jjdkr|j |jjn|jjdkr|j |jj|dkrq|dkrtdq|||j t|7_ |S)Nrr,TFr)readallZ _decompressoreof _read_eofrZ_decomp_factoryZ _decomp_argsrrZ_posZ_sizerrrrrZunconsumed_tailr5Z unused_datar_add_read_datar/)r3r8bufZ uncompressr%r%r&rs:    z_GzipReader.readcCs$t||j|_|jt||_dSr7)rQrgrrr/)r3rr%r%r&rsz_GzipReader._add_read_datacCstd|d\}}||jkrr?r6rrrrrrr __classcell__r%r%rr&rMs ! 3rM)rVc Cs6t}t|d||d}||W5QRX|S)Nwb)rTr r!rV)rBytesIOrrgetvalue)rr!rVrr4r%r%r&rsc Cs0tt|d}|W5QRSQRXdS)Nr)rrrr)rr4r%r%r&rsc Csddlm}|dd}|}|jdddd|jd dd d|jd d dd d|jdddgdd|}t}|jr|t}n |jrt }|j D]}|j r|dkrt ddt jjd}t jj}n>|dddkrt d|t|d}t|ddd}nB|dkr"t jj}t ddt jj|d}nt|d}t|dd}|d}|sPq^||q<|t jjk rt||t jjk r|qdS)Nr)ArgumentParserzeA simple command line interface for the gzip module: act like gzip, but do not delete the input file.)Z descriptionz--fast store_truezcompress faster)actionhelpz--bestzcompress betterz-dz --decompresszact like gunzip instead of gzipargs*-r1)nargsdefaultmetavarrr)rr rTrXrYzfilename doesn't end in .gz: r)rr rTr!r)argparserZadd_mutually_exclusive_group add_argument parse_args_COMPRESS_LEVEL_TRADEOFFZfastr{ZbestrzrrrsysstdinbufferstdoutexitrrGrrr) rparsergrouprr!argr4grr%r%r&main'sR          r__main__) r'rrxrrQrGrZ _compression__all__ZFTEXTrrrvrrLrOr{rrzrr*r+rrZ BaseStreamrZDecompressReaderrMrrrr=r%r%r%r&s8  ,* 0