Nf} |dZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZ ddlZn #e$rdZYnwxYw ddlZn #e$rdZYnwxYweefZ eefz Zn #e$rYnwxYwgdZdZd Zed zZd Zd Zd Zd ZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2e2Z3e!e"e#e$e'e(e)e%e&e*e+e,f Z4e!e"e)e,fZ5e*e+e,fZ6dZ7hd Z8e9e9e9e:e:e:d!Z;ej<d"krd#Z=nej>Z=d$Z?d%Z@d&ZAd'e3fd(ZBd)ZCdedfd*ZDd+ZEGd,d-eFZGGd.d/eGZHGd0d1eGZIGd2d3eGZJGd4d5eGZKGd6d7eGZLGd8d9eLZMGd:d;eLZNGd<d=eLZOGd>d?eLZPGd@dAeLZQGdBdCZRGdDdEZSGdFdGeTZUGdHdIeTZVGdJdKe jWZXejYdLZZGdMdNeTZ[GdOdPeTZ\dQZ]e\jZdRZ^e_dSkr e^dSdS)Tz,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-8cx|||}|d||t|z tzzS)z8Convert a string to a null-terminated bytes object. N)encodelenNUL)slengthencodingerrorss /usr/lib/python3.11/tarfile.pystnr;s9 6""A WfW:#a&&C/ //cx|d}|dkr |d|}|||S)z8Convert a null-terminated bytes object to a string. rN)finddecode)r6r8r9ps r:ntsrBs= 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$rEasciistrict0invalid header)ranger4rBintstrip ValueErrorInvalidHeaderError)r6nis r:ntirSs  t~ s1vvz""  A !GA 1q5MAA Q45==#a&&1*%)*A 7Aw))AAGGII$a((AA 7 7 7$%566 6 7 Hs )5BB9rFc|}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. rrFr$z%0*orHrGrDrEzoverflow in number field)rMbytesr5r bytearrayrLinsertrO)rQdigitsformat original_nr6rRs 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. rG 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 copyfileobjdivmodrLreadr4write) srcdstr7 exceptionbufsizeblocks remainderbrbs r:riris"G {{ ~3W---vw//FI 6]]hhw s88g  )455 5 #A~~hhy!! s88i  )455 5 # Fr<cttjdd}|)||d|}t |ddS)Nr8backslashreplace )end)getattrsysstdoutr3r@print)r6r8s r: _safe_printr|sVsz:t44H HHX1 2 2 9 9( C C !r<ceZdZdZdS)rzBase exception.N__name__ __module__ __qualname____doc__r<r:rr sDr<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:rrs&&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__6sirz)BJ6    2z " " BK D'$e,,r<c8tj|jdSN)rcloserrs r:rz_LowLevelFile.close?s r<c6tj|j|Sr)rrkrrr(s r:rkz_LowLevelFile.readBswtw%%%r<c:tj|j|dSr)rrlrrr6s r:rlz_LowLevelFile.writeEs !r<N)rrrrrrrkrlrr<r:rr0sZ ---&&&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__Ss  ?#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) rrrrrr4rcompressrrs 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)rbr4rprrlrs 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 methodrGrFTN) r decompressobjrrr _Stream__readrr ordrkr5)rflagxlenr6s 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)rrjrprLrkr )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.)_readrr4)rr(rbs r:rkz _Stream.reads: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)rrr4rrbrrkrpr 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)r4rbrrkrprr)rr(rrrbs r:__readz_Stream.__read)s MM XJ$hh,##DL11C  HHSMMM SMA $hh HHQKKTUU8$xr<N)r)rrrrrrrrlrrrrrrkrrrr<r:rrHsDDDLFFF ///%%%,>    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__?s$ <$$Y//r<c2|jj|_|jSr)rrkrbrs r:rkz_StreamProxy.readCsL% xr<c|jdrdS|jdddkr|jdddkrd S|jd rd Sd S) NsrrsBZhr s1AY&SYr)s]s7zXZrr)rb startswithrs r:rz_StreamProxy.getcomptypeGsp 8   / / 4 Xac]f $ $!B$9)D)D5 X !C D D 45r<c8|jdSr)rrrs r:rz_StreamProxy.closeQs 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__^s    GVT22   T I+% $ $LFD >??? HOOT66D='B C C C tOGtmGG TY   HOOUGTY= > > > > >  r<cdSrrrs r:rz_FileInFile.flushws r<cdSNTrrs r:readablez_FileInFile.readablezstr<cdSNFrrs r:writablez_FileInFile.writable}sur<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_ENDrO)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/s([0-9]{1,20}) cTeZdZdZedRidddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d%d'd%ZdSd)Zed*Zej d+Zed,Z e j d-Z d.Z d/Z e ed0fd1Zd2Zd3Zd4Zed5Zd6Zed7Zed8Zed9Zed:Zed;Zed<Zd=Zd>Zd?Zd@Z dAZ!dBZ"dCZ#dDZ$dEZ%dFZ&dGZ'dHZ(dIZ)dJZ*dKZ+dLZ,dMZ-dNZ.dOZ/dPZ0dQZ1d%S)TraInformational 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.linknamezcName 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)r9REGTYPEr:r;r,r-r<r=r r1r2r>rrs r:rzTarInfo.__init__s             r<c|jS)z(In pax headers, "name" is called "path".rrs r:r&z TarInfo.path s yr<c||_dSrrErCs r:r&z TarInfo.paths  r<c|jS)z0In pax headers, "linkname" is called "linkpath".r;rs r:r'zTarInfo.linkpathrr<c||_dSrrH)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<c&|j|jdz|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. ) rrr*r+r(r)r9r:r;r,r-r<r=r:r/)rrr*r+r(r)r9r:r;r,r-r<r=DIRTYPEr)rinfos r:get_infozTarInfo.get_infos  F*            <7 " "4<+@+@+E+E " LLLC LLL r<surrogateescapec|}|tkr||||S|tkr||||S|t kr|||Std)zNPXZ`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. rZrr&r;r')r,r, )r-r-rgrHrI))r*rF)r+rF)r( )r)rhFrrFr$Tr<r)r\r>copyr^r]r3UnicodeEncodeErrorr4 isinstancefloatroundstr_create_pax_generic_headerXHDTYPEr`r) rrQr8r>rhnamer7rX needs_paxval val_is_floatval_intrbs r:rWzTarInfo.create_pax_header`s $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)roXGLTYPE)clsr>s r:create_pax_global_headerz TarInfo.create_pax_global_headers--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. rOr$Nzname is too long)splitrLr4rr3 LENGTH_PREFIXr^rO)rrr8r9 componentsrRr[s r:r_zTarInfo._posix_split_namesZZ__ q#j//** 1 1AXXj!n--F88JqrrN++D6==62233}DD Hf5566+EE/00 0t|r<cx|dttfv}|rKt|ddd|}t|ddd|}n$t dd||}t dd||}t |ddd||t|d dd zd|t|d dd|t|d dd|t|d dd|t|ddd|d|dt t |ddd|||dt t |ddd||t |ddd||||t |ddd||g}tjdtzd |}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. r:r<rrFr=rrrrrNr*r+r(rhr)s r;rZr,rgr-r[rz%dsr<Niz%06orHi) getCHRTYPEBLKTYPEr[r;rBr\r`rrrrerU) rQrYr8r9has_device_fieldsr<r=partsrbr9s r:r`zTarInfo._create_headerse !HHV,,'0BB  4488J22Av>>H488J22Av>>HH2q(F33H2q(F33H $$c8V < < ##f,a 8 8 ""Av . . ""Av . . ##R 0 0 !$$b& 1 1  HHVW % % R((#x @ @ HHWk * * "%%r8V < < "%%r8V < <   2&&Xv > > $k%)+SXXe__==c9*++.//2%4%j5F!2G<<r:r8binarykeywordvaluerecordslrQrArQs r:roz"TarInfo._create_pax_generic_headers)//11  NGU  Wh////%      1 0 0G)//11 V VNGUnnW--G . X/@AA W--G s5zz)A-AIA CFF O66   uSVVW--4w>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)iIiQiYirOirrhiii)$r4rrrcountr5rrSrerPrBrrr*r+r(r)r9r:r;r,r-r<r=AREGTYPErrPGNUTYPE_SPARSErLrOrboolr?isdirrstrip GNU_TYPES)rxrbr8r9r9objr[rstructsrRr numbytes isextendedorigsizes r:frombufzTarInfo.frombuf"sF 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. ) rrkrrr8r9rr  _proc_member)rxr4rbrs r: fromtarfilezTarInfo.fromtarfileasa 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. ) r:rerd _proc_gnulongr _proc_sparserprwSOLARIS_XHDTYPE _proc_pax _proc_builtin)rr4s r:rzTarInfo._proc_membervs 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. rO)rrr1isregr:SUPPORTED_TYPES_blockr(r _apply_pax_infor>r8r9rrr)rr4r s r:rzTarInfo._proc_builtins#?//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. NrO)rrkrr(rr rrnr r:rerBr8r9rrdr;r removesuffix)rr4rbnextrs r:rzTarInfo._proc_gnulongso""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. rrhri)r?rrkrrLrSrOrrr2rr1rr(r ) rr4rrrrbrrRr rs r:rzTarInfo._proc_sparsesF)-(<%X   (/&&y11CC2YY   Sr\!233F"3sRxb'8#9::HH!EE7h7NNFH#5666r c#hJ ( "?//11)DKK ,B,BB  s7A;; B B c|j||j}|jt kr|j}n|j}d}d}g}t||kr||dkrst ||x}std t| d}n#t$rtdwxYw|dkrtd||zt|krtd|d|zdz } ||ddz| } | d\} } } | r| dks || dkrtd||| | f| dkr|| d kr|j}nd }||z }t||kr ||dks|d }|D]q\}} } || d d |j}|t,vr#|| ||j|j}n|| d d |j}|||<r ||}n/#t0$r"}t3t5|dd}~wwxYwd |vr|||ndd |vr|||nI|d dkr0|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. rNrKr$rrs hdrcharsetsBINARYr1GNU.sparse.mapGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrJr()&rrkrr(r:rwr>rir4_header_length_prefix_rematchrPrMgrouprOr)rw partitionrr8_decode_pax_fieldr9PAX_NAME_FIELDSrr rrn_proc_gnusparse_01_proc_gnusparse_00r_proc_gnusparse_10rprrr r1rr)rr4rbr>rr8 raw_headersrr7header_value_end_offsetkeyword_and_value raw_keywordequals raw_valuerrrrr s r:rzTarInfo._proc_paxsA o""4;;ty#9#9:: 9  !-KK!-2244K  #hhnnST!1!15;;CEEEE ;()9::: ;U[[^^,, ; ; ;()9::: ;zz()9:::V|c#hh&&()9:::&+kk!nnv&=&A # #EIIaLL1$45L$L M ->-H-H-N-N *K ;&D..C8O4PTX4X4X()9:::    Y? @ @ @m++0@ ))&/HH&H 6MCM#hhnnST!1!1R  H/: ) ) *FK,,['7N$$G/))..y(GDT((..y'7(($)K  :##G,,DD : : :'A//T 9 : { * *  # #D+ 6 6 6 6 + - -  # #D+ 6 6 6 6 __/ 0 0C 7 7KOOL^<_<_cf O O O+DK$$)::<<549O#C#Cdkk$)444F!' s$8"CC57J J9J44J9cg}g}|D]\}}}|dkrS |t|B#t$rt dwxYw|dkrS |t|#t$rt dwxYwt t |||_dS)z?Process a GNU tar extended sparse header, version 0.0. sGNU.sparse.offsetrKsGNU.sparse.numbytesN)rrMr@rOrPlistzipr2)rrroffsetsr_rrs r:rzTarInfo._proc_gnusparse_00Is !, ? ? Aw...?NN3u||~~#6#67777!???,-=>>>?222?OOC $7$78888!???,-=>>>?3 3w1122 s4A  A#-4B""B<c d|ddD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1. c,g|]}t|Sr)rM).0xs r: z.TarInfo._proc_gnusparse_01..`sKKKQ#a&&KKKr<r,Nr%r$)r{rrr2)rrr>r2s r:rzTarInfo._proc_gnusparse_01]s]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%) rrkrr{rMr4rrr1rrr2)rrr>r4fieldsr2rbnumbers r:rzTarInfo._proc_gnusparse_10cso""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.realsizerrON) rsetattrrM PAX_FIELDSPAX_NUMBER_FIELDSrOrrir>)rr>r8r9rrs r:rzTarInfo._apply_pax_infoss/*//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. rI)r@UnicodeDecodeError)rrr8fallback_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.)r: REGULAR_TYPESrs r:rz TarInfo.isregsyM))r<c*|Sr)rrs r:isfilezTarInfo.isfileszz||r<c"|jtkS)z!Return True if it is a directory.)r:rPrs r:rz TarInfo.isdiryG##r<c"|jtkS)z%Return True if it is a symbolic link.)r:SYMTYPErs r:issymz TarInfo.issymrr<c"|jtkS)z!Return True if it is a hard link.)r:LNKTYPErs r:islnkz TarInfo.islnkrr<c"|jtkS)z(Return True if it is a character device.)r:rrs r:ischrz TarInfo.ischrrr<c"|jtkS)z$Return True if it is a block device.)r:rrs r:isblkz TarInfo.isblkrr<c"|jtkS)zReturn True if it is a FIFO.)r:FIFOTYPErs r:isfifozTarInfo.isfifosyH$$r<c|jduSr)r2rs r:issparsezTarInfo.issparses{$&&r<c8|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)r:rrrrs r:isdevz TarInfo.isdevsyWgx888r<r)r)2rrrrdict __slots__rpropertyr&setterr'rLrRrr rXrUrVrW classmethodryr_ staticmethodr`rrcrorrrrrrrrrrrrrrrrrrrrrrrrr<r:rrsI   ,, !! GF HG     -,  $# >> FF     *) *)! "/.# $54% &99' *.-+ ,$- .$/ 0t1 I60X [[X_!!_!OOO0*HEV / / / / I I I M M M8Q8Q8QtMM[M  !!\!F\**[* 0-0-[0-d<<[<|))[)( / / /,68wwwr333(;;; ;;; ....DDD"""***$$$$$$$$$$$$$$$%%%'''99999r<rceZdZdZdZdZdZdZeZ e Z dZ e ZeZ d8dZedddefd Zed9d Zed:d Zed:d Zed;dZdddddZdZdZdZdZddddZ d?dZ!d@dd d!Z"dAdd d#Z#d$Z$ dBd%Z%d&Z&d'Z'd(Z(d)Z)d*Z*d+Z+d,Z,d-Z-d.Z.d/Z/dCd0Z0d1Z1d?d2Z2d3Z3d4Z4d5Z5d6Z6d7Z7dS)Drz=The TarFile Class provides an interface to tar archives. rFr$NrrScddddd}||vrtd||_|||_|sU|jdkr-tj|sd|_d|_t ||j}d |_n]|8t|d r(t|j ttfr|j }t|d r |j|_d |_|rtj |nd |_ ||_|||_|||_|||_|||_|||_| |_| |jt*kr| |_ni|_| | |_| | |_| |_d |_g|_d |_|j|_i|_ |jdkr d |_ |!|_ |jdkr |j"|j |j#|}|j$|nY#tJ$r"|j"|jYn/tL$r"}tOt|d d }~wwxYw|jdvrxd |_|jrl|j(|j)}|j*||xjtW|z c_d Sd Sd S#|js|j,d |_xYw)aOpen an (uncompressed) tar archive `name'. `mode' is either 'r' to read from an existing archive, 'a' to append data to an existing file or 'w' to create a new file overwriting an existing one. `mode' defaults to 'r'. If `fileobj' is given, it is used for reading or writing data. If it can be determined, `mode' is overridden by `fileobj's mode. `fileobj' is not closed, when TarFile is closed. rbzr+bwbxbrarr!mode must be 'r', 'a', 'w' or 'x'r rFNrrTrr rr)-rOr_moderr&exists bltn_openrrrkrrnrUabspathrrYr5 dereference ignore_zerosr8r9rr>debug errorlevel copybufsizermembers_loadedrr inodes firstmemberrrrrrr rryrirlr4r)rrrrrYr5rrr8r9r>rrrmodesrrbs r:rzTarFile.__init__s}T== u  @AA A 4[  $yCt(<(< ! dj11G$D   &!9!9 7<#u66|w'' *$\ #D -1;BGOOD)))t     DK  "DL  "*D   # ,D   $DM  "t{j'@'@*D  !D   DJ  !(DO'   l''))   yC#' #'99;; yC :L%%dk222:"&,":":4"@"@ ++G4444) ))$+666&:::'A//T9: :yO++# #,,??@P@U@U@W@WXXCL&&s+++KK3s88+KKKK ,+,, # % ""$$$DK s>;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)rrxs r:not_compressedz$TarFile.open..not_compressedvs}X.);;r<keyNrz - method z:  z'file could not be opened successfully: :r$rr|rzmode must be 'r' or 'w'Fr zundiscernible mode)rOsortedrrxrrr rrrr{rrrr)rxrrrrpkwargsr  error_msgsrfunc saved_posrerror_msgs_summaryfilemodestreamrs` r:rz TarFile.openLsJ 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 r )rO)rxrrrr's r:rzTarFile.taropens; + + +@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) rOgzipr2rr rrrrr) rxrrr compresslevelr'r2rrs r:gzopenzTarFile.gzopensS  & &;<< < 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. r0r1r)BZ2FilerN)r4rznot a bzip2 fileF) rOrr7rr rrEOFErrorrrr) rxrrrr4r'r7rrs r:bz2openzTarFile.bz2opens  & &;<< < 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. r0r1r)LZMAFilerrN)presetrznot an lzma fileF) rOrr;rrr rr8rrr) rxrrrr<r'r;rrrs r:xzopenzTarFile.xzopens  & &;<< < 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/rr5r9r=)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. NTr r%r) rrrrlr5rr 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. rONzfilename %r not found) _getmemberrKeyError)rrr5s r: getmemberzTarFile.getmember+s? //$++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. )_checkr_loadrrs r: getmemberszTarFile.getmembers6s0 |  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 SrrE)rr5s r:rz$TarFile.getnames..Ds>>> >>>r<)rGrs r:getnameszTarFile.getnames@s"?>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 )rEr|rSr,rr,r*r-r+rrr<r=r(r localtimer)rrrr;rr{)rverboserr5s r:rz TarFile.lists ?G  G ADM',77888w}'C 'C'C'.}'C 'CEFFF==??7gmmoo7$(8':J'KK!MNNNN  56669"nW];;BQB?@AAA  w}}(FBG H H H ?==??:(8 8999==??? W-= =>>> GGGG)  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. rLNr%ztarfile: Skipped %rr$ztarfile: Unsupported type %rztarfile: Excluded %rrrs)rErrr&r_dbgrorraddfilerr&listdiraddr)rrrj recursivertr5fs r:ryz TarFile.addsD 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(). rLN)rprr$)rErirXrYr8r9rrlr r4rrir(rjrr5rr)rr5rrbrprqrrs r:rwzTarFile.addfiles E)G$$mmDK DD 3 s3xx     w|W M M M M &w|Y ? ? FI1}} ""3)i*?#@AAA!  KK6I- -KK G$$$$$r<. numeric_ownercg}||}|D]r}|r0||tj|}d|_|||| |s|d||D]}tj ||j } | |||| ||| ||m#t$r/}|jdkr|dd|zYd}~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. N set_attrsrc|jSrrE)r s r:z$TarFile.extractall..-sqvr<r!r~r$ tarfile: %s)rrrirextractsortreverserr&rrchownutimechmodr rrv)rr&rr directoriesr5dirpathrs r: extractallzTarFile.extractalls ?G 6 6G}} %""7+++)G,,$ LL$gmmoo2E'4  6 6 6 6 --...# 4 4Ggll466G 4 7G= III 7G,,, 7G,,,, 4 4 4?Q&&IIa!233333333  4 4 4sAD E %E  Erc|dt|tr||}n|}|r*t j||j|_ | |t j||j ||dS#t$ri}|j dkr|j|dd|jzn,|dd|jd|jYd}~dSYd}~dSd}~wt"$r0}|j dkr|dd|zYd}~dSd}~wwxYw) 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. rrrNr$rz tarfile: rv)rErkrnrCrrr&rr;r@_extract_memberrrrfilenamervstrerrorr )rmemberr&rrr5rs r:rzTarFile.extract=s C fc " " nnV,,GGG ==?? H#%7<<g6F#G#GG  0  "',,tW\*J*J+4/< ! > > > > > N N N"":%IIa!;<<<<IIaaQZZZ!LMMMMMMMMM=<<<<< 0 0 0"" !]Q./////////  0s%(>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. rOr$z -> N)rrrrPr&dirnamermakedirsrrrvrr;rmakefilermakedirrmakefiforrmakedevmakelinkr:r makeunknownrrr)rr5 targetpathrr upperdirss r:rzTarFile._extract_members\ &&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<cT tj|ddS#t$rYdSwxYw)z,Make a directory called targetpath. rN)rmkdirFileExistsErrorrr5rs r:rzTarFile.makedirsC  HZ ' ' ' ' '    DD s  ''c |j}||j|j}t |d5}|ji|jD]2\}}||t |||t|3||j| nt |||jt|ddddS#1swxYwYdS)z'Make a file called targetpath. rN) rrr1rrr2rirr(truncate)rr5rsourcerptargetr r(s r:rzTarFile.makefiles5 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)rrvr:rs r:rzTarFile.makeunknownsO 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.makefifos; 2x  ? Ij ! ! ! ! !=>> >r<cRttdrttdstd|j}|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)rrr&lexistsunlinksymlinkr;rr@linkrrsymlink_exceptionrBr rs r:rzTarFile.makelinksT  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&c\ttdrtjdkr|j}|j}|sp t rt j|jd}n#t$rYnwxYw trtj |j d}n#t$rYnwxYw | 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%lchownzcould not change ownerN)rrrr+r*rggetgrnamr-rBregetpwnamr,rrrrr )rr5rrgurs r:rz TarFile.chown sf 2y ! ! Dbjlla&7&7 A A ;L77:D;L77:D D==??/wr8'<'</Ij!Q/////HZA..... D D D"#;< ?s =8=cttdsdS tj||j|jfdS#t$r}t d|d}~wwxYw)zBSet modification time of targetpath according to tarinfo. rNz"could not change modification time)rrrr)rr rs r:rz TarFile.utime, svr7##  F L HZ'-!? @ @ @ @ @ 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: )rErr rrrrkrr5rrrrvrrPrnrrr Exceptionrrkrrrrr)rmr5rrs r:rz TarFile.next7 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.+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. rONT)r5rzlinkname %r not found) rrrtrr&rrr;rArB)rr5r;limitrs 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)rrrrr4)rrr5s r:__iter__zTarFile.__iter__ s < | # # # # # # # F   'iikkG QJEMMM s4<((((,u-\ ))++#'DLF QJEMMM r<cV||jkrt|tjdSdS)z.Write debugging output to sys.stderr. fileN)rr{rystderr)rlevelmsgs r:rvz TarFile._dbg s4 DJ   #CJ ' ' ' ' ' '  r<c.||Sr)rErs r: __enter__zTarFile.__enter__ s  r<c||dS|js|jd|_dSr)rrrr)rr:r tracebacks r:__exit__zTarFile.__exit__ sD < JJLLLLL# % ""$$$DKKKr<) NrNNNNNNrSNNNN)rN)rNr)rNN)NNN)Trr)r}N)rT)TFr)8rrrrrrrrrrYr r8r9rr5r/rrrr?rrr5r9r=rrrCrGrJrorryrwrrrrrrrrrrrrrrrArFrErrrvrrrr<r:rrs EKLJFH FGJAEHL>B)-bbbb^#tZ[/[/[/[[/z222[2[@[6[: I%%%*   ??? aaaaFD@1"1"1"1"1"1"f%%%%2&4%&4&4&4&4&4P$0$0$0$0$0$0L@>B&+*0*0*0*0bNNN BBB??? A A AVVV4DDD:???LLL<<<B.CCCC&>((( 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 ddl}d}||}|ddddd |d }|d d dd|ddddd|ddddd|dddd|}|j|j}t |rt|d5}|t|tj dddn #1swxYwY|j r$td |dSdS|d!d" |dS|j|j}t |rQt |d#5}||j $ddddS#1swxYwYdS|d!d" |dS|jLt%|jd!kr|jd}t&j}nKt%|jd%kr |j\}}n(|d!|t |rt |d#5}||&dddn #1swxYwY|j rC|d'krd( |} nd) ||} t| dSdS|d!d" |dS|j|jd} t&j| \} } d*d*d+d+d,d,d,d,d-} | | vr d.| | znd/}|j}t | |5}|D]}|| dddn #1swxYwY|j r&td0 | dSdSdS)1Nrz3A simple command-line interface for tarfile module.) descriptionz-vz --verbose store_trueFzVerbose output)actiondefaulthelpT)requiredz-lz--list zShow listing of a tarfile)metavarrz-ez --extract+)rz zExtract tarfile into target dir)nargsrrz-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validrrz{!r} is a tar archive.r$z{!r} is not a tar archive. r)rrr%)r&r}z{!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_argumentadd_mutually_exclusive_group parse_argstestrrrGr{ryrrrrYexitrrrr4rcurdir format_helprcreatepopr&splitextry)rrparserrargsrmrtfrrtar_namerext compressionstar_mode tar_files file_names r:mainr sOOOGK  $ $ $ = =F k,-///  / / / > >E tX{7999 t[<=??? tZs39;;; tX{8:::     D 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 9sI4AEE EHH  H -LLLP;;P?P?__main__)`rversion __author__ __credits__builtinsrrryrr rhrSrr`rirererrgAttributeErrorNotImplementedErrorrr NameError__all__r5rr?rbr\r^r]r|rBrrrrrrPrCONTTYPErerdrrprwrrrrrrrrrrrlrMrrr getfilesystemencodingr;rBrSr[rerir|rrr rr r r rrrrPrrrobjectrr BufferedReaderr/compilerrrrrrrr<r:rsu:6 H '&&&&& JJJJ CCCJJJJ CCC$%89 '#   D  % % %   ^                    HgGXWg#%5! #(>+ /   . 988       7d??HH(s(**H 000 &&&   (N    < * * *"&$    2     y        8                x        (        (        {        ;        [                K   0ooooooood6