\d FdZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZ ddlZn #e$rdZYnwxYw ddlZn #e$rdZYnwxYweefZ eefz Zn #e$rYnwxYwgdZdZd Zed zZd Zd Zd Zd Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3e3Z4e"e#e$e%e(e)e*e&e'e+e,e-f Z5e"e#e*e-fZ6e+e,e-fZ7dZ8hd Z9e:e:e:e;e;e;d!Znej?Z>d$Z@d%ZAd&ZBd'e4fd(ZCd)ZDdedfd*ZEd+ZFGd,d-eGZHGd.d/eHZIGd0d1eHZJGd2d3eHZKGd4d5eHZLGd6d7eHZMGd8d9eMZNGd:d;eMZOGd<d=eMZPGd>d?eMZQGd@dAeMZRGdBdCZSGdDdEZTGdFdGeUZVGdHdIeUZWGdJdKe jXZYGdLdMeHZZGdNdOeZZ[GdPdQeZZ\GdRdSeZZ]GdTdUeZZ^GdVdWeZZ_dedYZ`dZZad[Zbd\Zceaebecd]ZdeUZeGd^d_eUZfGd`daeUZgdbZhegjZdcZiejddkr eidSdS)fz,Read from and write to tar format archives. z0.9.0u"Lars Gustäbel (lars@gustaebel.de)u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.)openN)TarFileTarInfo is_tarfileTarError ReadErrorCompressionError StreamError ExtractError HeaderErrorENCODING USTAR_FORMAT GNU_FORMAT PAX_FORMATDEFAULT_FORMATrisustar sustar00d01234567LKSxgX)pathlinkpathsizemtimeuidgidunamegname>r&r-r,r')atimectimer)r*r+r(ntutf-8c|td|||}|d||t|z tzzS)z8Convert a string to a null-terminated bytes object. Nzmetadata cannot contain None) ValueErrorencodelenNUL)slengthencodingerrorss ..\python\lib\tarfile.pystnr<sM y7888 6""A WfW:#a&&C/ //cx|d}|dkr |d|}|||S)z8Convert a null-terminated bytes object to a string. rN)finddecode)r7r9r:ps r;ntsrCs= u ABww bqbE 88Hf % %%r=c||ddvr]d}tt|dz D]}|dz}|||dzz }|ddkrdt|dz z|z }nT t|dd}t|pd d}n#t $rt d wxYw|S) z/Convert a number field to a python number. r)r$rFasciistrict0invalid header)ranger5rCintstripr3InvalidHeaderError)r7nis r;ntirSs  t~ s1vvz""  A !GA 1q5MAA Q45==#a&&1*%)*A 7Aw))AAGGII$a((AA 7 7 7$%566 6 7 Hs )5BB9rGc|}t|}d|cxkr d|dz zkr$nn!td|dz |fzdtz}n|tkrd|dz z |cxkr d|dz zkrfnnc|dkrt dg}nt dg}d|z|z}t |dz D] }|d|dz|dz}!ntd |S) z/Convert a python number to a number field. rrGr$z%0*orIrHrErFzoverflow in number field)rNbytesr6r bytearrayrMinsertr3)rQdigitsformat original_nr7rRs r;itnr[s3J AAA!!!!fqj!!!!!! &FQJ?*G 4 4s : :  36A:#6"6!"Q"Q"Q"Qcfqj>Q"Q"Q"Q"Q"Q 665'""AA5'""Av !Avz""  A HHQE " " " !GAA 3444 Hr=cdttjd|z}dttjd|z}||fS)aCalculate the checksum for a member's header by summing up all characters except for the chksum field which is treated as if it was filled with spaces. According to the GNU tar sources, some tars (Sun and NeXT) calculate chksum with signed char, which will be different if there are chars in the buffer with the high bit set. So we calculate two checksums, unsigned and signed. rH 148B8x356B 148b8x356b)sumstruct unpack_from)bufunsigned_chksum signed_chksums r; calc_chksumsresMC 2< E EFFFO#f0sCCDDDM M ))r=c|pd}|dkrdS|tj|||dSt||\}}t|D]J}||}t ||kr |d||K|dkrH||}t ||kr |d||dS)zjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. i@rNunexpected end of data)shutil copyfileobjdivmodrMreadr5write) srcdstr8 exceptionbufsizeblocks remainderbrbs r;riris"G {{ ~3W---vw//FI 6]]hhw s88g  )455 5 #A~~hhy!! s88i  )455 5 # Fr=cttjdd}|)||d|}t |ddS)Nr9backslashreplace )end)getattrsysstdoutr4rAprint)r7r9s r; _safe_printr|sVsz:t44H HHX1 2 2 9 9( C C !r=ceZdZdZdS)rzBase exception.N__name__ __module__ __qualname____doc__r=r;rrsDr=rceZdZdZdS)r z%General exception for extract errors.Nr~rr=r;r r s//Dr=r ceZdZdZdS)rz&Exception for unreadable tar archives.Nr~rr=r;rrs00Dr=rceZdZdZdS)r z.Exception for unavailable compression methods.Nr~rr=r;r r s88Dr=r ceZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.Nr~rr=r;r r sGGDr=r ceZdZdZdS)r z!Base exception for header errors.Nr~rr=r;r r s++Dr=r ceZdZdZdS)EmptyHeaderErrorzException for empty headers.Nr~rr=r;rr!s&&Dr=rceZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.Nr~rr=r;rr$s**Dr=rceZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.Nr~rr=r;rr's,,Dr=rceZdZdZdS)rPzException for invalid headers.Nr~rr=r;rPrP*s((Dr=rPceZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nr~rr=r;rr-s==Dr=rc*eZdZdZdZdZdZdZdS) _LowLevelFilezLow-level file object. Supports reading and writing. It is used instead of a regular file object for streaming access. ctjtjtjztjzd|}t tdr|tjz}tj||d|_dS)NrwO_BINARYi) osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrrrfd)selfnamemodes r;__init__z_LowLevelFile.__init__:sirz)BJ6    2z " " BK D'$e,,r=c8tj|jdSN)rcloserrs r;rz_LowLevelFile.closeCs r=c6tj|j|Sr)rrkrrr(s r;rkz_LowLevelFile.readFswtw%%%r=c:tj|j|dSr)rrlrrr7s r;rlz_LowLevelFile.writeIs !r=N)rrrrrrrkrlrr=r;rr4sZ ---&&&r=rc\eZdZdZdZdZdZdZdZdZ dZ d Z dd Z d Z d ZdZdS)_StreamaClass that serves as an adapter between TarFile and a stream-like object. The stream-like object only needs to have a read() or write() method and is accessed blockwise. Use of gzip or bzip2 compression is possible. A stream-like object could be for example: sys.stdin, sys.stdout, a socket, a tape device etc. _Stream is intended to be used only internally. cd|_|t||}d|_|dkr#t|}|}|pd|_||_||_||_||_d|_ d|_ d|_ |dkr ddl }n#t$rtd dwxYw||_ |d|_|d kr"||j|_dS|dS|d krs ddl}n#t$rtd dwxYw|d kr.d|_||_t2|_dS||_dS|d krs ddl}n#t$rtddwxYw|d kr.d|_||_|j|_dS||_dS|dkrtd|zdS#|js|jd|_ xYw)z$Construct a _Stream object. TNF*r=rgzzzlib module is not availablerbz2bz2 module is not availablexzlzma module is not availabletarunknown compression type %r) _extfileobjr _StreamProxy getcomptyperrcomptypefileobjrprbposclosedzlib ImportErrorr crc32crc _init_read_gzerrorro_init_write_gzrdbufBZ2DecompressorcmpOSError BZ2CompressorlzmaLZMADecompressor LZMAErrorLZMACompressorr) rrrrrrprrrs r;rz_Stream.__init__Ws  ?#D$//G$D  s??#7++G**,,H        - 4UKKKK"UUU*+IJJPTTU  ::c??3;;&&(((%)ZDNNN'')))))U""TJJJJ"TTT*+HIItST3;; #DI"2244DH%,DNNN"0022DHHHT!!UKKKK"UUU*+IJJPTTU3;; #DI#4466DH%)^DNNN#2244DHHHU""&'Dx'OPPP#" # % ""$$$DK syH BHB,,A H8HHDHD555H,HHFHF..5H%HH*Icdt|dr|js|dSdSdS)Nr)rrrrs r;__del__z_Stream.__del__sB 4 " " 4;  JJLLLLL    r=c@|jd|jj|jj |jjd|_t jdttj }| d|zdz|j dr|j dd|_ tj|j |_ | |j d d t"zdS) z6Initialize for writing with gzip compression. r-1Y-@,@,0I,C,-//Kc$)++&6&677  (94{BCCC 9  e $ $ ' #2#DIG$$TY//  TY%%lI>>DEEEEEr=c|jdkr%|j||j|_|xjt |z c_|jdkr|j|}||dS)z&Write string s to the stream. rrN) rrrrrr5rcompressrrs r;rlz _Stream.writesu =D yq$(33DH CFF =E ! !!!!$$A Qr=c(|xj|z c_t|j|jkrd|j|jd|j|j|jd|_t|j|jkbdSdS)z]Write string s to the stream if a whole new block is ready to be written. N)rbr5rprrlrs r;__writez_Stream.__writes A $(mmdl** L  tx  6 7 7 7x .DH$(mmdl******r=c|jrdSd|_ |jdkr2|jdkr'|xj|jz c_|jdkr|jr|j|jd|_|jdkrg|jtj d|j |jtj d|j dz|j s|j dSdS#|j s|j wwxYw) z[Close the _Stream object. No operation should be done on it afterwards. NTrrr=rrl)rrrrbrflushrrlr`rrrrrrs r;rz _Stream.closes: ;  F  %yCDMU$:$:DHNN,,,yCDH ""48,,,=D((L&&v{4'B'BCCCL&&v{4J9N'O'OPPP# % ""$$$$$ % %4# % ""$$$$ %s C'D#Ec|j|jj |_d|_|ddkrt d|ddkrtdt|d}|d|d zr]t|dd t|dzz}| ||d zr% |d}|r |tkrn$|d zr% |d}|r |tkrn$|dzr|ddSdS)z:Initialize for reading a gzip compressed fileobj. r=r%snot a gzip filer$zunsupported compression methodrHrGTN) r decompressobjrrr _Stream__readrr ordrkr6)rflagxlenr7s r;rz_Stream._init_read_gzs9**DI,?+?@@  ;;q>>[ ( (-.. . ;;q>>W $ $"#CDD D4;;q>>"" A !8 t{{1~~&&s4;;q>>/B/B)BBD IIdOOO !8  KKNNAHH  "9  KKNNAHH  !8  KKNNNNN  r=c|jS)z3Return the stream's file pointer position. )rrs r;tellz _Stream.tells xr=rc||jz dkrbt||jz |j\}}t|D]}||j||nt d|jS)zXSet the stream's file pointer to pos. Negative seeking is forbidden. rz seeking backwards is not allowed)rrjrprMrkr )rrrqrrrRs r;seekz _Stream.seeks >Q   &sTX~t| D D FI6]] ( ( $,'''' IIi @AA Axr=cr|J||}|xjt|z c_|S)z5Return the next size number of bytes from the stream.)_readrr5)rr(rbs r;rkz _Stream.read s:jj CHH r=c(|jdkr||St|j}|jg}||kr|jr|j}d|_n"|j|j}|snk |j |}n"#|j $r}td|d}~wwxYw| ||t|z }||kd |}||d|_|d|S)z+Return size bytes from the stream. rr=zinvalid compressed dataN)rrr5rrbrrkrpr decompressrorappendjoin)rr(ctrbes r;rz _Stream._reads' =E ! !;;t$$ $  NN YK$hhx hl'' 55 Bh))#..> B B B 9::A B HHSMMM SMA$hh HHQKKdeeH $xs<B B6!B11B6c@t|j}|jg}||krO|j|j}|sn-|||t|z }||kOd|}||d|_|d|S)zsReturn size bytes from stream. If internal buffer is empty, read another block from the stream. r=N)r5rbrrkrprr)rr(rrrbs r;__readz_Stream.__read-s MM XJ$hh,##DL11C  HHSMMM SMA $hh HHQKKTUU8$xr=N)r)rrrrrrrrlrrrrrrkrrrr=r;rrLsDDDLFFF ///%%%,>    6r=rc*eZdZdZdZdZdZdZdS)rzsSmall proxy class that enables transparent compression detection for the Stream interface (mode 'r|*'). c\||_|jt|_dSr)rrk BLOCKSIZErb)rrs r;rz_StreamProxy.__init__Cs$ <$$Y//r=c2|jj|_|jSr)rrkrbrs r;rkz_StreamProxy.readGsL% xr=c|jdrdS|jdddkr|jdddkrd S|jd rd Sd S) NsrrsBZhr s1AY&SYr)s]s7zXZrr)rb startswithrs r;rz_StreamProxy.getcomptypeKsp 8   / / 4 Xac]f $ $!B$9)D)D5 X !C D D 45r=c8|jdSr)rrrs r;rz_StreamProxy.closeUs r=N)rrrrrrkrrrr=r;rr>sZ000r=rc`eZdZdZd dZdZdZdZdZdZ e j fd Z d d Z d Zd ZdS) _FileInFilezA thin wrapper around an existing file object that provides a part of its data as an individual file object. Nc||_||_||_d|_t |dd|_d|_|d|fg}d|_g|_d}|j}|D]T\}}||kr|j d||df|j d|||z|f||z }||z}U||jkr%|j d||jdfdSdS)NrrFT) roffsetr(positionrxrr map_indexmapr)rrr r( blockinfolastposrealposs r;rz_FileInFile.__init__bs    GVT22   T I+% $ $LFD >??? HOOT66D='B C C C tOGtmGG TY   HOOUGTY= > > > > >  r=cdSrrrs r;rz_FileInFile.flush{s r=cdSNTrrs r;readablez_FileInFile.readable~str=cdSNFrrs r;writablez_FileInFile.writablesur=c4|jSr)rseekablers r;rz_FileInFile.seekables|$$&&&r=c|jS)z*Return the current file position. )rrs r;rz_FileInFile.tell }r=c|tjkr)tt|d|j|_n|tjkrG|dkrt|j|zd|_nst|j|z|j|_nP|tjkr1tt|j|z|jd|_ntd|jS)z(Seek to a position in the file. rzInvalid argument) ioSEEK_SETminmaxr(rSEEK_CURSEEK_ENDr3)rrwhences r;rz_FileInFile.seeks R[ Ha 0 0$)< r=r ceZdZfdZxZS) ExFileObjectct|j|j|j|j}t |dSr)r r offset_datar(sparsesuperr)rtarfiletarinfor __class__s r;rzExFileObject.__init__sBgow/B gn.. !!!!!r=rrrr __classcell__r6s@r;r/r/s8"""""""""r=r/ceZdZdS) FilterErrorN)rrrrr=r;r;r;sDr=r;ceZdZfdZxZS)AbsolutePathErrorcj||_td|jddS)Nzmember z has an absolute pathr5r3rrrr5r6s r;rzAbsolutePathError.__init__s6  H7<HHHIIIIIr=r7r9s@r;r=r=sAJJJJJJJJJr=r=ceZdZfdZxZS)OutsideDestinationErrorc||_||_t|jd|ddzdS)Nz would be extracted to , which is outside the destinationr5_pathr3rrrr5r&r6s r;rz OutsideDestinationError.__init__sT   GLMM4MMM=> ? ? ? ? ?r=r7r9s@r;rBrB8?????????r=rBceZdZfdZxZS)SpecialFileErrorch||_t|jddS)Nz is a special filer?r@s r;rzSpecialFileError.__init__s3  GL>>>?????r=r7r9s@r;rKrKsA@@@@@@@@@r=rKceZdZfdZxZS)AbsoluteLinkErrorch||_t|jddS)Nz! is a symlink to an absolute pathr?r@s r;rzAbsoluteLinkError.__init__s3  GLMMMNNNNNr=r7r9s@r;rNrNsAOOOOOOOOOr=rNceZdZfdZxZS)LinkOutsideDestinationErrorc||_||_t|jd|ddzdS)Nz would link to rDrErFrHs r;rz$LinkOutsideDestinationError.__init__sT   GLEE4EEE=> ? ? ? ? ?r=r7r9s@r;rQrQrIr=rQTc^i}|j}tj|}|dtjfr,|jdtjzx}|d<tj|rt|tjtj ||}tj ||g|krt|||j }||dz}|rr| s|r|dzs|dz}|dz}n:|s|rd}nt#|||j kr||d<|r|jd|d<|jd|d <|jd|d <|jd|d <|s|rtj|jrt/|tjtj ||j}tj ||g|krt1|||S) N/ri@irr*r+r,r-)rrr&realpathrseplstripisabsr=r commonpathrBrisregislnkisdirissymrKr*r+r,r-linknamerNrQ)member dest_pathfor_data new_attrsr target_pathrs r;_get_filtered_attrsrfsI ;D  ++I RV}%%D#);#5#5cBFl#C#CCy  w}}T( ''''""27<< 4#@#@AAK w; 233y@@%fk::: ;D e|  /||~~ / /e|#FND  /6<<>> /'v... 6;   $If G : !#Ie  : !#Ie  < #!%Ig  < #!%Ig  <<>> GV\\^^ Gw}}V_-- 0'///'**27<< 6?+S+STTKw!!; ":;;yHH1&+FFF r=c|Srr)rarbs r;fully_trusted_filterrh)s Mr=cNt||d}|r|jdi|ddiS|S)NFdeeprrfrrarbrds r; tar_filterrm,sC#FIu==I7v~66 666666 Mr=cNt||d}|r|jdi|ddiS|S)NTrjFrrkrls r; data_filterro2sC#FIt<Zed?Zd@ZdAZ dBZ!dCZ"dDZ#dEZ$dFZ%dGZ&dHZ'dIZ(dJZ)dKZ*dLZ+dMZ,dNZ-dOZ.dPZ/dQZ0dRZ1dSZ2dTZ3d%S)WraInformational class which holds the details about an archive member given by a tar header block. TarInfo objects are returned by TarFile.getmember(), TarFile.getmembers() and TarFile.gettarinfo() and are usually created internally. rzName of the archive member.rzPermission bits.r*z6User ID of the user who originally stored this member.r+z7Group ID of the user who originally stored this member.r(zSize in bytes.r)zTime of last modification.chksumzHeader checksum.typezFile type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.r`zcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.r,z User name.r-z Group name.devmajorzDevice major number.devminorzDevice minor number.r zThe tar header starts here.r1zThe file's data starts here. pax_headerszMA dictionary containing key-value pairs of an associated pax extended header.r2zSparse member information.r4N_sparse_structs _link_targetrc||_d|_d|_d|_d|_d|_d|_t|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_i|_dS)zXConstruct a TarInfo object. name is the optional name of the member. irrN)rrr*r+r(r)rrREGTYPErsr`r,r-rtrur r1r2rvrrs r;rzTarInfo.__init__hs             r=c|jS)z(In pax headers, "name" is called "path".rrs r;r&z TarInfo.paths yr=c||_dSrr}r{s r;r&z TarInfo.paths  r=c|jS)z0In pax headers, "linkname" is called "linkpath".r`rs r;r'zTarInfo.linkpathrr=c||_dSrr)rr`s r;r'zTarInfo.linkpaths   r=cJd|jj|jt|fzS)Nz<%s %r at %#x>)r6rridrs r;__repr__zTarInfo.__repr__s!4>#:49RXX"NNNr=T) rr)rr`r*r+r,r-rj_KEEPc  | rtj|} ntj|} || ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _ | S)zGReturn a deep copy of self with the given attributes replaced. ) copydeepcopyrr)rr`r*r+r,r-) rrr)rr`r*r+r,r-rjrresults r;rzTarInfo.replaces  %]4((FFYt__F u  FK    FL u  FK 5 &FO e  FJ e  FJ    FL    FL r=c>|jd}n |jdz}|j||j|j|j|j|j|j|j|j |j |j |j d }|dtkr+|dds|dxxdz cc<|S)z9Return the TarInfo's attributes as a dictionary. N) rrr*r+r(r)rrrsr`r,r-rtrursrrT)rrr*r+r(r)rrrsr`r,r-rtruDIRTYPEr)rrinfos r;get_infozTarInfo.get_infos 9 DD9v%D             <7 " "4<+@+@+E+E " LLLC LLL r=surrogateescapecn|}|D]\}}|td|z|tkr||||S|t kr||||S|tkr|||Std)z >KD%} !5!<=== \ ! !++D(FCC C z ! !))$&AA A z ! !))$99 9-.. .r=ct|d<t|d||tkrt dt|d||t kr&||d||\|d<|d<||t||S)z3Return the object as a ustar header block. magicr`zlinkname is too longrprefix) POSIX_MAGICr5r4 LENGTH_LINKr3 LENGTH_NAME_posix_split_name_create_headerr)rrr9r:s r;rzTarInfo.create_ustar_headers$W tJ&&x88 9 9K G G344 4 tF|""8V44 5 5 C C+/+A+A$v,PXZ`+a+a (DNDL""4xHHHr=ct|d<d}t|d||tkr&|||dt ||z }t|d||t kr&|||dt||z }|||t||zS)z:Return the object as a GNU header block sequence. rr=r`r) GNU_MAGICr5r4r_create_gnu_long_headerGNUTYPE_LONGLINKrGNUTYPE_LONGNAMErr)rrr9r:rbs r;rzTarInfo.create_gnu_headers"W  tJ&&x88 9 9K G G 4//Z0@BRT\^dee eC tF|""8V44 5 5 C C 4//V >NPXZ`aa aCT((z8VLLLLr=ct|d<|j}ddtfddtfddfD]h\}}}||vr ||dd n#t $r||||<Y@wxYwt|||kr ||||<id D]u\}}d }||} t| t} | rt| n| } d | cxkr d |dz zks nd ||<d}n | r| ||<d}|r||vrt| ||<v|r| |t|} nd} | ||tddzS)zReturn the object as a ustar header block. If it cannot be represented this way, prepend a pax extended header sequence with supplement information. rrr&r`r')r,r, )r-r-rrIrJ))r*rG)r+rG)r( )r)rFrrGr$Tr=r)rrvrrrr4UnicodeEncodeErrorr5 isinstancefloatroundstr_create_pax_generic_headerXHDTYPErr) rrr9rvrhnamer8rX needs_paxval val_is_floatval_intrbs r;rzTarInfo.create_pax_headers $W &++-- - J /T&(>$@ 0 0 D% ## T !!'84444%   %)$Z E" 4:''%)$Z E"R - -LD&It*C%c511L$09eCjjjcG3333! "33333T   !%T   -T44$'HH D!  11+wQQCCCT((|WiPPPPsA##A;:A;c:||tdS)zAReturn the object as a pax global header block sequence. r1)rXGLTYPE)clsrvs r;create_pax_global_headerz TarInfo.create_pax_global_header3s--k7GLLLr=c|d}tdt|D]}d|d|}d||d}t|||t kr.t|||t krntd||fS)zUSplit a name longer than 100 chars into a prefix and a name part. rTr$Nzname is too long)splitrMr5rr4 LENGTH_PREFIXrr3)rrr9r: componentsrRrs r;rzTarInfo._posix_split_name9sZZ__ q#j//** 1 1AXXj!n--F88JqrrN++D6==62233}DD Hf5566+EE/00 0t|r=c|dttfv}|rKt|ddd|}t|ddd|}n$t dd||}t dd||}|dt }|t dt |d dd ||t|d dd zd|t|d dd|t|ddd|t|ddd|t|ddd|d|t |ddd |||dtt |ddd||t |ddd||||t |ddd||g}tj dtzd |} t| t dd} | ddtd| zdz| ddz} | S) zReturn a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants. rsrtrrGrurNzTarInfo.type must not be Nonerrrrr*r+r(rr)s r`rr,rr-rrz%dsr=iz%06orIi)getCHRTYPEBLKTYPEr[r<rzr3rr`rrrrerU) rrYr9r:has_device_fieldsrtrufiletypepartsrbrrs r;rzTarInfo._create_headerIs !HHV,,'0BB  4488J22Av>>H488J22Av>>HH2q(F33H2q(F33H88FG,,  <== = $$c8V < < ##f,a 8 8 ""Av . . ""Av . . ##R 0 0 !$$b& 1 1   R((#x @ @ HHWk * * "%%r8V < < "%%r8V < <   2&&Xv > > $k%)+SXXe__==c9*++.//2%4%j5F!2G<<EMPUU UGG'V V 7||V #W !!$ gyII##G,,- -s4 AAct|dkrtdt|tkrtd|t tkrt dt|dd}|t|vrtd|}t|dd|||_ t|dd |_ t|d d |_ t|d d |_t|d d |_t|d d|_||_|dd |_t|d d|||_t|dd|||_t|dd|||_t|dd|_t|dd|_t|dd||}|jt0kr&|j dr t4|_|jt6krd}g}t9dD]h} t|||dz} t||dz|dz} n#t:$rYn!wxYw|| | f|dz }it?|d} t|dd} || | f|_ |!r|j "d|_ |r |jtFvr|dz|j z|_ |S)zAConstruct a TarInfo object from a 512 byte bytes object. rz empty headerztruncated headerzend of file headerz bad checksumrlt|ii i)iIiQiYirTirriii)$r5rrrcountr6rrSrerPrCrrr*r+r(r)rrrsr`r,r-rtruAREGTYPErrGNUTYPE_SPARSErMr3rboolrwr^rstrip GNU_TYPES)rrbr9r:rrobjrrstructsrRr numbytes isextendedorigsizes r;frombufzTarInfo.frombufsF s88q==">22 2 s88y &'9:: : 99S>>Y & & !566 6SS\"" c** * *$^44 4cees1S5z8V44s3s7|$$c#c'l##c#c'l##s3s7|$$CG %%  s3w<3s3w<6:: CG h77 CG h77 3s3w<(( 3s3w<(( SS\8V44 8x  CH$5$5c$:$: CH 8~ % %CG1XX   Sr\!233F"3sRxb'8#9::HH!EE1222r c#hJ3s3w<((H#*J"AC  99;; ,xs++CH  /chi//|ch.CH s7J<< K  K c|jt}|||j|j}|jtz |_||S)zOReturn the next TarInfo object from TarFile object tarfile. ) rrkrrr9r:rr  _proc_member)rr4rbrs r; fromtarfilezTarInfo.fromtarfilesa o""9--kk#w/@@_))++i7 (((r=c*|jttfvr||S|jtkr||S|jt ttfvr| |S| |S)zYChoose the right processing method depending on the type and call it. ) rsrr _proc_gnulongr _proc_sparserrSOLARIS_XHDTYPE _proc_pax _proc_builtin)rr4s r;rzTarInfo._proc_members 9)+;< < <%%g.. . Y. ( ($$W-- - Y7G_= = =>>'** *%%g.. .r=c|j|_|j}|s|jt vr|||jz }||_| |j |j |j | r|jd|_|S)zfProcess a builtin type or an unknown type which will be treated as a regular file. rT)rrr1r\rsSUPPORTED_TYPES_blockr(r _apply_pax_inforvr9r:r^rr)rr4r s r;rzTarInfo._proc_builtin"s#?//11! ::<< -49O;; dkk$),, ,F W0'2BGNSSS ::<< . ((--DI r=c6|j||j} ||}n/#t $r"}t t|dd}~wwxYw|j|_|j tkr!t||j |j |_n0|j tkr t||j |j |_|r|jd|_|S)zSProcess the blocks that hold a GNU longname or longlink member. NrT)rrkrr(rr rrr rsrrCr9r:rrr`r^ removesuffix)rr4rbnextrs r;rzTarInfo._proc_gnulong8so""4;;ty#9#9:: :##G,,DD : : :'A//T 9 : k 9( ( (C!17>BBDII Y* * *W%5w~FFDM ::<< 4 ..s33DI sA A6A11A6c2|j\}}}|`|r|jt}d}t dD]l} t |||dz}t ||dz|dz} n#t $rYn%wxYw|r| r||| f|dz }mt|d}|||_ |j |_ |j | |j z|_||_ |S)z8Process a GNU sparse header plus extra headers. rrri)rwrrkrrMrSr3rrr2rr1rr(r ) rr4rrrrbrrRr rs r;rzTarInfo._proc_sparseSsF)-(<%X   (/&&y11CC2YY   Sr\!233F"3sRxb'8#9::HH!EE7h7NNFH#5666r c#hJ ( "?//11)DKK ,B,BB  s7A;; B B cv|j||j}|jt kr|j}n|j}tj d|}|+| d d|d<| d}|dkr|j }nd}tjd}d} |||}|sn|\} } t#| } | dkrt%d ||d dz|d| zdz } || dd|j} | t.vr#|| ||j |j} n|| dd|j} | || <|| z } ||} n/#t2$r"} t5t7| dd} ~ wwxYwd |vr|| |ned |vr|| ||nI| ddkr0| ddkr|| |||jt>t@fvr~| !||j |j|j"| _"d|vrM| j#}| $s| jtJvr|| | jz }||_"| S)zVProcess an extended or global header as described in POSIX.1-2008. s\d+ hdrcharset=([^\n]+)\nNr$r1 hdrcharsetBINARYs(\d+) ([^=]+)=rTrLr%GNU.sparse.mapGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrKr()&rrkrr(rsrrvrresearchgrouprArr9compilematchgroupsrNrPrwr)_decode_pax_fieldr:PAX_NAME_FIELDSrr rr_proc_gnusparse_01_proc_gnusparse_00_proc_gnusparse_10rrrr r1r\r)rr4rbrvrrr9regexrr8rrrrr s r;rzTarInfo._proc_paxos[ o""4;;ty#9#9:: 9  !-KK!-2244K 7==  (- A(=(=g(F(FK % !__\22  ! !'HHH  -.. KKS))E #llnnOFG[[F{{()9::: ! q(Q&)@1)DDEE,,WgwN$$G/))..uh@P((..ugw(($)K 6MC9 > :##G,,DD : : :'A//T 9 : { * *  # #D+ 6 6 6 6 + - -  # #D+s ; ; ; ; __/ 0 0C 7 7KOOL^<_<_cf O O O+DK$$)::<<549O#C#Cdkk$)444F!' s!G77 H#HH#cg}tjd|D]7}|t|d8g}tjd|D]7}|t|d8t t |||_dS)z?Process a GNU tar extended sparse header, version 0.0. s\d+ GNU.sparse.offset=(\d+)\nr$s\d+ GNU.sparse.numbytes=(\d+)\nN)rfinditerrrNrlistzipr2)rrrvrboffsetsrrs r;rzTarInfo._proc_gnusparse_00s[!BCHH 0 0E NN3u{{1~~.. / / / /[!DcJJ 1 1E OOC A// 0 0 0 03w1122 r=c d|ddD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1. c,g|]}t|Sr)rN).0xs r; z.TarInfo._proc_gnusparse_01..sKKKQ#a&&KKKr=r,Nr%r$)rr r r2)rrrvr2s r;rzTarInfo._proc_gnusparse_01s]LK+.>"?"E"Ec"J"JKKK3vccc{F14a4L99:: r=c Zd}g}|jt}|dd\}}t |}t ||dzkrwd|vr"||jtz }|dd\}}|t |t ||dzkw|j|_tt|ddd|ddd|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Nrr$r%) rrkrrrNr5rrr1r r r2)rrrvr4fieldsr2rbnumbers r;rzTarInfo._proc_gnusparse_10so""9--iiq)) V&kkFQJ&&Cw++I666))E1--KFC MM#f++ & & & &kkFQJ&& #?//113vccc{F14a4L99:: r=c|D]\}}|dkrt|d||dkrt|dt|B|dkrt|dt|g|tvr^|tvr) t ||}n#t $rd}YnwxYw|dkr|d}t|||||_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namer&rr(zGNU.sparse.realsizerrTN) rsetattrrN PAX_FIELDSPAX_NUMBER_FIELDSr3rrrv)rrvr9r:rrs r;rzTarInfo._apply_pax_infos/*//11 . .NGU+++fe,,,,---fc%jj1111111fc%jj1111J&&///" 1' :5 A A%""" !"f$$!LL--Egu---&++--sB%% B43B4c| ||dS#t$r|||cYSwxYw)z1Decode a single field from a pax record. rJ)rAUnicodeDecodeError)rrr9fallback_encodingfallback_errorss r;rzTarInfo._decode_pax_fieldsV D<<(33 3! D D D<< 1?CC C C C Ds  ;;cTt|t\}}|r|dz }|tzS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. r$)rjr)rrrqrrs r;rzTarInfo._blocks4#5)44   aKF !!r=c|jtvSz4Return True if the Tarinfo object is a regular file.)rs REGULAR_TYPESrs r;r\z TarInfo.isreg syM))r=c*|Sr)r\rs r;isfilezTarInfo.isfile$szz||r=c"|jtkS)z!Return True if it is a directory.)rsrrs r;r^z TarInfo.isdir(yG##r=c"|jtkS)z%Return True if it is a symbolic link.)rsSYMTYPErs r;r_z TarInfo.issym,r$r=c"|jtkS)z!Return True if it is a hard link.)rsLNKTYPErs r;r]z TarInfo.islnk0r$r=c"|jtkS)z(Return True if it is a character device.)rsrrs r;ischrz TarInfo.ischr4r$r=c"|jtkS)z$Return True if it is a block device.)rsrrs r;isblkz TarInfo.isblk8r$r=c"|jtkS)zReturn True if it is a FIFO.)rsFIFOTYPErs r;isfifozTarInfo.isfifo<syH$$r=c|jduSr)r2rs r;issparsezTarInfo.issparse@s{$&&r=c8|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)rsrrr.rs r;isdevz TarInfo.isdevCsyWgx888r=r)r)4rrrrdict __slots__rpropertyr&setterr'rrrrrr rrrr classmethodrr staticmethodrrrrrrrrrrrrrrrrrr\r"r^r_r]r*r,r/r1r3rr=r;rrEs{   ,, !! GF HG     -,  $# >> FF     *) *)! "/.# $54% &99' *.-+ ,$- .$/ 0t1 I60X [[X_!!_!OOO%eeuE88*HEV////" I I I M M M8Q8Q8QtMM[M  ''\'R\**[* 0-0-[0-d<<[<|))[)( / / /,68fffP 3 3 3;;; ;;; ....DDD"""***$$$$$$$$$$$$$$$%%%'''99999r=rceZdZdZdZdZdZdZeZ e Z dZ e ZeZdZ d=dZedddefd Zed>d Zed?d Zed?d Zed@dZdddddZdZdZdZdZdAdZdBdddZ dCdddZ!dDdZ"dZ#dEddd!d"Z$dFddd!d$Z%d%Z&d&Z'd'Z(d(Z)d)Z* dGd*Z+d+Z,d,Z-d-Z.d.Z/d/Z0d0Z1d1Z2d2Z3d3Z4d4Z5dHd5Z6d6Z7dDd7Z8d8Z9d9Z:d:Z;d;Z;AL&4IL&)J0L&2 J;JJBL&&*Mc |s|std|dvrՈfd}g}tj|D]}tj|} ||} | |d|fi|cS#t t f$r<} |d|d| ||| Yd} ~ d} ~ wwxYwd |} t d | d |vrc| d d \} }| pd} |pd }|jvrtj|} nt d|z| || |fi|Sd|vrw| dd \} }| pd} |pd }| dvrtdt|| |||} || |fi|}n#| xYwd|_ |S|dvrj|||fi|Std)aOpen a tar archive for reading, writing or appending. Return an appropriate TarFile class. mode: 'r' or 'r:*' open for reading with transparent compression 'r:' open for reading exclusively uncompressed 'r:gz' open for reading with gzip compression 'r:bz2' open for reading with bzip2 compression 'r:xz' open for reading with lzma compression 'a' or 'a:' open for appending, creating the file if necessary 'w' or 'w:' open for writing without compression 'w:gz' open for writing with gzip compression 'w:bz2' open for writing with bzip2 compression 'w:xz' open for writing with lzma compression 'x' or 'x:' create a tarfile exclusively without compression, raise an exception if the file is already created 'x:gz' create a gzip compressed tarfile, raise an exception if the file is already created 'x:bz2' create a bzip2 compressed tarfile, raise an exception if the file is already created 'x:xz' create an lzma compressed tarfile, raise an exception if the file is already created 'r|*' open a stream of tar blocks with transparent compression 'r|' open an uncompressed stream of tar blocks for reading 'r|gz' open a gzip compressed stream of tar blocks 'r|bz2' open a bzip2 compressed stream of tar blocks 'r|xz' open an lzma compressed stream of tar blocks 'w|' open an uncompressed stream for writing 'w|gz' open a gzip compressed stream for writing 'w|bz2' open a bzip2 compressed stream for writing 'w|xz' open an lzma compressed stream for writing znothing to open)rr:*c&j|dkS)Ntaropen) OPEN_METH)rrs r;not_compressedz$TarFile.open..not_compresseds}X.);;r=)keyNrz - method z:  z'file could not be opened successfully: :r$rr|rzmode must be 'r' or 'w'FrBzundiscernible mode)r3sortedrUrxrrr rrrrrrrrT)rrrrrpkwargsrV error_msgsrfunc saved_posrerror_msgs_summaryfilemodestreamrs` r;rz TarFile.opensJ 0G 0.// / <   < < < < <J"3=nEEE  sCM($;<<& ' I4c7==f=====!#34%%&C(&C&Ca&C&CDDD* Y///HHHH  "&:!6!6 [GY[[\\ \ D[[!%C!3!3 Hh3H(5H3=((sCM($;<<&'Dx'OPPP4h::6:: : D[[!%C!3!3 Hh3H(5Hz)) !:;;;T8XwHHF Ch99&99  !AMH _ $ $3;tT7==f== =-...s$* A77C2B??C! F--Gc >|dvrtd||||fi|S)zCOpen uncompressed tar archive name for reading or writing. r?rA)r3)rrrrr\s r;rTzTarFile.taropen1s; + + +@AA As4w11&111r=rc |dvrtd ddlm}n#t$rt ddwxYw |||dz||}n+#t $r}||dkrt d |d}~wwxYw |j|||fi|}nR#t $r0}||dkrt d |d}~w|xYwd |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rrrmode must be 'r', 'w' or 'x'r)GzipFilezgzip module is not availableNrsrrF) r3gziprgrr rrrTrr) rrrr compresslevelr\rgrrs r;gzopenzTarFile.gzopen9sS  & &;<< < M % % % % % % % M M M"#ABB L M htTCZHHGG   "ts{{ 1229    D$::6::AA    MMOOOs{{ 1229   MMOOO  s77A A5A00A59B C+B??Cc ||dvrtd ddlm}n#t$rt ddwxYw||p|||} |j|||fi|}nY#t tf$r0}||dkrtd |d}~w|xYwd |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rerfr)BZ2FilerN)rirznot a bzip2 fileF) r3rrlrr rTrEOFErrorrrr) rrrrrir\rlrrs r;bz2openzTarFile.bz2openZs  & &;<< < L # # # # # # # L L L"#@AAt K L''/T4}MMM  D$::6::AA"    MMOOOs{{ 233:   MMOOO  s 7 AB2-+BB2c v|dvrtd ddlm}m}n#t$rt ddwxYw||p|||} |j|||fi|}nT#|tf$r0} ||dkrtd | d} ~ w|xYwd |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rerfr)LZMAFilerrN)presetrznot an lzma fileF) r3rrprrr rTrmrrr) rrrrrqr\rprrrs r;xzopenzTarFile.xzopenvs  & &;<< < M 0 0 0 0 0 0 0 0 0 M M M"#ABB L M(7?dD@@@  D$::6::AA8$    MMOOOs{{ 233:   MMOOO  s 9 A B/*+BB/rTrjrnrr)rrrrc|jrdSd|_ |jdvr|jtt dzz|xjt dzz c_t|jt\}}|dkr*|jtt|z z|j s|j dSdS#|j s|j wwxYw)zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTrBr%r) rrrrlr6rr rj RECORDSIZErr)rrqrrs r;rz TarFile.closes ;  F  %yO++ ""3)a-#8999 A . %+4; $C$C! q==L&&sj9.D'EFFF# % ""$$$$$ % %4# % ""$$$$ %s BC#C1c~||d}|td|z|S)aReturn a TarInfo object for member `name'. If `name' can not be found in the archive, KeyError is raised. If a member occurs more than once in the archive, its last occurrence is assumed to be the most up-to-date version. rTNzfilename %r not found) _getmemberrKeyError)rrr5s r; getmemberzTarFile.getmembers? //$++c"2"233 ?2T9:: :r=cn||js||jS)zReturn the members of the archive as a list of TarInfo objects. The list has the same order as the members in the archive. )_checkrM_loadrLrs r; getmemberszTarFile.getmemberss0 |  JJLLL|r=c>d|DS)zReturn the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). cg|] }|j Srr})rr5s r;rz$TarFile.getnames..s>>> >>>r=)r|rs r;getnameszTarFile.getnamess"?>DOO,=,=>>>>r=c|d||j}||}tj|\}}|tjd}|d}|}||_ |1|j stj |}n;tj |}n&tj |}d}|j}tj|ri|j|jf} |j s:|jdkr/| |jvr&||j| krt*} |j| }nt,} | dr ||j| <ntj|rt0} ntj|rt4} njtj|rt8} tj|}n:tj|rt>} ntj |rtB} ndS||_||_"|j#|_$|j%|_&| t,kr |j'|_(nd|_(|j)|_*| |_+||_,tZr6 t[j.|j$d|_/n#t`$rYnwxYwtbr6 tcj2|j&d|_3n#t`$rYnwxYw| t>tBfvrftitdrQtitdr zlink to )rzrr|rrar,r*r-r+r*r,rtrur(r)r localtimerr^r_r`r]r{)rverboserLr5s r;r z TarFile.list0s ?G  G E<' ---- gl ; ;<<<w}'C 'C'C'.}'C 'CEFFF==??7gmmoo7$(8':J'KK!MNNNN  5666=( 56666 ="&."?"?"C!DEEE  w}}(FBG H H H ?==??:(8 8999==??? W-= =>>> GGGG5  r=filterc|d||}|jCtj||jkr|dd|zdS|d||||}||dd|zdS|(||}||dd|zdS|rAt|d5}| ||ddddS#1swxYwYdS| r| ||ryttj |D]Y}| tj||tj|||| XdSdS| |dS) a!Add the file `name' to the archive. `name' may be any type of file (directory, fifo, symbolic link, etc.). If given, `arcname' specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by setting `recursive' to False. `filter' is a function that expects a TarInfo object argument and returns the changed TarInfo object, if it returns None the TarInfo object will be excluded from the archive. rNr%ztarfile: Skipped %rr$ztarfile: Unsupported type %rtarfile: Excluded %rr<r)rzrrr&rF_dbgrr\rEaddfiler^r[listdiraddr)rrr recursiverr5fs r;rz TarFile.addVsD E ?G 9 RW__T%:%:di%G%G IIa.5 6 6 6 F !T//$00 ? IIa7$> ? ? ? F  fWooG !3d:;;; ==?? "4&& )! Wa((( ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )]]__ " LL ! ! ! 6 4 0 01166AHHRW\\$22BGLL!4L4L%f6666 6 666 LL ! ! ! ! !s;DD#&D#cf|dtj|}||j|j|j}|j||xjt|z c_|j }|t||j|j |t|j t\}}|dkr/|jtt|z z|dz }|xj|tzz c_|j|dS)aAdd the TarInfo object `tarinfo' to the archive. If `fileobj' is given, it should be a binary file, and tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects directly, or by using gettarinfo(). rN)rprr$)rzrrrYr9r:rrlr r5rKrir(rjrr6rLr)rr5rrbrprqrrs r;rzTarFile.addfiles E)G$$mmDK DD 3 s3xx     w|W M M M M &w|Y ? ? FI1}} ""3)i*?#@AAA!  KK6I- -KK G$$$$$r=c|6|j}|tSt|trt d|St |r|S t |S#t$rtd|ddwxYw)NzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z not found) extraction_filterrhrr TypeErrorcallable_NAMED_FILTERSrwr3)rrs r;_get_filter_functionzTarFile._get_filter_functions >+F~++&#&& 76777M F   M G!&) ) G G G;v;;;<<$ F Gs AA7.) numeric_ownerrcg}||}||}|D]q}||||}||r|||||| |r|dd|D]}t j||j } | || || || | || m#t$r} || Yd} ~ d} ~ wwxYwdS)aExtract all members from the archive to the current working directory and set owner, modification time and permissions on directories afterwards. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by getmembers(). If `numeric_owner` is True, only the numbers for user/group names are used and not the names. The `filter` function will be called on each member just before extraction. It can return a changed TarInfo or None to skip the member. String names of common filters are accepted. N set_attrsrc|jSrr})r@s r;z$TarFile.extractall..sqvr=T)rWreverse)r)r_get_extract_tarinfor^r _extract_onesortrr&rrchownutimechmodr _handle_nonfatal_error) rr&rLrr directoriesfilter_functionrar5dirpathrs r; extractallzTarFile.extractalls 33F;; ?G ; ;F//NNG}} ,""7+++   gt7==??7J,9  ; ; ; ; --t<<<# / /Ggll466G / 7G= III 7G,,, 7G,,,, / / /++A........ /  / /sAD E!D;;Erc||}||||}||||||dSdS)aExtract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a TarInfo object. You can specify a different directory using `path'. File attributes (owner, mtime, mode) are set unless `set_attrs' is False. If `numeric_owner` is True, only the numbers for user/group names are used and not the names. The `filter` function will be called before extraction. It can return a changed TarInfo or None to skip the member. String names of common filters are accepted. N)rrr)rrar&rrrrr5s r;extractzTarFile.extracts\33F;;++FOTJJ     gtY F F F F F  r=ct|tr||}n|}|} |||}nZ#ttf$r}||Yd}~n/d}~wt $r}||Yd}~nd}~wwxYw| |dd|j zdS| r>tj |}tj ||j|_|S)z@Get filtered TarInfo (or None) from member, which might be a strNr%r)rrrxrr;_handle_fatal_errorr rrrr]rrr&rr`rx)rrarr&r5 unfilteredrs r;rzTarFile._get_extract_tarinfos/ fc " " nnV,,GGG  +%ogt44GG% ( ( (  $ $Q ' ' ' ' ' ' ' ' + + +  ' ' * * * * * * * * + ? IIa/*/A B B B4 ==?? Hi((G#%7<<g6F#G#GG s! >BA)) B6BBcT|d ||tj||j||dS#t $r }||Yd}~dSd}~wt$r }| |Yd}~dSd}~wwxYw)z%Extract from filtered tarinfo to diskrrN) rz_extract_memberrr&rrrrr r)rr5r&rrrs r;rzTarFile._extract_one s C +  "',,tW\*J*J+4/< ! > > > > > ( ( (  $ $Q ' ' ' ' ' ' ' ' ' + + +  ' ' * * * * * * * * * +s#(>w(G(GHHH4r=c|d}|dtj}tj|}|r3tj|stj||s| r&| d|j d|j n| d|j | r|||n|r|||n|r|||n|s|r|||nz|s| r|||n;|jt0vr|||n||||rY||||| s0||||||dSdSdS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. rTr$z -> N)rrrrXr&dirnamerDmakedirsr]r_rrr`r\makefiler^makedirr/makefifor*r,makedevmakelinkrsr makeunknownrrr)rr5 targetpathrr upperdirss r;rzTarFile._extract_memberK s\ &&s++ ''RV44 GOOJ//  #RW^^I66 # K " " " ==?? 'gmmoo ' IIaw|||W5E5EF G G G G IIa & & & ==?? / MM': . . . . ]]__ / LL* - - - - ^^   / MM': . . . . ]]__ /  / LL* - - - - ]]__ /  / MM': . . . . \ 0 0   Wj 1 1 1 1 MM': . . .  0 JJw M : : :==?? 0 7J/// 7J/////  0 0 0 0r=c |jtj|dStj|ddS#t$rYdSwxYw)z,Make a directory called targetpath. Ni)rrmkdirFileExistsErrorrr5rs r;rzTarFile.makedir| sa |#$$$$$U+++++    DD s66 AAc |j}||j|j}t |d5}|ji|jD]2\}}||t |||t|3||j| nt |||jt|ddddS#1swxYwYdS)z'Make a file called targetpath. r=N) rrr1rKrEr2rirr(truncate)rr5rsourcerptargetr r(s r;rzTarFile.makefile s5 G'(((" z4 ( ( NF~)$+NJJLFDKK'''iIIII GL)))!!!!FFGL)WMMM N N N N N N N N N N N N N N N N N NsBCCCcn||||dd|jzdS)zYMake a file from a TarInfo object with an unknown type at targetpath. r$z9tarfile: Unknown file type %r, extracted as regular file.N)rrrsrs r;rzTarFile.makeunknown sO gz*** !24;LA B B B B Br=cvttdrtj|dStd)z'Make a fifo called targetpath. mkfifozfifo not supported by systemN)rrrr rs r;rzTarFile.makefifo s; 2x  ? Ij ! ! ! ! !=>> >r=cZttdrttdstd|j}|d}|r|t jz}n|t jz}tj||tj |j |j dS)z?? A A A A Ar=cR |rOtj|rtj|tj|j|dStj|jrtj |j|dS| | ||dS#t$rL | | ||YdS#t$rtddwxYwwxYw)zMake a (symbolic) link called targetpath. If it cannot be created (platform limitation), we try to make a copy of the referenced file instead of a link. z%unable to resolve link inside archiveN)r_rr&lexistsunlinksymlinkr`rDrxlinkrrsymlink_exceptionrwr rs r;rzTarFile.makelink sR  V}} 57??:..*Ij))) 7+Z888887>>'"6775GG0*=====(()?)?)H)H)355555  V V V V$$T%;%;G%D%D%/111111 V V V"#JKKQUU V  Vs*A!C%>C%)C D&)DD""D&cttdr*tjdkr|j}|j}|s~ t r&|jrt j|jd}n#t$rYnwxYw tr&|j rtj |j d}n#t$rYnwxYw|d}|d} | r-ttdrtj |||dStj|||dS#t$r}t!d|d}~wwxYwdSdS)zSet owner of targetpath according to tarinfo. If numeric_owner is True, use .gid/.uid instead of .gname/.uname. If numeric_owner is False, fall back to .gid/.uid when the search based on name fails. geteuidrr%Nr?lchownzcould not change owner)rrrr+r*rr-getgrnamrwrr,getpwnamr_rrrr )rr5rrgurs r;rz TarFile.chown s 2y ! ! Dbjlla&7&7 A A ;w};L77:D;w};L77:Dyy D==??/wr8'<'</Ij!Q/////HZA..... D D D"#;<)D99D>c|jdS tj||jdS#t$r}t d|d}~wwxYw)zASet file permissions of targetpath according to tarinfo. Nzcould not change mode)rrrrr )rr5rrs r;rz TarFile.chmod s` <  F ? HZ . . . . . ? ? ?677Q > ?s' AAAc|j}|dSttdsdS tj|||fdS#t$r}t d|d}~wwxYw)zBSet modification time of targetpath according to tarinfo. Nrz"could not change modification time)r)rrrrr )rr5rr)rs r;rz TarFile.utime s  = Fr7##  F L HZ% 0 0 0 0 0 L L LCDD! K Ls= AAAc0|d|j|j}d|_|S|j|jkrX|jdkrdS|j|jdz |jdstdd} |j |}n#t$rL}|j r:| dd|j|fz|xjtz c_Yd}~iYd}~nYd}~wt$rs}|j r:| dd|j|fz|xjtz c_Yd}~|jdkrtt|dYd}~nd}~wt $r|jdkrtd dYnt"$r2}|jdkrtt|dYd}~n~d}~wt$$r"}tt|dd}~wt&$rD} ddl}t+||jrtd |d|#t.$r|wxYwd}~wwxYw ||j|nd|_|S) zReturn the next member of the archive as a TarInfo object, when TarFile is opened for reading. Return None if there is no more available. raNrr$rgTr%z0x%X: %sz empty filez zlib error: )rzrOr rrrrkrr5rrrHrrrPrrrr ExceptionrrrrrLrrM)rmr5rrs r;rz TarFile.next s1 D   ' A#D H ;$,++-- - -{at L  dkAo . . .<$$Q'' : 8999  ,22488!   $IIat{A.>!>???KK9,KKHHHH& 6 6 6$6IIat{A.>!>???KK9,KKHHHH[A%%#CFF++5&%%%%# < < <;!###L11t;$#' 6 6 6;!###CFF++5$####( 2 2 2A''T1   KKK!!TZ00 '(:q(:(:;;E"G     L   ( ( ( (DLs`+C I.V]22$H * g..v{;; $k {"" #  &W%% % & &s: A A cF |}|nd|_dS)zWRead through the entire archive file and look for readable members. TN)rrM)rr5s r;r{z TarFile._loadw s. iikkG  r=c|jrtd|jjz| |j|vrtd|jzdSdS)znCheck if TarFile is still open, and if the operation's mode corresponds to TarFile's mode. z %s is closedNzbad operation for mode %r)rrr6rr)rrs r;rzzTarFile._check s] ; D.4>+BBCC C    5 55 ABB B   5 5r=c6|rOdtdtj|j|jf}d}n |j}|}|||d}|td|z|S)zZFind the target member of a symlink or hardlink member in the archive. rTNT)r5r zlinkname %r not found) r_rrrr&rrr`rvrw)rr5r`limitras r;rzTarFile._find_link_target s ==?? xxtbgoogl.K.KWM]-^ _ _``HEE'HE5DII >2X=>> > r=c#2K|jr|jEd{VdSd}|j|}|dz }|V |t |jkr|j|}n)|js |}|s d|_dSndS|dz }|VY)z$Provide an iterator object. Nrr$T)rMrLrOrr5)rr r5s r;__iter__zTarFile.__iter__ s < | # # # # # # # F   'iikkG QJEMMM s4<((((,u-\ ))++#'DLF QJEMMM r=cV||jkrt|tjdSdS)z.Write debugging output to sys.stderr. fileN)rIr{rystderr)rlevelmsgs r;rz TarFile._dbg s4 DJ   #CJ ' ' ' ' ' '  r=c.||Sr)rzrs r; __enter__zTarFile.__enter__ s  r=c||dS|js|jd|_dSr)rrrr)rrsr tracebacks r;__exit__zTarFile.__exit__ sD < JJLLLLL# % ""$$$DKKKr=) NrNNNNNNrNNNN)rN)rNr)rNN)NNNTrr)rN)rT)TFr)>rrrrrIrGrHrJrrYr r9r:rr5r/rrrr8rtrrTrjrnrrrUrrxr|rrr rrrrrrrrrrrrrrrrrrrrrrvr{rzrrrrrrr=r;rrHs EKLJFH FGJAEHL>B)-bbbb^#tZ[/[/[/[[/z222[2[@[6[: I%%%*   ??? aaaaF$D$$$$$L1"1"1"1"1"1"f%%%%2GGG$+/%+/+/+/+/+/ZGGGGGG&. + + +,,, C C C@>B&+*0*0*0*0b   NNN BBB???AAA$VVV2DDDB??? L L L<<<B&&&&&&&&PCCCC&>((( r=rc t|dr:|}t|}||nt|}|dS#t $rYdSwxYw)zReturn True if name points to a tar archive that we are able to handle, else return False. 'name' should be a string, file, or file-like object. rk)rTF)rrrrrr)rrrs r;rr s  4  ))++CT"""A IIcNNNNT A  t uusA-A11 A?>A?c z ddl}d}||}|ddddd |d d td |d}|dddd|ddddd|ddddd|dd dd!|}|jr|j|d"d#|j |j }t|rt|d$5}| t| tj%dddn #1swxYwY|jr$td&|dSdS|d"d'|dS|j|j}t|rQt& |d(5}||j)ddddS#1swxYwYdS|d"d'|dS|jRt)|jd"kr|jd}t*j}nKt)|jd*kr |j\}}n(|d"|t|rt& |d(5}|||j+dddn #1swxYwY|jrC|d,krd-|} nd.||} t| dSdS|d"d'|dS|j|jd} t*j| \} } d/d/d0d0d1d1d1d1d2} | | vr d3| | znd4}|j}t& | |5}|D]}|| dddn #1swxYwY|jr&td5| dSdSdS)6Nrz3A simple command-line interface for tarfile module.) descriptionz-vz --verbose store_trueFzVerbose output)actiondefaulthelpz--filterz zFilter for extraction)metavarchoicesr'T)requiredz-lz--list zShow listing of a tarfile)r(r'z-ez --extract+)r+z zExtract tarfile into target dir)nargsr(r'z-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr$z&--filter is only valid for extraction rrz{!r} is a tar archive.z{!r} is not a tar archive. rR)rr%)r&rrz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.rrr)rz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:rz{!r} file created.)argparseArgumentParser add_argumentradd_mutually_exclusive_group parse_argsrrexittestrrr|r{ryrrrYr rr5rcurdir format_helprcreatepopr&splitextr)r.r#parserrargsrmrtfr5rtar_name_ext compressionstar_mode tar_files file_names r;mainrD s$OOOGK  $ $ $ = =F k,-///  N .4666  / / / > >E tX{7999 t[<=??? tZs39;;; tX{8:::     D {Bt|+ A@AAA yi c?? Gc3 93   cnn&&SZ8888 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9| <.55c::;;;;; < < KK9@@EE F F F F F  i c?? Gc5)) .R --- . . . . . . . . . . . . . . . . . . KK9@@EE F F F F F  ! t|   ! !,q/CYFF   ! # #,KC KK6--// 0 0 0 c?? Gc5)) ?R 6$+ >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| S==3::3??CC2396#v3F3Fc    KK9@@EE F F F F F  ;??1%%!!(++3   03l/B/B4,s+++K \\(H - - "& " " y!!!! " " " " " " " " " " " " " " " " < 9 &--h77 8 8 8 8 81 ! . 9 9sI6AFF FII I /MMMRR R__main__r )krversion __author__ __credits__builtinsrrEryrr rhrrr`rrwarningsrrrAttributeErrorNotImplementedErrorrr NameError__all__r6rrtrrrrrrzrr(r&rrrr.CONTTYPErrrrrrrrrrrr rrrrrNrrr getfilesystemencodingr<rCrSr[rerir|rrr rr r r rrrrPrrrobjectrr BufferedReaderr/r;r=rBrKrNrQrfrhrmrorrrrrrDrrr=r;rSs:6 H '&&&&& JJJJ CCCJJJJ CCC$%89 '#   D  % % %   ^                    HgGXWg#%5! #(>+ /   . 988       7d??HH(s(**H 000&&&   (N    < * * *"&$    2     y        8                x        (        (        {        ;        [                K   0ooooooood6