)U† dZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZ ddlZ ddlZeeefZgdZdZd 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;ejxd"k(rd#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 jZXGdLdMeGZYGdNdOeYZZGdPdQeYZ[GdRdSeYZ\GdTdUeYZ]GdVdWeYZ^GdXdYeYZ_eYeeHfZ`dgdZZad[Zbd\Zcd]Zdebecedd^ZeeTZfejd_ZhGd`daeTZiGdbdceTZjddZkejj ZdeZlemdfk(relyy#e$rdZY$wxYw#e$rdZY-wxYw)hz,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_FORMATrfully_trusted_filter data_filter tar_filter FilterErrorAbsoluteLinkErrorOutsideDestinationErrorSpecialFileErrorAbsolutePathErrorLinkOutsideDestinationErrorisustar sustar00d01234567LKSxgX)pathlinkpathsizemtimeuidgidunamegname>r/r6r5r0)atimectimer2r3r4r1ntutf-8cv| td|j||}|d||t|z tzzS)z8Convert a string to a null-terminated bytes object. Nzmetadata cannot contain None) ValueErrorencodelenNUL)slengthencodingerrorss ./opt/alt/python312/lib64/python3.12/tarfile.pystnrEsC y788 6"A Wf:#a&C/ //c\|jd}|dk7r|d|}|j||S)z8Convert a null-terminated bytes object to a string. rN)finddecode)r@rBrCps rDntsrLs4 u ABw bqE 88Hf %%rFc6|ddvrMd}tt|dz D]}|dz}|||dzz }|ddk(rdt|dz z|z }|S t|dd}t|j xsd d}|S#t $r t d wxYw) z/Convert a number field to a python number. r)r-rOasciistrict0invalid header)ranger>rLintstripr<InvalidHeaderError)r@nis rDntir\s  t~ s1vz"A !GA 1q5MA# Q45=#a&1*%)*A H  7Aw)AAGGI$a(A H 7$%56 6 7s +BBrPc|}t|}d|cxkr d|dz zkr nntd|dz |fzdtz}|S|tk(rzd|dz z |cxkr d|dz zkrbn td |dk\r t dg}nt dg}d|z|z}t |dz D]}|j d|dz|dz}|Std ) z/Convert a python number to a number field. rrPr-z%0*orRrQrNrOzoverflow in number field)rWbytesr?r bytearrayrVinsertr<)rZdigitsformat original_nr@r[s rDitnrdsJ AAA!fqj!! &FQJ?*G 4s : H : 36A:#6"6!"Qcfqj>Q"Q344 65'"A5'"Av !Avz"A HHQE " !GA# H344rFcdttjd|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. rQ 148B8x356B 148b8x356b)sumstruct unpack_from)bufunsigned_chksum signed_chksums rD calc_chksumsrnsGC 2 2< EFFO#f00sCDDM M ))rFcx|xsd}|dk(ry|tj|||yt||\}}t|D]:}|j |}t ||kr|d|j |<|dk7r8|j |}t ||kr|d|j |y)zjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. i@rNunexpected end of data)shutil copyfileobjdivmodrVreadr>write) srcdstrA exceptionbufsizeblocks remainderbrks rDrrrrs"G { ~3W-vw/FI 6]hhw s8g 45 5 #  A~hhy! s8i 45 5 # rFcttjdd}|!|j|dj |}t |dy)NrBbackslashreplace )end)getattrsysstdoutr=rJprint)r@rBs rD _safe_printrs@szz:t4H HHX1 2 9 9( C !rFceZdZdZy)rzBase exception.N__name__ __module__ __qualname____doc__rFrDrrsrFrceZdZdZy)r z%General exception for extract errors.NrrrFrDr r s/rFr ceZdZdZy)rz&Exception for unreadable tar archives.NrrrFrDrrs0rFrceZdZdZy)r z.Exception for unavailable compression methods.NrrrFrDr r s8rFr ceZdZdZy)r z=Exception for unsupported operations on stream-like TarFiles.NrrrFrDr r sGrFr ceZdZdZy)r z!Base exception for header errors.NrrrFrDr r s+rFr ceZdZdZy)EmptyHeaderErrorzException for empty headers.NrrrFrDrr s&rFrceZdZdZy)TruncatedHeaderErrorz Exception for truncated headers.NrrrFrDrr#s*rFrceZdZdZy)EOFHeaderErrorz"Exception for end of file headers.NrrrFrDrr&s,rFrceZdZdZy)rYzException for invalid headers.NrrrFrDrYrY)s(rFrYceZdZdZy)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.NrrrFrDrr,s=rFrc(eZdZdZdZdZdZdZy) _LowLevelFilezLow-level file object. Supports reading and writing. It is used instead of a regular file object for streaming access. ctjtjtjztjzd|}t tdr|tj z}tj||d|_y)NrwO_BINARYi) osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrrrfd)selfnamemodes rD__init__z_LowLevelFile.__init__9sarzz)BJJ6   2z " BKK D''$e,rFcBtj|jyN)rcloserrs rDrz_LowLevelFile.closeBs rFcBtj|j|Sr)rrtrrr1s rDrtz_LowLevelFile.readEswwtww%%rFcDtj|j|yr)rrurrr@s rDruz_LowLevelFile.writeHs !rFN)rrrrrrrtrurrFrDrr3s -&rFrcZeZdZdZdZdZdZdZdZdZ dZ d Z dd Z d Z d Zd Zy)_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 that works with bytes, and the method is accessed blockwise. Use of gzip or bzip2 compression is possible. A stream-like object could be for example: sys.stdin.buffer, sys.stdout.buffer, a socket, a tape device etc. _Stream is intended to be used only internally. cd|_|t||}d|_|dk(rt|}|j}|xsd|_||_||_||_||_d|_ d|_ d|_ |dk(r[ ddl }||_ |jd|_|d k(r"|j"|_|j'y|j)|y|d k(rI ddl}|d k(r(d|_|j/|_t2|_y|j5||_y|d k(rN ddl} |d k(r.d|_| j9|_| j:|_y| j=|_y|dk7rtd|zy#t$r td dwxYw#t$r td dwxYw#t$r tddwxYw#|js|jj?d|_ xYw)z$Construct a _Stream object. TNF*rFrgzzzlib module is not availablerbz2bz2 module is not availablexzlzma module is not availabletarunknown compression type %r) _extfileobjr _StreamProxy getcomptyperrcomptypefileobjryrkposclosedzlib ImportErrorr crc32crcerrorrx _init_read_gz_init_write_gzrdbufBZ2DecompressorcmpOSError BZ2CompressorlzmaLZMADecompressor LZMAErrorLZMACompressorr) rrrrrry compresslevelrrrs rDrz_Stream.__init__Ws  ?#D$/G$D  s?#7+G**,H        - 4U! ::c?3;%)ZZDN&&('' 6U"T3; #DI"224DH%,DN"00?DHT!U3; #DI#446DH%)^^DN#224DHU"&'Dx'OPP#E#U*+IJPTTU#T*+HItST#U*+IJPTTU ## ""$DK sy:GFAGGG F($,GG(G.G22G%G;GF%%G(F>>GGG0H cXt|dr|js|jyyy)Nr)rrrrs rD__del__z_Stream.__del__s# 4 "4;; JJL,7 "rFct|jj||jj|jj |jjd|_t jdttj}|jd|zdz|jjdr|jdd|_ tjj|j|_ |j|jj!dd t"zy) z6Initialize for writing with gzip compression. rDErFc*|jdk(r+|jj||j|_|xjt |z c_|jdk7r|j j|}|j|y)z&Write string s to the stream. rrN) rrrrrr>rcompressrrs rDruz _Stream.writesg ==D yyq$((3DH CF ==E !!!!$A QrFcZ|xj|z c_t|j|jkDrt|jj |jd|j|j|jd|_t|j|jkDrsyy)z]Write string s to the stream if a whole new block is ready to be written. N)rkr>ryrrurs rD__writez_Stream.__writesr A $((mdll* LL  txx 6 7xx .DH$((mdll*rFc|jryd|_ |jdk(r<|jdk7r-|xj|jj z c_|jdk(r|jr|j j|jd|_|jdk(ru|j jtjd|j|j jtjd|jdz|js|j jyy#|js|j jwwxYw) z[Close the _Stream object. No operation should be done on it afterwards. NTrrrFrrl)rrrrkrflushrrurirrrrrrs rDrz _Stream.closes  ;;   %yyCDMMU$:DHHNN,,yyCDHH ""488,==D(LL&&v{{4'BCLL&&v{{4J9N'OP## ""$$4## ""$$s DE)E=c|jj|jj |_d|_|j ddk7r t d|j ddk7r tdt|j d}|j d|d zrIt|j dd t|j dzz}|j||d zr |j d}|r |tk(rn|d zr |j d}|r |tk(rn|dzr|j dy y )z:Initialize for reading a gzip compressed fileobj. rFr.snot a gzip filer-zunsupported compression methodrQrPN) r decompressobjrrr _Stream__readrr ordrtr?)rflagxlenr@s rDrz_Stream._init_read_gzs+99**DII,?,?+?@  ;;q>[ (-. . ;;q>W $"#CD D4;;q>" A !8t{{1~&s4;;q>/B)BBD IIdO !8KKNAH "9KKNAH !8 KKN rFc|jS)z3Return the stream's file pointer position. )rrs rDtellz _Stream.tells xxrFc||jz dk\rnt||jz |j\}}t|D]}|j |j|j ||jSt d)zXSet the stream's file pointer to pos. Negative seeking is forbidden. rz seeking backwards is not allowed)rrsryrVrtr )rrrzr{r[s rDseekz _Stream.seekst >Q  &sTXX~t|| D FI6] $,,'# IIi xx@A ArFcl|J|j|}|xjt|z c_|S)z5Return the next size number of bytes from the stream.)_readrr>)rr1rks rDrtz _Stream.read s3jj CH rFc(|jdk(r|j|St|j}|jg}||kr|jr|j}d|_n(|j j |j}|snA |jj|}|j||t|z }||krdj|}||d|_|d|S#|j$r}td|d}~wwxYw)z+Return size bytes from the stream. rrFzinvalid compressed dataN)rrr>rrkrrtryr decompressrxrappendjoin)rr1ctrkes rDrz _Stream._reads ==E !;;t$ $  N YYK$hxxhhll'' 5 Bhh))#. HHSM SMA$h HHQKdeH $x >> B 9:A BsC11D D  Dc*t|j}|jg}||krM|jj|j}|sn%|j ||t|z }||krMdj |}||d|_|d|S)zsReturn size bytes from stream. If internal buffer is empty, read another block from the stream. rFN)r>rkrrtryrr)rr1rrrks rD__readz_Stream.__read/s M XXJ$h,,##DLL1C HHSM SMA $h HHQKTU8$xrFN)r)rrrrrrrrurrrrrrtrrrrFrDrrKsF ENF"/%,> 6rFrc(eZdZdZdZdZdZdZy)rzsSmall proxy class that enables transparent compression detection for the Stream interface (mode 'r|*'). cZ||_|jjt|_yr)rrt BLOCKSIZErk)rrs rDrz_StreamProxy.__init__Es <<$$Y/rFcP|jj|_|jSr)rrtrkrs rDrtz_StreamProxy.readIsLL%% xxrFc|jjdry|jdddk(r|jdddk(ry |jjd ry y ) NsrrsBZhr s1AY&SYr)s]s7zXZrr)rk startswithrs rDrz_StreamProxy.getcomptypeMsV 88   / XXa]f $!B9)D XX !C DrFc8|jjyr)rrrs rDrz_StreamProxy.closeWs rFN)rrrrrrtrrrrFrDrr@s0rFrcheZdZdZd dZdZdZdZdZdZ e jfd Z d d Z d Zd Zy) _FileInFilezA thin wrapper around an existing file object that provides a part of its data as an individual file object. Nc||_||_||_d|_||_d|_|d|fg}d|_g|_d}|j}|D]U\}}||kDr|jjd||df|jjd|||z|f||z }||z}W||jkr*|jjd||jdfyy)NrFT) roffsetr1positionrr map_indexmapr)rrrr1r blockinfolastposrealposs rDrz_FileInFile.__init__ds       T I++%LFD >? HHOOT66D='B C tOGtmG & TYY  HHOOUGTYY= > rFcyrrrs rDrz_FileInFile.flush}s rFcyNTrrs rDreadablez_FileInFile.readablesrFcyNFrrs rDwritablez_FileInFile.writablesrFc6|jjSr)rseekablers rDr%z_FileInFile.seekables||$$&&rFc|jS)z*Return the current file position. )rrs rDrz_FileInFile.tell}}rFc.|tjk(r1tt|d|j|_|j S|tj k(rc|dkr*t|j |zd|_|j St|j |z|j|_|j S|tjk(r>tt|j|z|jd|_|j Std)z(Seek to a position in the file. rzInvalid argument) ioSEEK_SETminmaxr1rSEEK_CURSEEK_ENDr<)rrwhences rDrz_FileInFile.seeks R[[ Ha 0$))rrrtrr?) rr1rkdatastartstoprrAr|s rDrtz_FileInFile.readsD <99t}},DtTYY67DQh,0HHT^^,D)eT6DMM0D0NNa'N~~TXX6)*tdmm34F !!&DMME,A"BCLL%%f-q6V##$<==qsV|# FND MMV #M'Qh( rFch|jt|}||dt|t|Sr)rtr>)rr|rks rDreadintoz_FileInFile.readintos,iiA)3s8 3xrFcd|_yr)rrs rDrz_FileInFile.closes  rFr)rrrrrrr r#r%rr)r*rrtr5rrrFrDrr^sB ?2 ' %'KK > rFrceZdZfdZxZS) ExFileObjectct|j|j|j|j|j }t ||yr)rr offset_datar1rsparsesuperr)rtarfiletarinfor __class__s rDrzExFileObject.__init__s;goow/B/B gllGNN< !rFrrrr __classcell__r?s@rDr8r8s ""rFr8c eZdZy)rN)rrrrrFrDrrsrFrceZdZfdZxZS)rcN||_t| d|jdy)Nzmember z has an absolute pathr>r<rrrr>r?s rDrzAbsolutePathError.__init__s&  77<<"22GHIrFr@rBs@rDrrsJJrFrceZdZfdZxZS)rcf||_||_t| |jd|ddzy)Nz would be extracted to , which is outside the destinationr>_pathr<rrrr>r/r?s rDrz OutsideDestinationError.__init__s;   GLL++B4("M=> ?rFr@rBs@rDrr ??rFrceZdZfdZxZS)rcL||_t| |jdy)Nz is a special filerFrGs rDrzSpecialFileError.__init__s$  GLL++=>?rFr@rBs@rDrrs@@rFrceZdZfdZxZS)rcL||_t| |jdy)Nz is a link to an absolute pathrFrGs rDrzAbsoluteLinkError.__init__s$  GLL++IJKrFr@rBs@rDrrsLLrFrceZdZfdZxZS)rcf||_||_t| |jd|ddzy)Nz would link to rJrKrLrNs rDrz$LinkOutsideDestinationError.__init__s:   GLL+?4("E=> ?rFr@rBs@rDrrrOrFrceZdZfdZxZS)LinkFallbackErrorcj||_||_t| d|jdd|dzy)Nzlink z would be extracted as a zcopy of z, which was rejectedrLrNs rDrzLinkFallbackError.__init__sC   5 00IJ%dX-ABC DrFr@rBs@rDrWrWsDDrFrWc2i}|j}tjj|tjj}|j dtj fr1|jjdtj zx}|d<tjj|r t|tjjtjj||tjj}tjj||g|k7r t|||j}|y|dz}|r^|js|jr|dzs|dz}|dz}n.|j!s|j#rd}n t%|||jk7r||d<|r|j&d|d <|j(d|d <|j*d|d <|j,d|d <|js|j#r]tjj|j.r t1|tjj3|j.}||j.k7r||d <|j#rItjj|tjj5||j.}n*tjj||j.}tjj|tjj}tjj||g|k7r t7|||S)N)rS/ri@irr3r4r5r6linkname)rrr/realpath ALLOW_MISSINGrseplstripisabsrr commonpathrrisregislnkisdirissymrr3r4r5r6r]rnormpathdirnamer)member dest_pathfor_data new_attrsr target_pathr normalizeds rD_get_filtered_attrsrpsI ;;D  2773H3H II RVV}%#);;#5#5cBFFl#CCy  ww}}T ''''""277<< 4#@*,''*?*?#AK ww; 23y@%fk:: ;;D e| ||~e|FND 6<<>'v.. 6;;  $If  :: !#Ie  :: !#Ie  << #!%Ig  << #!%Ig  <<>V\\^ww}}V__-'//))&//:JV__,(2 *%||~ ggll9+-77??4+@+1??< !ggll9+1??< ''**;24''2G2G+IKww!!; ":;yH1&+FF rFc|Srr)rjrks rDrrCs MrFcPt||d}|r|jdi|ddiS|S)NFdeeprrprrjrkrms rDrrFs1#FIu=Iv~~6 666 MrFcPt||d}|r|jdi|ddiS|S)NTrsFrrtrus rDrrLs1#FItZd?Zd@Z dAZ!dBZ"dCZ#dDZ$dEZ%dFZ&dGZ'dHZ(dIZ)dJZ*dKZ+dLZ,dMZ-dNZ.dOZ/dPZ0dQZ1dRZ2dSZ3y%)VraInformational 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.r3z6User ID of the user who originally stored this member.r4z7Group ID of the user who originally stored this member.r1zSize in bytes.r2zTime 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.r5z User name.r6z Group name.devmajorzDevice major number.devminorzDevice minor number.rzThe tar header starts here.r:zThe file's data starts here. pax_headerszMA dictionary containing key-value pairs of an associated pax extended header.r;zSparse member information.r=N_sparse_structs _link_targetc||_d|_d|_d|_d|_d|_d|_t|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_i|_y)zXConstruct a TarInfo object. name is the optional name of the member. irrN)rrr3r4r1r2ryREGTYPErzr]r5r6r{r|rr:r;r}rrs rDrzTarInfo.__init__s}             rFc|jS)z(In pax headers, "name" is called "path".rrs rDr/z TarInfo.pathsyyrFc||_yrrrs rDr/z TarInfo.paths  rFc|jS)z0In pax headers, "linkname" is called "linkpath".r]rs rDr0zTarInfo.linkpathr'rFc||_yrr)rr]s rDr0zTarInfo.linkpaths   rFc`d|jj|jt|fzS)Nz<%s %r at %#x>)r?rridrs rD__repr__zTarInfo.__repr__s&4>>#:#:499RX"NNNrFT) rr2rr]r3r4r5r6rs_KEEPc | rtj|} ntj|} || ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _|| ur|| _ | S)zGReturn a deep copy of self with the given attributes replaced. ) copydeepcopyrr2rr]r3r4r5r6) rrr2rr]r3r4r5r6rsrresults rDrzTarInfo.replaces ]]4(FYYt_F u FK   FL u FK 5 &FO e FJ e FJ   FL   FL rFc|jd}n|jdz}|j||j|j|j|j |j |j|j|j|j|j|jd }|dtk(r!|djds |dxxdz cc<|S)z9Return the TarInfo's attributes as a dictionary. N) rrr3r4r1r2ryrzr]r5r6r{r|rzrrZ)rrr3r4r1r2ryrzr]r5r6r{r|DIRTYPEr)rrinfos rDget_infozTarInfo.get_infos 99 D99v%D            <7 "4<+@+@+E LC L rFsurrogateescapec.|j}|jD]\}}| td|z|tk(r|j |||S|t k(r|j |||S|tk(r|j||Std)zr= LENGTH_LINKr< LENGTH_NAME_posix_split_name_create_headerr)rrrBrCs rDrzTarInfo.create_ustar_headers$W tJ&&x8 9K G34 4 tF|""8V4 5 C+/+A+A$v,PXZ`+a (DNDL""4xHHrFcZt|d<d}t|dj||tkDr||j |dt ||z }t|dj||t kDr||j |dt||z }||j|t||zS)z:Return the object as a GNU header block sequence. rrFr]r) GNU_MAGICr>r=r_create_gnu_long_headerGNUTYPE_LONGLINKrGNUTYPE_LONGNAMErr)rrrBrCrks rDrzTarInfo.create_gnu_headers"W  tJ&&x8 9K G 4//Z0@BRT\^de eC tF|""8V4 5 C 4//V >NPXZ`a aCT((z8VLLLrFc\t|d<|jj}ddtfddtfddfD];\}}}||vr ||j dd t|||kDs4||||<=d D]e\}}d }||} t| t} | r t| n| } d | cxkr d |dz zks nd ||<d}n | r| ||<d}|sS||vsXt| ||<g|r|j|t|} nd} | |j|tddzS#t $r ||||<YwxYw)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]r0)r5r5 )r6r6rrRrS))r3rP)r4rP)r1 )r2rFrrPr-TrFr)rr}rrrr=UnicodeEncodeErrorr> isinstancefloatroundstr_create_pax_generic_headerXHDTYPErr) rrrBr}rhnamerAra needs_paxval val_is_floatval_intrks rDrzTarInfo.create_pax_headers~ $W &&++- - J /T&(>$@ D% # T !!'84 4:'%)$Z E"!$@(RLD&It*C%c51L$0eCjcG3! "33T  %T  T4$'H D!%R* 11+wQCCT((|WiPPPG& %)$Z E" sDD+*D+c0|j|tdS)zAReturn the object as a pax global header block sequence. r:)rXGLTYPE)clsr}s rDcreate_pax_global_headerz TarInfo.create_pax_global_headerPs--k7GLLrFcR|jd}tdt|D]t}dj|d|}dj||d}t|j ||t ksNt|j ||t ksq||fStd)zUSplit a name longer than 100 chars into a prefix and a name part. rZr-Nzname is too long)splitrVr>rr= LENGTH_PREFIXrr<)rrrBrC componentsr[rs rDrzTarInfo._posix_split_nameVsZZ_ q#j/*AXXj!n-F88JqrN+D6==623}D Hf56+Et|+/0 0rFch|jdttfv}|r;t|jddd|}t|jddd|}nt dd||}t dd||}|jdt }| t dt |jd dd ||t|jd dd zd|t|jd dd|t|jddd|t|jddd|t|jddd|d|t |jddd |||jdtt |jddd||t |jddd||||t |jddd||g}tjdtzdj|} 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. rzr{rrPr|rNzTarInfo.type must not be Nonerrrrr3r4r1rr2s r]rr5rr6rrz%dsrFiz%06orRi)getCHRTYPEBLKTYPErdrErr<rrirr rrnr^) rrbrBrChas_device_fieldsr{r|filetypepartsrkrys rDrzTarInfo._create_headerfs !HHV,'0BB 488J2Av>H488J2Av>H2q(F3H2q(F3H88FG,  <= = $c8V < #f,a 8 "Av . "Av . #R 0 !$b& 1   R(#x @ HHWk * "%r8V < "%r8V <   2&Xv > $kk%)+SXXe_=c9*+./2%4j5F!2G<r r?)payloadrzr{s rD_create_payloadzTarInfo._create_payloads9 #3w<; q=  I-4 4GrFc|j||tz}i}d|d<||d<t||d<t|d<|j |t |||j |zS)zTReturn a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence for name. z ././@LongLinkrrzr1r)r=r?r>rrrr)rrrzrBrCrs rDrzTarInfo._create_gnu_long_headerst {{8V,s2&V V 4yV !W !!$ hG##D)* *rFcd}|jD]\}} |jddd}|r|dz }|jD]\}}|jd}|r|j|d}n|jd}t|t|zdz}d x} } |tt | z} | | k(rn| } |t t | d d z|zd z|zd zz }i} d| d<|| d<t|| d<t | d<|j| td d|j|zS#t$rd}YwxYw)zReturn a POSIX.1-2008 extended or global header sequence that contains a list of keyword, value pairs. The values must be strings. Fr:rSTrFs21 hdrcharset=BINARY rrrrR = z././@PaxHeaderrrzr1rr) rr=rr>rr^rrrr) rr}rzrBbinarykeywordrrecordslrZrKrs rDrz"TarInfo._create_pax_generic_headers)//1NGU  Wh/2  0 0G)//1NGUnnW-G X/@A W-G s5z)A-AIACF O6  uSVW-4w>EMPUU UG!2('V V 7|V #W !!$ gyI##G,- -I&  sD99 E E clt|dk(r tdt|tk7r td|j t tk(r t dt|dd}|t|vr td|}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||}|j$t0k(r&|jj3dr t4|_|j$t6k(rxd}g}t9dD]@} t|||dz} t||dz|dz} |j=| | f|dz }Bt?|d} t|dd} || | f|_ |jCr |jjEd|_ |r)|j$tFvr|dz|jz|_ |S#t:$rYwxYw)zAConstruct a TarInfo object from a 512 byte bytes object. rz empty headerztruncated headerzend of file headerz bad checksumrlt|ii i)iIiQiYirZirriii)$r>rr rcountr?rr\rnrYrLrrr3r4r1r2ryrzr]r5r6r{r|AREGTYPErrGNUTYPE_SPARSErVr<rboolr~rfrstrip GNU_TYPES)rrkrBrCryobjrrstructsr[rnumbytes isextendedorigsizes rDfrombufzTarInfo.frombufs s8q=">2 2 s8y &'9: : 99S>Y & !56 6SS\" c* *$^4 4es1Sz8V4s3s|$c#cl#c#cl#s3s|$C %  s3<3s3<6: C h7 C h7 3s3<( 3s3<( SS\8V4 88x CHH$5$5c$:CH 88~ %CG1X Sr!23F"3sRxb#9:H12r c#hJ3s3<(H#*J"AC  99;xxs+CH chhi/|chh.CH "s$%J&& J32J3c|jjt}|j||j|j }|jj tz |_|j|S)zOReturn the next TarInfo object from TarFile object tarfile. ) rrtr rrBrCrr _proc_member)rr=rkrs rD fromtarfilezTarInfo.fromtarfiles^ oo""9-kk#w//@__))+i7 ((rFc|jttfvr|j|S|jtk(r|j |S|jt ttfvr|j|S|j|S)zYChoose the right processing method depending on the type and call it. ) rzrr _proc_gnulongr _proc_sparserrSOLARIS_XHDTYPE _proc_pax _proc_builtin)rr=s rDrzTarInfo._proc_member2sx 99)+;< <%%g. . YY. ($$W- - YY7G_= =>>'* *%%g. .rFc|jj|_|j}|js|jt vr||j |jz }||_|j|j|j|j|jr |jjd|_|S)zfProcess a builtin type or an unknown type which will be treated as a regular file. rZ)rrr:rdrzSUPPORTED_TYPES_blockr1r_apply_pax_infor}rBrCrfrr)rr=rs rDrzTarInfo._proc_builtin?s#??//1!! ::<499O; dkk$)), ,F W00'2B2BGNNS ::< ((-DI rFcF|jj|j|j} |j |}|j|_|jtk(r't||j|j|_n9|jtk(r&t||j|j|_|j#r |jj%d|_|S#t $r}t t|dd}~wwxYw)zSProcess the blocks that hold a GNU longname or longlink member. NrZ)rrtrr1rr rrrrzrrLrBrCrrr]rf removesuffix)rr=rknextrs rDrzTarInfo._proc_gnulongUsoo""4;;tyy#9: :##G,D kk 99( (C!1!17>>BDI YY* *W%5%5w~~FDM ::< ..s3DI ! :'A/T 9 :sC== D DD c |j\}}}|`|r|jjt}d}t dD]D} t |||dz}t ||dz|dz} |r| r|j|| f|dz }Ft|d}|r||_ |jj|_ |j|j|jz|_||_ |S#t $rYywxYw)z8Process a GNU sparse header plus extra headers. rrri)r~rrtr rVr\r<rrr;rr:rr1r) rr=rrrrkrr[rrs rDrzTarInfo._proc_sparseps )-(<(<%X  //&&y1CC2Y Sr!23F"3sRxb#9:HhNNFH#56r c#hJ "??//1))DKK ,BB  "s%C55 DDc|jj|j|j}|jt k(r |j }n|j j}d}d}g}t||kDr||dk7rtj||x}s td t|jd}|dkr td||zt|kDr td|jd|zdz } ||j!ddz| } | j#d\} } } | r | dk7s|| dk7r td|j%|| | f| dk(r|| d k(r |j&}nd }||z }t||kDr ||dk7r|d }|D]x\}} } |j)| d d |j*}|t,vr)|j)| ||j&|j*}n|j)| d d |j*}|||<z |j/|}d |vr|j7||nRd |vr|j9||n;|j;d dk(r'|j;ddk(r|j=||||jt>t@fvr|jC||j&|j*|jD|_"d|vrS|jF}|jIs|jtJvr||j|jz }||_"|S#t$r tdwxYw#t0$r}t3t5|dd}~wwxYw)zVProcess an extended or global header as described in POSIX.1-2008. rNrUr-rrs hdrcharsetsBINARYr:GNU.sparse.mapGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrTr1)&rrtrr1rzrr}rr>_header_length_prefix_rematchrYrWgroupr<r2r partitionrrB_decode_pax_fieldrCPAX_NAME_FIELDSrr rr_proc_gnusparse_01_proc_gnusparse_00r_proc_gnusparse_10rrrrr:rdr)rr=rkr}rrB raw_headersrrAheader_value_end_offsetkeyword_and_value raw_keywordequals raw_valuerrrrrs rDrzTarInfo._proc_paxs oo""4;;tyy#9: 99 !--K!--224K  #hnST!15;;CEEEE()9:: ;U[[^, z()9::V|c#h&()9::&+kk!nv&=&A # #EIIaL1$45L M ->-H-H-N *K&D.C8O4PTX4X()9::    Y? @m+0@ )&//H&H 6MCM#hnST!1R  H/: *FK,,['7NN$G/)..y(GDTDT(..y'7($)K #/:( :##G,D { *  # #D+ 6 + -  # #D+ 6 __/ 0C 7KOOL^<_cf.> O++DK$))::<499O#Cdkk$))44F!' y ;()9:: ;| :'A/T 9 :s$1M"MM N&M;;Ncrg}g}|D]d\}}}|dk(r* |jt|j6|dk(s< |jt|jft t |||_y#t$r t dwxYw#t$r t dwxYw)z?Process a GNU tar extended sparse header, version 0.0. sGNU.sparse.offsetrUsGNU.sparse.numbytesN)rrWrJr<rYlistzipr;)rrr offsetsr_rrs rDrzTarInfo._proc_gnusparse_00s!, Aw..?NN3u||~#6722?OOC $78"-3w12 "?,-=>>? "?,-=>>?s(B (B! B!B6c |djdDcgc] }t|}}tt|ddd|ddd|_ycc}w)z?Process a GNU tar extended sparse header, version 0.1. r,Nr.r-)rrWrrr;)rrr}xr;s rDrzTarInfo._proc_gnusparse_01sZ#..>"?"E"Ec"JK"JQ#a&"JK3vcc{F14a4L9: LsAc d}g}|jjt}|jdd\}}t |}t ||dzkrgd|vr"||jjtz }|jdd\}}|j t |t ||dzkrg|jj|_tt|ddd|ddd|_ y)z?Process a GNU tar extended sparse header, version 1.0. Nrr-r.) rrtr rrWr>rrr:rrr;)rrr}r=fieldsr;rknumbers rDr zTarInfo._proc_gnusparse_10soo""9-iiq) V&kFQJ&Cw++I66))E1-KFC MM#f+ & &kFQJ& #??//13vcc{F14a4L9: rFc|jD]\}}|dk(rt|d||dk(rt|dt|5|dk(rt|dt|Q|tvsZ|tvr t ||}|dk(r|j d}t||||j|_y#t $rd}YHwxYw) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namer/rr1zGNU.sparse.realsizerrZN) rsetattrrW PAX_FIELDSPAX_NUMBER_FIELDSr<rrr})rr}rBrCrrs rDrzTarInfo._apply_pax_info/s*//1NGU++fe,--fc%j111fc%j1J&//" 1' :5 Af$!LL-Egu-2"'++- &" !"s4B== C  C cj |j|dS#t$r|j||cYSwxYw)z1Decode a single field from a pax record. rS)rJUnicodeDecodeError)rrrBfallback_encodingfallback_errorss rDrzTarInfo._decode_pax_fieldFs< D<<(3 3! D<< 1?C C Ds 22cHt|t\}}|r|dz }|tzS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. r-)rsr )rrrzr{s rDrzTarInfo._blockNs,#5)4  aKF !!rFc&|jtvSz4Return True if the Tarinfo object is a regular file.)rz REGULAR_TYPESrs rDrdz TarInfo.isregWsyyM))rFc"|jSr%)rdrs rDisfilezTarInfo.isfile[szz|rFc(|jtk(S)z!Return True if it is a directory.)rzrrs rDrfz TarInfo.isdir_yyG##rFc(|jtk(S)z%Return True if it is a symbolic link.)rzSYMTYPErs rDrgz TarInfo.issymcr*rFc(|jtk(S)z!Return True if it is a hard link.)rzLNKTYPErs rDrez TarInfo.islnkgr*rFc(|jtk(S)z(Return True if it is a character device.)rzrrs rDischrz TarInfo.ischrkr*rFc(|jtk(S)z$Return True if it is a block device.)rzrrs rDisblkz TarInfo.isblkor*rFc(|jtk(S)zReturn True if it is a FIFO.)rzFIFOTYPErs rDisfifozTarInfo.isfifossyyH$$rFc|jduSr)r;rs rDissparsezTarInfo.issparsews{{$&&rFc<|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)rzrrr4rs rDisdevz TarInfo.isdevzsyyWgx888rFr)r)4rrrrdict __slots__rpropertyr/setterr0rrrrrr rrrr classmethodrr staticmethodrrrrrrrrrrrrrr rrrrdr(rfrgrer0r2r5r7r9rrFrDrrbs , ! G H    -  $ > F   * *! "/# $5% &9' *.+ ,- ./ 01 I60 [[__!!O%eeuE88*HEV/" I M8QtMM  ''R** 0-0-d<<|))( /,68wr3(; ; ..D"*$$$$$%'9rFrceZdZdZdZdZdZdZeZ e Z dZ e ZeZdZ d;dZedddefdZedd Zd ddddZdZdZdZdZd?dZd@dddZ dAdddZ!dBdZ"dZ#dCddddZ$dZ%dDdddd Z&d!Z' dBd"Z(d#Z)d$Z*d%Z+ dEddd&d'Z,d(Z-d)Z.d*Z/d+Z0d,Z1d-Z2d.Z3d/Z4d0Z5d1Z6d2Z7dFd3Z8d4Z9dBd5Z:d6Z;d7Zd:Z?y)Grz=The TarFile Class provides an interface to tar archives. rFr-Nrcddddd}||vr td||_|||_|sZ|jdk(r-tjj |sd|_d|_t ||j}d |_n^|8t|d r,t|jttfr |j}t|d r|j|_d |_|rtjj|nd |_ ||_|||_|||_|||_|||_|||_| |_| |jt*k(r| |_ni|_| | |_| | |_| |_d |_g|_d |_|jj;|_i|_ |jdk(rd |_ |jC|_ |jdk(r^ |jjE|j< |j jG|}|j6jI|]|jdvrd |_|j,rm|j jQ|j,jS}|jjU||xj<tW|z c_y y y #tJ$r(|jjE|j<YtL$r}tOt|d d }~wwxYw#|js|jjYd |_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'rFrFNrrTrrFrr)-r<r_moderr/exists bltn_openrrrrrr^abspathrrbr> dereference ignore_zerosrBrCrr}debug errorlevel copybufsizermembers_loadedrrinodes firstmemberrrrrrr rrrrur>r)rrrrrbr>rMrNrBrCr}rOrPrQmodesrrks rDrzTarFile.__init__sT= u @A A 4[ yyCt(< ! djj1G$D  &!97<<#u6||w'$\\ #D -1BGGOOD)t     DK  "DL  "*D   # ,D   $DM  "t{{j'@*D !D   DJ  !(DO'   ll'')   yyC#' #'99; yyCLL%%dkk2:"&,,":":4"@ ++G4 yyO+# ##,,??@P@P@U@U@WXCLL&&s+KK3s8+K$, * ))$++6&:'A/T9: ## ""$DK s>>A L;6K&BL;&.L8L;L8L33L88L;;0M+c |s |s td|dvrzfd}g}tj|D]:}tj|} ||j } | |d|fi|cSd j|} t d | d |vrb|jd d \} }| xsd} |xsd }|jvrtj|} nt d|z| || |fi|Sd|vrg|jdd \} }| xsd} |xsd }| dvr td|jdd}t|| ||||} || |fi|}d|_|S|dvrj|||fi|Std#t t f$r5} |jd|d| ||j Yd} ~ d} ~ wwxYw#|jxYw)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|dk(S)Ntaropen) OPEN_METH)rrs rDnot_compressedz$TarFile.open..not_compressed4s}}X.);;rF)keyNrz - method z:  z'file could not be opened successfully: :r-rr|rzmode must be 'r' or 'w'r FrHzundiscernible mode)r<sortedr[rrrr rrrrpoprrrrZ)rrrrrykwargsr\ error_msgsrfunc saved_posrerror_msgs_summaryfilemoderstreamrs` rDrz TarFile.open s5JG./ / <  <J"3==nEsCMM($;<& ' Ic7=f== F"&:!6 FGYFZ[\ \ D[!%C!3 Hh3H(5H3==(sCMM($;<&'Dx'OPPh:6: : D[!%C!3 Hh3H(5Hz) !:;;"JJ:MT8Xw*,F h9&9"AMH _ $3;;tT7=f= =-..W"#34%% (2aU&CD* Y/ D  s$" F G G*GG Gc 6|dvr td||||fi|S)zCOpen uncompressed tar archive name for reading or writing. rErG)r<)rrrrrds rDrZzTarFile.taropenjs- + +@A A4w1&11rFc |dvr td ddlm} |||dz||} |j|||fi|}d |_ |S#t$r t ddwxYw#t $r}||dk(r t d |d}~wwxYw#t $r'}|j|dk(r t d |d}~w|jxYw) 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 availableNr|rrF) r<gziprorr rrrZrr) rrrrrrdrorrs rDgzopenzTarFile.gzopenrs  &;< < M % tTCZHG  D$:6:A + M"#AB L M  "ts{ 129    MMOs{ 129   MMO s9AABA B'A;;B C "B..Cc P|dvr td ddlm}||xs|||} |j |||fi|}d |_ |S#t$r t ddwxYw#t tf$r'}|j|dk(r td |d}~w|jxYw) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rmrnr)BZ2FilerN)rrznot a bzip2 fileF) r<rrsrr rZrEOFErrorrrr) rrrrrrdrsrrs rDbz2openzTarFile.bz2opens  &;< < L #'/T4}M  D$:6:A ! L"#@At K L"  MMOs{ 23:   MMO s"AAAB%-"BB%c L|dvr td ddlm}m}||xs|||} |j |||fi|}d |_ |S#t$r t ddwxYw#|tf$r'} |j|dk(r td | d} ~ w|jxYw) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rmrnr)LZMAFilerrN)presetrznot an lzma fileF) r<rrwrrr rZrtrrr) rrrrrxrdrwrrrs rDxzopenzTarFile.xzopens  &;< < M 07?dD@  D$:6:A ! M"#AB L M8$  MMOs{ 23:   MMO s"AA A B#+"B  B#rZrqrury)rrrrc|jryd|_ |jdvr|jjtt dzz|xj t dzz c_t|j t\}}|dkDr)|jjtt|z z|js|jjyy#|js|jjwwxYw)zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTrHr.r) rrrrur?r rrs RECORDSIZErr)rrzr{s rDrz TarFile.closes ;;   %yyO+ ""3)a-#89 A . %+4;; $C! q=LL&&sj9.D'EF## ""$$4## ""$$s BC)Dcf|j|jd}|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. rZzfilename %r not found) _getmemberrKeyError)rrr>s rD getmemberzTarFile.getmembers6 //$++c"23 ?2T9: :rFcr|j|js|j|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. )_checkrS_loadrRrs rD getmemberszTarFile.getmemberss' || JJL||rFc\|jDcgc]}|jc}Scc}w)zReturn the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). )rr)rr>s rDgetnameszTarFile.getnamess)-1OO,=>,= ,=>>>s)c.|jd| |j}||}tjj |\}}|j tj d}|jd}|j}||_ |8|jstj|}n9tj|}n#tj|j}d}|j}tj |r|j"|j$f} |jsE|j&dkDr6| |j(vr(||j(| k7rt*} |j(| }nt,} | dr||j(| <ntj.|rt0} ntj2|rt4} njtj6|rt8} tj:|}n9tj<|rt>} ntj@|rtB} ny||_||_"|jF|_$|jJ|_&| t,k(r|jN|_(nd|_(|jR|_*| |_+||_,tZr( t[j\|jHd|_/tbr( tcjd|jLd|_3| t>tBfvrhtitdrXtitdrHtjj|jl|_7tjp|jl|_9|S#t`$rYwxYw#t`$rYwxYw) aCreate a TarInfo object from the result of os.stat or equivalent on an existing file. The file is either named by `name', or specified as a file object `fileobj' with a file descriptor. If given, `arcname' specifies an alternative name for the file in the archive, otherwise, the name is taken from the 'name' attribute of 'fileobj', or the 'name' argument. The name should be a text string. awxNrZrr-rmajorminor):rrrr/ splitdriverr`rar>r=rMlstatstatfstatfilenost_modeS_ISREGst_inost_devst_nlinkrTr.rS_ISDIRrS_ISFIFOr4S_ISLNKr,readlinkS_ISCHRrS_ISBLKrrst_uidr3st_gidr4st_sizer1st_mtimer2rzr]pwdgetpwuidr5r~grpgetgrgidr6rrst_rdevr{rr|) rrarcnamerdrvr>statresr]stmdinoderzs rD gettarinfozTarFile.gettarinfos E  < zlink to )rrrrrir5r3r6r4r0r2r{r|r1r2r localtimerrfrgr]rer)rverboserRr>s rDrz TarFile.listisf ?GG<<' - gll ;<w}}'C 'C'.}}'C 'CEF==?gmmo$(8(8':J:J'KK!MN  56==( 56 ="&.."?"C!DE  w}}BG H==?(8(8 89==? W-=-= => G5rFfiltercb|jd||}|jBtjj ||jk(r|j dd|zy|j d||j ||}||j dd|zy| ||}||j dd|zy|jr(t|d5}|j||dddy|jr|j||ruttj|D]S}|jtjj||tjj|||| Uyy|j|y#1swYyxYw) 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 %rrBr)rrrr/rL_dbgrrdrKaddfilerfrblistdiraddr)rrr recursiverr>fs rDrz TarFile.addsq E ?G 99 RWW__T%:dii%G IIa.5 6  !T//$0 ? IIa7$> ?   WoG !3d:; ==?4&! Wa('&]]_ LL ! 4 01AHHRWW\\$2BGGLL!4L%f62 LL !'&s F%%F.c|jdtj|}|j|j|j|j }|j j||xjt|z c_|j}|t||j |j|t|jt\}}|dkDr.|j jtt|z z|dz }|xj|tzz c_|j j#|y)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)ryrr-)rrrrbrBrCrrurr>rQrrr1rsr r?rRr)rr>rrkryrzr{s rDrzTarFile.addfiles E))G$mmDKK D 3 s3x      w||W M &w||Y ? FI1} ""3)i*?#@A!  KK6I- -K G$rFc|M|j}|"tjdtdtSt |t r td|St|r|S t|S#t$rtd|ddwxYw)NzPython 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior.r) stacklevelzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z not found) extraction_filterwarningswarnDeprecationWarningrrr TypeErrorcallable_NAMED_FILTERSr~r<)rrs rD_get_filter_functionzTarFile._get_filter_functions >++F~ J'1 6 ,+&#&677M F M G!&) ) Gwvj ;<$ F Gs A''B) numeric_ownerrcg}|j|}||}|D]a}|j|||\}} ||jr|j| |j |||j ||c|j dd|D]} || |}||j| d#tjj||j} tj| } tj | j"s|j|d|j%|| | |j'|| |j)|| y#t $r%} |j| t| Yd} ~ d} ~ wwxYw#t$r|j|dYwxYw#t*$r} |j-| Yd} ~ Cd} ~ wwxYw) 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_attrsrfilter_functionc|jSrr)rFs rDz$TarFile.extractall.. sqvvrFT)r]reversezexcluded by filtermissingznot a directory)r)r_get_extract_tarinforfr _extract_onesort_FILTER_ERRORS_log_no_directory_fixupreprrr/rrrFileNotFoundErrorrrrchownutimechmodr _handle_nonfatal_error)rr/rRrr directoriesrrjr> unfilteredexcdirpathrrs rD extractallzTarFile.extractalls 33F; ?GF"&";";#/ GZ}}"":.   gt7==?7J,9.=  ? -t<&J /-j$?G?001EG'',,tW\\:HHW-E||EMM200:KL 7G= I 7G, 7G,5& &00T#YG)00)D  /++A.. /sl E$"F77*F7"F71F7)8F7$ F-F F7 FF7F40F73F44F77 GGGcJ|jdd|jd|dy)Nr.z!tarfile: Not fixing up directory z ())rr)rrjreasons rDrzTarFile._log_no_directory_fixup7 s !;;( )rFc|j|}|j|||\}}||j||||yy)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) rrjr/rrrrr>rs rDextractzTarFile.extract; sO33F;"77 OT+     gtY F rFct|tr|j|}n|}d} |||}| |jdd|jzy|jrDtj|}tjj||j|_||fS#ttf$r}|j |Yd}~d}~wt $r}|j|Yd}~d}~wwxYw)zGet (filtered, unfiltered) TarInfos from *member* *member* might be a string. Return (None, None) if not found. Nr.r)NN)rrrrr_handle_fatal_errorr rrrrerrr/rr]r)rrjrr/rfilteredrs rDrzTarFile._get_extract_tarinfoO s fc "/JJ +&z48H   IIa/*//A B >> yy*H$&GGLLx7H7H$IH !##% (  $ $Q ' ' +  ' ' * * +s# B++C7:C C7C22C7c8|jd |j|tjj ||j ||||y#t $r}|j|Yd}~yd}~wt$r}|j|Yd}~yd}~wwxYw)zExtract from filtered tarinfo to disk. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a symlink) r)rrrextraction_rootN) r_extract_memberrr/rrrrr r)rr>r/rrrrs rDrzTarFile._extract_onem s C +  "'',,tW\\*J+4/<1@15 ! 7  (  $ $Q ' ' +  ' ' * * +s#?A BA22 B>BBcN|jdkDr|jdd|zy)z=Handle non-fatal error (ExtractError) according to errorlevelr- tarfile: %sN)rPrrrs rDrzTarFile._handle_nonfatal_error s$ ??Q   IIa* +rFcL|jdkDrt|trY|j |j dd|j zy|j dd|j d|jy|j ddt |jd|y)z1Handle "fatal" error according to self.errorlevelrNr-rz tarfile: r)rPrrfilenamerstrerrorrzrrs rDrzTarFile._handle_fatal_error st ??Q   7 #zz! !]QZZ78 !QZZHI IIaT!W-=-=qA BrFc|jdt|tr|j|}n|}|j s|j t vr|j||S|js|jrEt|jtr td|j|j|Sy)a\Extract a member from the archive as a file object. `member' may be a filename or a TarInfo object. If `member' is a regular file or a link, an io.BufferedReader object is returned. For all other existing members, None is returned. If `member' does not appear in the archive, KeyError is raised. rz'cannot extract (sym)link as file objectN)rrrrrdrzr fileobjectrergrrr extractfile_find_link_target)rrjr>s rDrzTarFile.extractfile s C fc "nnV,GG ==?gll/A??41 1 ]]_ $,,0""KLL''(>(>w(GHHrFrrc|jd}|jdtj}tjj |}|r4tjj |stj||js|jr,|jd|jd|jn|jd|j|jr|j||n|jr|j!||n|j#r|j%||n|j's|j)r|j+||nm|js|jr|j-||||n7|j.t0vr|j3||n|j|||rI|j5||||js%|j7|||j9||yyy)zExtract the filtered TarInfo object tarinfo to a physical file called targetpath. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a symlink) rZr-z -> rN)rrrr`r/rirJmakedirsrergrrr]rdmakefilerfmakedirr5makefifor0r2makedevmakelink_with_filterrzr makeunknownrrr)rr> targetpathrrrr upperdirss rDrzTarFile._extract_member s &&s+ ''RVV4 GGOOJ/ RWW^^I6 KK " ==?gmmo IIaw||W5E5EF G IIa & ==? MM': . ]]_ LL* - ^^  MM': . ]]_  LL* - ]]_   % % / / & 1\\ 0   Wj 1 MM': .  JJw M :==? 7J/ 7J/# rFc |jtj|ytj|dy#t$r#tjj |sYywxYw)z,Make a directory called targetpath. Ni)rrmkdirFileExistsErrorr/rfrr>rs rDrzTarFile.makedir sT ||#$U+ 77==,- s!;;)A'&A'c |j}|j|j|j}t |d5}|j d|j D])\}}|j|t |||t|+|j|j|jnt |||jt|dddy#1swYyxYw)z'Make a file called targetpath. rCN) rrr:rQrKr;rrrr1truncate)rr>rsourcerytargetrr1s rDrzTarFile.makefile s G''("" z4 (F~~)$+NNLFDKK'iI%3 GLL)!FFGLL)WM) ( (s BCC cf|j|||jdd|jzy)zYMake a file from a TarInfo object with an unknown type at targetpath. r-z9tarfile: Unknown file type %r, extracted as regular file.N)rrrzrs rDrzTarFile.makeunknown s3 gz* !24;LLA BrFcdttdrtj|ytd)z'Make a fifo called targetpath. mkfifozfifo not supported by systemN)rrrr rs rDrzTarFile.makefifo s& 2x IIj !=> >rFcfttdrttds td|j}|d}|j r|t j z}n|t jz}tj||tj|j|jy)zrrs rDrzTarFile.makedev sr7#72y+AHI I|| <D ==? DLL D DLL D TG,,g.>.>? ArFc*|j||ddSr)rrs rDmakelinkzTarFile.makelink- s((*dDIIrFcd} |jrUtjj|rtj|tj |j |ytjj|jr!tj|j|y |j|}||}n| td |||}||j#||||yy#t$rd}YTwxYw#t$r|r tddwxYw#t$r}t||j |d}~wwxYw)a3Make 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. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a link). FNTz%unable to resolve link inside archivez[makelink_with_filter: if filter_function is not None, extraction_root must also not be Noner)rgrr/lexistsunlinksymlinkr]rJrlinksymlink_exceptionrr~r rrWrr) rr>rrrkeyerror_to_extracterrorrrcauses rDrzTarFile.makelink_with_filter0 s]$)  ,}}77??:.IIj) 7++Z877>>'"6"67GGG00*=8  //8J  "!H&">?? M*:G    :1@1@ ! B /! ,'+ $ ,  '";=BFG   " M'AuL Ms=A$C;)A C;5D  D(; D D  D%( E 1EE cttdrtjdk(r|j}|j}|sj t r.|j r"t j|j d} tr.|jr"tj|jd}|d}|d} |jr(ttdrtj|||ytj|||yyy#t$rYwxYw#t$rYuwxYw#t$r}t!d|d}~wwxYw)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.NrHlchownzcould not change owner)rrrr4r3rr6getgrnamr~rr5getpwnamrgrrrr )rr>rrgurs rDrz TarFile.chownb s 2y !bjjla&7 A A w}}LL7:w}}LL7:yy D==?wr8'<IIj!Q/HHZA./'8 !    D"#;rrs rDrz TarFile.chmod sF <<   ? HHZ . ?67Q > ?s 0 A  AA c|j}|yttdsy tj|||fy#t$r}t d|d}~wwxYw)zBSet modification time of targetpath according to tarinfo. Nrz"could not change modification time)r2rrrrr )rr>rr2rs rDrz TarFile.utime sZ  = r7#  L HHZ% 0 LCD! K Ls; A AAcL|jd|j|j}d|_|S|j|jj k7r^|jdk(ry|jj |jdz |jj ds tdd} |jj|} ||j0j3||Sd|_|S#t$rU}|jr?|jdd|j|fz|xjtz c_Yd}~Yd}~d}~wt$rz}|jr?|jdd|j|fz|xjtz c_Yd}~|jdk(rtt|dYd}~d}~wt $r|jdk(r td dY-t"$r/}|jdk(rtt|dYd}~_d}~wt$$r}tt|dd}~wt&$r@} ddl}t+||j,rtd |d|#t.$r|wxYwd}~wwxYw) 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-rpTr.z0x%X: %sz empty filez zlib error: )rrUrrrrrtrr>rrrNrr rYrrrr ExceptionrrrrrRrrS)rmr>rrs rDrz TarFile.next sR D    '  A#D H ;;$,,++- -{{a LL  dkkAo .<<$$Q' 899 ,,2248<    LL   ( DLI" $$IIat{{A.>!>?KK9,K%& 6$$IIat{{A.>!>?KK9,K[[A%#CF+5&# <;;!##L1t;$' 6;;!##CF+5$( 2A'T1 !!TZZ0',qc(:;E"G sb<D J# AE J#%AG0$G'J#J# $H66 J#I J#$+J JJJ#c|j}d}| |j|}|d|}|rtjj |}t |D]a}|r|j|jk(rd}!|r*tjj |j}n |j}||k(s_|cS|r t|y#t$rd}YwxYw)z}Find an archive member by name from bottom to top. If tarinfo is given, it is used as the starting point. FNT) rindexr<rr/rhreversedrr) rrr> normalizerRskippingr rj member_names rDr}zTarFile._getmember s //#   * g."&5/ 77##D)Dw'F>>V]]2$H gg..v{{; $kk {" ( W% % 1   sC CCcV|j |jd|_y)zWRead through the entire archive file and look for readable members. NT)rrSrs rDrz TarFile._load s(iik% iik% rFc|jr"td|jjz|'|j|vrtd|jzyy)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)rrr?rr)rrs rDrzTarFile._check sS ;;.4>>+B+BBC C    55 AB B!6 rFc,|jrQdjtdtjj |j |jf}d}n|j}|}|j||d}|td|z|S)zZFind the target member of a symlink or hardlink member in the archive. rZNT)r>r"zlinkname %r not found) rgrrrr/rirr]r}r~)rr>r]limitrjs rDrzTarFile._find_link_target s ==?xxtbggoogll.KWM]M]-^ _`HE''HE5DI >2X=> > rFc#RK|jr|jEd{yd}|j|j}|dz }| |t |jkr|j|}n'|js|j}|s d|_yy|dz }|Y7w)z$Provide an iterator object. Nrr-T)rSrRrUrr>)rr r>s rD__iter__zTarFile.__iter__( s <<|| # #     'iikG QJEMs4<<((,,u-\\))+#'DL QJEM $sB'B%BB'cZ||jkrt|tjyy)z.Write debugging output to sys.stderr. fileN)rOrrstderr)rlevelmsgs rDrz TarFile._dbgG s# DJJ  #CJJ ' rFc&|j|Sr)rrs rD __enter__zTarFile.__enter__M s  rFc||jy|js|jjd|_yr)rrrr)rrzr tracebacks rD__exit__zTarFile.__exit__Q s2 < JJL## ""$DKrF) NrNNNNNNrNNNN)rN)rNra)rNN)NNNTrr).N)rT)TFr")@rrrrrOrMrNrPrrbr rBrCrr>r8rrrr>r{rrZrqruryr[rrrrrrrrrrrrrrrrrrrrrrrr rrrrrr}rrrr*rr2r5rrFrDrrs EKLJFH FGJAEHL>B)-b^#tZ]/]/~22@6: I%* ? aF$D$L1"1"f%2G.C/%C/J)GG($>&*+(, C@>B&+10@D(,10p N B?A$J0BdDB? L<B&&PC&>( rFrc t|dr.|j}t|}|j|n t|}|j y#t $rYywxYw)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. rt)rTF)rrrrrr)rrrs rDrr_ sX  4 ))+CT"A IIcNT A   sAA A$#A$c ddl}d}|j|}|jddddd |jd d td |j d}|jdddd|jddddd|jddddd|jdd dd!|j }|j r|j|jd"d#|j|j}t|rut|d$5}|jt|jtj%ddd|j r=td&j#|y|jd"d'j#|yy|j$u|j$}t|rzFilter for extraction)metavarchoicesr>T)requiredz-lz--list zShow listing of a tarfile)r?r>z-ez --extract+)rBz 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 rr,z{!r} is a tar archive.z{!r} is not a tar archive. rX)rr.)r/rr7z{!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_argsrrexittestrrrrrr.rrbrrr>rcurdir format_helprcreatercr/splitextr)rEr:parserrargsrvrtfrLr0tar_namerext compressionstar_mode tar_files file_names rDmainrYt sGK  $ $ $ =F k,-/  N .46  / / / >E tX{79 t[<=? tZs39; tX{8:    D {{t||+ A@A yyii c?c33 cnn&SZZ8 ||.55c:; KK9@@E F  ii c?c5)R -*) KK9@@E F  ! t||  !,,q/CYYF  ! #,,KC KK6--/ 0 c?c5)R 6$++ >*||S=3::3?C2396#v3Fc KK9@@E F  ;;??1%!!(+3  03l/B4,s++KK \\(H -& y!'. << &--h7 8 / !M *)*)>. -s0:P-P:Q"Q-P7:QQQ__main__r6)nrversion __author__ __credits__builtinsrrKrrr)rqrrrirrerrrrAttributeErrorNotImplementedErrorrr__all__r?r r{rrrrrrrr.r,rrrr4CONTTYPErrrrrrrrrrrr&rrrrrWrrr getfilesystemencodingrErLr\rdrnrrrrrr rr r r rrrrYrrrobjectrrBufferedReaderr8rrrrrrrWrrprrrrrcompilerrrrrYrrrFrDrhs:6 H ' $%8'B *   ^                    HgGXWg#%5! #(>+ /   . 9       77d?H(s((*H 0& (N < *"&$ 2 y  8    x  (  (  {  ;  [    K 0rrj6