asda?‰PNG  IHDR ? f ??C1 sRGB ??é gAMA ±? üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T a bYh @sdZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZz ddlZWneydZYn0z ddlZWneydZYn0eefZzeef7ZWneyYn0gdZdZd Zed Zd 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!Zne?Z>d$d%Z@d&d'ZAd(d)ZBd*e4fd+d,ZCd-d.ZDdedfd/d0ZEd1d2ZFGd3d4d4eGZHGd5d6d6eHZIGd7d8d8eHZJGd9d:d:eHZKGd;d<dd>eHZMGd?d@d@eMZNGdAdBdBeMZOGdCdDdDeMZPGdEdFdFeMZQGdGdHdHeMZRGdIdJdJZSGdKdLdLZTGdMdNdNeUZVGdOdPdPeUZWGdQdRdRe jXZYGdSdTdTeHZZGdUdVdVeZZ[GdWdXdXeZZ\GdYdZdZeZZ]Gd[d\d\eZZ^Gd]d^d^eZZ_drd`daZ`dbdcZadddeZbdfdgZceaebecdhZdeUZeGdidjdjeUZfGdkdldleUZgdmdnZhegjZdodpZiejdqkreidS)sz,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&)Zatimectimer(r)r*r'ntutf-8cCs8|durtd|||}|d||t|tS)z8Convert a string to a null-terminated bytes object. Nzmetadata cannot contain None) ValueErrorencodelenNUL)slengthencodingerrorsr8#/usr/local/lib/python3.9/tarfile.pystns r:cCs*|d}|dkr|d|}|||S)z8Convert a null-terminated bytes object to a string. rN)finddecode)r4r6r7pr8r8r9ntss  r?cCs|ddvrbd}tt|dD]}|dK}|||d7}q |ddkrdt|d| }n>z"t|dd}t|p|d d}Wntytd Yn0|S) z/Convert a number field to a python number. r)r#rAasciistrict0invalid header)ranger2r?intstripr0InvalidHeaderError)r4nir8r8r9ntis    rNrBcCst|}d|kr$d|dkrDnntd|d|fdt}n|tkrd|d |krrd|dkrnnV|dkrtdg}ntdg}d||}t|dD]}|d|d@|dL}qntd |S) z/Convert a python number to a number field. rrBr#z%0*orDrCr@rAzoverflow in number field)rIbytesr3r bytearrayrHinsertr0)rLdigitsformatr4rMr8r8r9itns  2    rTcCs0dttd|}dttd|}||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. rCZ 148B8x356BZ 148b8x356b)sumstruct unpack_from)bufZunsigned_chksumZ signed_chksumr8r8r9 calc_chksumss rYc Cs|pd}|dkrdS|dur.t|||dSt||\}}t|D],}||}t||krf|d||qD|dkr||}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 copyfileobjdivmodrHreadr2write) srcdstr5 exceptionbufsizeblocks remainderbrXr8r8r9r\s$       r\cCs8ttjdd}|dur(||d|}t|dddS)Nr6backslashreplace )end)getattrsysstdoutr1r=print)r4r6r8r8r9 _safe_printsrnc@seZdZdZdS)rzBase exception.N__name__ __module__ __qualname____doc__r8r8r8r9rsrc@seZdZdZdS)r z%General exception for extract errors.Nror8r8r8r9r sr c@seZdZdZdS)rz&Exception for unreadable tar archives.Nror8r8r8r9rsrc@seZdZdZdS)rz.Exception for unavailable compression methods.Nror8r8r8r9rsrc@seZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.Nror8r8r8r9r sr c@seZdZdZdS)r z!Base exception for header errors.Nror8r8r8r9r sr c@seZdZdZdS)EmptyHeaderErrorzException for empty headers.Nror8r8r8r9rt srtc@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.Nror8r8r8r9ru#sruc@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.Nror8r8r8r9rv&srvc@seZdZdZdS)rKzException for invalid headers.Nror8r8r8r9rK)srKc@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nror8r8r8r9rw,srwc@s0eZdZdZddZddZddZdd Zd S) _LowLevelFilezLow-level file object. Supports reading and writing. It is used instead of a regular file object for streaming access. cCsFtjtjtjBtjBd|}ttdr2|tjO}t||d|_dS)NrwO_BINARYi) osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrr|rfd)selfnamemoder8r8r9__init__9s  z_LowLevelFile.__init__cCst|jdSN)r}closerrr8r8r9rBsz_LowLevelFile.closecCst|j|Sr)r}r^rrr'r8r8r9r^Esz_LowLevelFile.readcCst|j|dSr)r}r_rrr4r8r8r9r_Hsz_LowLevelFile.writeN)rprqrrrsrrr^r_r8r8r8r9rx3s  rxc@sreZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dddZ ddZ ddZddZdS)_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. c Csd|_|durt||}d|_|dkr6t|}|}|pd|fg}d|_g|_d}|j}|D]L\}}||kr||j d||df|j d||||f||7}||}qX||jkr|j d||jdfdS)NrrFT) roffsetr'positionrjrr map_indexmapr)rrrr'Z blockinfoZlastposZrealposr8r8r9ras(    z_FileInFile.__init__cCsdSrr8rr8r8r9rzsz_FileInFile.flushcCsdSNTr8rr8r8r9readable}sz_FileInFile.readablecCsdS)NFr8rr8r8r9writablesz_FileInFile.writablecCs |jSr)rseekablerr8r8r9rsz_FileInFile.seekablecCs|jS)z*Return the current file position. )rrr8r8r9rsz_FileInFile.tellcCs|tjkr tt|d|j|_nj|tjkr\|dkrFt|j|d|_qt|j||j|_n.|tjkrtt|j||jd|_ntd|jS)z(Seek to a position in the file. rzInvalid argument) ioSEEK_SETminmaxr'rSEEK_CURSEEK_ENDr0)rrwhencer8r8r9rs   z_FileInFile.seekc Cs |dur|j|j}nt||j|j}d}|dkr|j|j\}}}}||jkr`|krhqnqq6|jd7_|jt|jkr6d|_q6t|||j}|r|j||j||j|}t||krt d||7}n |t |7}||8}|j|7_q,|S)z!Read data from the file. Nrrr#rZ) r'rrrrr2rrr^rr3) rr'rXdatastartstoprr5rfr8r8r9r^s,     z_FileInFile.readcCs&|t|}||dt|<t|Sr)r^r2)rrfrXr8r8r9readintosz_FileInFile.readintocCs d|_dSr)rrr8r8r9rsz_FileInFile.close)N)N)rprqrrrsrrrrrrrrrr^rrr8r8r8r9r[s  rcseZdZfddZZS) ExFileObjectcs&t|j|j|j|j}t|dSr)rr offset_datar'sparsesuperr)rtarfiletarinfor __class__r8r9rs zExFileObject.__init__rprqrrr __classcell__r8r8rr9rsrc@s eZdZdS) FilterErrorN)rprqrrr8r8r8r9rsrcseZdZfddZZS)AbsolutePathErrorcs ||_td|jddS)Nzmember z has an absolute pathrrrrrrrr8r9rszAbsolutePathError.__init__rr8r8rr9rsrcseZdZfddZZS)OutsideDestinationErrorcs.||_||_t|jd|dddS)Nz would be extracted to , which is outside the destinationr_pathrrrrrr%rr8r9rs z OutsideDestinationError.__init__rr8r8rr9rsrcseZdZfddZZS)SpecialFileErrorcs||_t|jddS)Nz is a special filerrrr8r9rszSpecialFileError.__init__rr8r8rr9rsrcseZdZfddZZS)AbsoluteLinkErrorcs||_t|jddS)Nz is a link to an absolute pathrrrr8r9rszAbsoluteLinkError.__init__rr8r8rr9rsrcseZdZfddZZS)LinkOutsideDestinationErrorcs.||_||_t|jd|dddS)Nz would link to rrrrrr8r9rs z$LinkOutsideDestinationError.__init__rr8r8rr9rsrTcCsi}|j}tj|}|dtjfr@|jdtj}|d<tj|rTt|tjtj ||}tj ||g|krt |||j }|dur|d@}|r| s|r|d@s|dM}|dO}n|s|rd}nt|||j kr||d<|r|jdurd|d<|jdur*d|d <|jdur>d|d <|jdurRd|d <|sf|rtj|jr~t||rtj |tj||j}ntj ||j}tj|}tj ||g|krt|||S) N/ri@irr)r*r+r,)rr}r%realpathrseplstripisabsrr commonpathrrisregislnkisdirissymrr)r*r+r,linknamerdirnamer)member dest_pathZfor_data new_attrsrZ target_pathrr8r8r9_get_filtered_attrss^             rcCs|Srr8)rrr8r8r9fully_trusted_filter/srcCs,t||d}|r(|jfi|ddiS|S)NFdeeprrrrrr8r8r9 tar_filter2s rcCs,t||d}|r(|jfi|ddiS|S)NTrFrrr8r8r9 data_filter8s r)Z fully_trustedrrc@seZdZdZedddddddd d d d d dddddddddZdiddZeddZej ddZeddZ e j ddZ ddZ e e e e e e e e d e d! d"d#Z d$d%Zeed&fd'd(Zd)d*Zd+d,Zd-d.Zed/d0Zd1d2Zed3d4Zed5d6Zed7d8Zed9d:Zed;d<Zed=d>Zd?d@ZdAdBZ dCdDZ!dEdFZ"dGdHZ#dIdJZ$dKdLZ%dMdNZ&dOdPZ'dQdRZ(dSdTZ)dUdVZ*dWdXZ+dYdZZ,d[d\Z-d]d^Z.d_d`Z/dadbZ0dcddZ1dedfZ2dgdhZ3dS)jraInformational 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. zName of the archive member.zPermission bits.z6User ID of the user who originally stored this member.z7Group ID of the user who originally stored this member.zSize in bytes.zTime of last modification.zHeader checksum.zFile type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.zcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.z User name.z Group name.zDevice major number.zDevice minor number.zThe tar header starts here.zThe file's data starts here.zMA dictionary containing key-value pairs of an associated pax extended header.zSparse member information.N)rrr)r*r'r(chksumtyper r+r,devmajordevminorrr pax_headersrr_sparse_structs _link_targetrcCsj||_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(rREGTYPErr r+r,rrrrrrrrr8r8r9rns"zTarInfo.__init__cCs|jS)z(In pax headers, "name" is called "path".rrr8r8r9r%sz TarInfo.pathcCs ||_dSrr"r!r8r8r9r%scCs|jS)z0In pax headers, "linkname" is called "linkpath".r rr8r8r9r&szTarInfo.linkpathcCs ||_dSrr#)rr r8r8r9r&scCsd|jj|jt|fS)Nz<%s %r at %#x>)rrpridrr8r8r9__repr__szTarInfo.__repr__T) rr(rr r)r*r+r,r_KEEPc Cs| rt|} n t|} || ur(|| _|| ur6|| _|| urD|| _|| urR|| _|| ur`|| _|| urn|| _|| 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,rr&resultr8r8r9rs(  zTarInfo.replacecCs|jdurd}n |jd@}|j||j|j|j|j|j|j|j|j |j |j |j d }|dt kr||dds||dd7<|S)z9Return the TarInfo's attributes as a dictionary. N) rrr)r*r'r(rrr r+r,rrrrr)rrr)r*r'r(rrr r+r,rrDIRTYPEr)rrinfor8r8r9get_infos(  zTarInfo.get_infosurrogateescapecCsz|}|D]\}}|durtd|q|tkrD||||S|tkrZ||||S|tkrn|||StddS)zq*z||dd Wn"tyt||||<Yq*Yn0t|||kr*||||<q*d D]\}}d }||} t| t } | rt | n| } d | krd |dksnd ||<d}n| r| ||<d}|r||vrt | ||<q|r4| |t |} nd} | ||tddS)zReturn the object as a ustar header block. If it cannot be represented this way, prepend a pax extended header sequence with supplement information. r5rr%r r&)r+r+ )r,r,r@rDrE))r)rB)r*rB)r' )r(rAFrrBr#Trr)r7rr'r9r8r1UnicodeEncodeErrorr2 isinstancefloatroundstr_create_pax_generic_headerXHDTYPEr;r ) rr,r6rrZhnamer5rRZ needs_paxvalZ val_is_floatZval_intrXr8r8r9r2s>       zTarInfo.create_pax_headercCs||tdS)zAReturn the object as a pax global header block sequence. r/)rGXGLTYPE)clsrr8r8r9create_pax_global_header9sz TarInfo.create_pax_global_headercCs~|d}tdt|D]T}d|d|}d||d}t|||tkrt|||tkrqvqtd||fS)zUSplit a name longer than 100 chars into a prefix and a name part. rr#Nzname is too long)splitrHr2rr1 LENGTH_PREFIXr9r0)rrr6r7 componentsrMr6r8r8r9r:?s zTarInfo._posix_split_namec Cs|dttfv}|r@t|ddd|}t|ddd|}ntdd||}tdd||}|dt}|durxtdt|d dd ||t|d dd @d|t|d dd|t|ddd|t|ddd|t|ddd|d|t|ddd |||dtt|ddd||t|ddd||||t|ddd||g}t dt d |} t | t dd} | ddt d| d| dd} | S) zReturn a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants. rrrrBrrNzTarInfo.type must not be Nonerrrr*r)r*r'rAr(s r r5r+r@r,r6rz%dsriz%06orDi)getCHRTYPEBLKTYPErTr:r r0r7rVrrrrYrO) r,rSr6r7Zhas_device_fieldsrrZfiletypepartsrXrr8r8r9r;Os:  &zTarInfo._create_headercCs.tt|t\}}|dkr*|t|t7}|S)zdReturn the string payload filled with zero bytes up to the next 512 byte border. r)r]r2rr3)payloadrdrer8r8r9_create_payloadyszTarInfo._create_payloadcCsR|||t}i}d|d<||d<t||d<t|d<||t||||S)zTReturn a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence for name. z ././@LongLinkrrr'r5)r1r3r2r<r;r rU)rKrrr6r7r,r8r8r9r=s zTarInfo._create_gnu_long_headerc Cs0d}|D]6\}}z|ddWq ty@d}YqDYq 0q d}|rT|d7}|D]\}}|d}|r||d}n |d}t|t|d}d } } |tt| } | | krq| } q|tt| d d |d |d 7}q\i} d| d<|| d<t|| d<t| d<|| td d| |S)zReturn a POSIX.1-2008 extended or global header sequence that contains a list of keyword, value pairs. The values must be strings. Fr/rETrs21 hdrcharset=BINARY r.rrrD = z././@PaxHeaderrrr'r5r) r/r1rBr2rFrOr7r;r rU) rKrrr6binarykeywordr3recordslrLr>r,r8r8r9rGs<   ( z"TarInfo._create_pax_generic_headerc Cstt|dkrtdt|tkr(td|ttkr>tdt|dd}|t|vrbt d|}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||}|jtkr|j drt|_|jtkr6d}g}tdD]j} z0t|||d} t||d|d} WntyYqYn0|| | f|d7}qt|d} t|dd} || | f|_ |!rN|j "d|_ |rp|jt#vrp|d|j |_ |S)zAConstruct a TarInfo object from a 512 byte bytes object. rz empty headerztruncated headerzend of file headerz bad checksumrlt|ii i)iIiQiYirirrAiii)$r2rtrrucountr3rvrNrYrKr?rrr)r*r'r(rrr r+r,rrAREGTYPErr+GNUTYPE_SPARSErHr0rboolrr rstrip GNU_TYPES)rKrXr6r7robjr6rstructsrMrnumbytes isextendedorigsizer8r8r9frombufsZ         zTarInfo.frombufcCs8|jt}|||j|j}|jt|_||S)zOReturn the next TarInfo object from TarFile object tarfile. ) rr^rrpr6r7rr _proc_member)rKrrXrkr8r8r9 fromtarfiles zTarInfo.fromtarfilecCsT|jttfvr||S|jtkr,||S|jtttfvrF| |S| |SdS)zYChoose the right processing method depending on the type and call it. N) rr?r> _proc_gnulongrg _proc_sparserHrJSOLARIS_XHDTYPE _proc_pax _proc_builtin)rrr8r8r9rqs    zTarInfo._proc_membercCsR|j|_|j}|s$|jtvr4|||j7}||_| |j |j |j |S)zfProcess a builtin type or an unknown type which will be treated as a regular file. ) rrrr rSUPPORTED_TYPES_blockr'r_apply_pax_inforr6r7)rrrr8r8r9rw(s zTarInfo._proc_builtincCs|j||j}z||}Wnty<tdYn0|j|_|jt krdt ||j |j |_ n|jtkrt ||j |j |_|S)zSProcess the blocks that hold a GNU longname or longlink member. missing or bad subsequent header)rr^ryr'rrr rwrrr?r?r6r7rr>r )rrrXnextr8r8r9rs9s   zTarInfo._proc_gnulongc Cs|j\}}}|`|r|jt}d}tdD]l}z0t|||d}t||d|d} WntyxYqYn0|r| r||| f|d7}q,t|d}q||_ |j |_ |j | |j |_||_ |S)z8Process a GNU sparse header plus extra headers. rrArdi)rrr^rrHrNr0rrhrrrryr'r) rrrlrnrorXrrMrrmr8r8r9rtOs(       zTarInfo._proc_sparsecCs,|j||j}|jtkr&|j}n |j}t d|}|durX| d d|d<| d}|dkrr|j }nd}td}d}|||}|sq6|\} } t| } | dkrtd ||d d|d| d} || dd|j} | tvr|| ||j |j} n|| dd|j} | || <|| 7}qz||} Wnty`td Yn0d |vrz|| |nHd |vr|| ||n.| ddkr| ddkr|| |||jttfvr(| ||j |j|j!| _!d|vr(| j"} | #s| jt$vr"| | | j7} | |_!| S)zVProcess an extended or global header as described in POSIX.1-2008. s\d+ hdrcharset=([^\n]+)\nNr#r/ hdrcharsetZBINARYs(\d+) ([^=]+)=rrGr$r{GNU.sparse.mapGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrFr')%rr^ryr'rrJrr'researchgroupr=rPr6compilematchgroupsrIrKrir_decode_pax_fieldr7PAX_NAME_FIELDSrrr rw_proc_gnusparse_01_proc_gnusparse_00_proc_gnusparse_10rHrurzrrr rx)rrrXrrr~r6Zregexrr5rZr3r|rr8r8r9rvksh       $         zTarInfo._proc_paxcCshg}td|D]}|t|dqg}td|D]}|t|dq:tt|||_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)rfinditerrrIrlistzipr)rr|rrXZoffsetsrrmr8r8r9rszTarInfo._proc_gnusparse_00cCs@dd|ddD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|qSr8)rI).0xr8r8r9 rz.TarInfo._proc_gnusparse_01..r,Nr$r#)rMrrr)rr|rrr8r8r9rszTarInfo._proc_gnusparse_01cCsd}g}|jt}|dd\}}t|}t||dkrtd|vrT||jt7}|dd\}}|t|q,|j|_t t |ddd|ddd|_ dS)z?Process a GNU tar extended sparse header, version 1.0. NrXr#r$) rr^rrMrIr2rrrrrr)rr|rrfieldsrrXZnumberr8r8r9rs  zTarInfo._proc_gnusparse_10c Cs|D]\}}|dkr&t|d|q|dkr@t|dt|q|dkrZt|dt|q|tvr|tvrzt||}Wntyd}Yn0|dkr|d}t|||q||_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namer%rr'zGNU.sparse.realsizerrN) r/setattrrI PAX_FIELDSPAX_NUMBER_FIELDSr0rir'r)rrr6r7rZr3r8r8r9rzs"   zTarInfo._apply_pax_infocCs2z||dWSty,|||YS0dS)z1Decode a single field from a pax record. rEN)r=UnicodeDecodeError)rr3r6Zfallback_encodingZfallback_errorsr8r8r9r s zTarInfo._decode_pax_fieldcCs"t|t\}}|r|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. r#)r]r)rrerdrer8r8r9ryszTarInfo._blockcCs |jtvSz4Return True if the Tarinfo object is a regular file.)r REGULAR_TYPESrr8r8r9r sz TarInfo.isregcCs|Sr)r rr8r8r9isfile szTarInfo.isfilecCs |jtkS)z!Return True if it is a directory.)rr+rr8r8r9r $sz TarInfo.isdircCs |jtkS)z%Return True if it is a symbolic link.)rSYMTYPErr8r8r9r (sz TarInfo.issymcCs |jtkS)z!Return True if it is a hard link.)rLNKTYPErr8r8r9r ,sz TarInfo.islnkcCs |jtkS)z(Return True if it is a character device.)rrQrr8r8r9ischr0sz TarInfo.ischrcCs |jtkS)z$Return True if it is a block device.)rrRrr8r8r9isblk4sz TarInfo.isblkcCs |jtkS)zReturn True if it is a FIFO.)rFIFOTYPErr8r8r9isfifo8szTarInfo.isfifocCs |jduSr)rrr8r8r9issparse<szTarInfo.issparsecCs|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)rrQrRrrr8r8r9isdev?sz TarInfo.isdev)r)4rprqrrrsdict __slots__rpropertyr%setterr&r%r&rr-rr r4r0r1r2 classmethodrLr: staticmethodr;rUr=rGrprrrqrwrsrtrvrrrrzrryr rr r r rrrrrr8r8r8r9rKs       :  )   2 >  h  rc @seZdZdZdZdZdZdZeZ e Z dZ e ZeZdZdfdd Zedddefd d Zedgd d ZedhddZediddZedjddZdddddZddZddZddZd d!Zdkd"d#Zdldd%d&d'Z dmdd(d)d*Z!dnd+d,Z"d-d.Z#doddd0d1d2Z$dpddd0d4d5Z%d6d7Z&d8d9Z'd:d;Z(dd?Z*dqd@dAZ+dBdCZ,dDdEZ-dFdGZ.dHdIZ/dJdKZ0dLdMZ1dNdOZ2dPdQZ3dRdSZ4dTdUZ5drdVdWZ6dXdYZ7dsdZd[Z8d\d]Z9d^d_Z:d`daZ;dbdcZd }| dvrRtdt || |||} z|| | fi|} Wn| Yn0d| _ | S|dvrj |||fi|StddS)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)rzr:*csj|dkS)Ntaropen) OPEN_METH)rrKr8r9not_compressedsz$TarFile.open..not_compressed)keyNrzz%file could not be opened successfully:r#rr|ryzmode must be 'r' or 'w'Frzundiscernible mode) r0sortedrrjrrrrrMrrrr) rKrrrrckwargsrrfuncZ saved_posfilemodestreamrr8rr9rsP%            z TarFile.opencKs$|dvrtd||||fi|S)zCOpen uncompressed tar archive name for reading or writing. rr)r0)rKrrrrr8r8r9r*szTarFile.taropenrcKs|dvrtdzddlm}Wnty:tdYn0z|||d||}Wn,ty~|durx|dkrxtd Yn0z|j|||fi|}Wn@ty||dkrtd Yn|Yn0d |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rzr{rmode must be 'r', 'w' or 'x'r)GzipFilezgzip module is not availablerfNrzrF) r0gziprrrrrrrr)rKrrr compresslevelrrrr8r8r9gzopen2s0   zTarFile.gzopenc Ks|dvrtdzddlm}Wnty:tdYn0||pD|||d}z|j|||fi|}WnDttfy||dkrt dYn|Yn0d |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rrr)BZ2Filer)rrzznot a bzip2 fileF) r0rrrrrrEOFErrorrrr)rKrrrrrrrr8r8r9bz2openSs& zTarFile.bz2openc Ks|dvrtdzddlm}m}Wnty>tdYn0||pH|||d}z|j|||fi|}WnD|tfy||dkrt dYn|Yn0d |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rrr)LZMAFilerr)presetrzznot an lzma fileF) r0rrrrrrrrrr) rKrrrrrrrrr8r8r9xzopenos& zTarFile.xzopenrrrr)rrrrcCs|jr dSd|_zp|jdvrn|jttd|jtd7_t|jt\}}|dkrn|jtt|W|j s|j n|j s|j 0dS)zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTrr$r) rrrr_r3rrr] RECORDSIZErr)rrdrer8r8r9rs  z TarFile.closecCs(||d}|dur$td||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. rNzfilename %r not found) _getmemberriKeyError)rrrr8r8r9 getmembers zTarFile.getmembercCs||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_loadrrr8r8r9 getmembersszTarFile.getmemberscCsdd|DS)zReturn the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). cSsg|] }|jqSr8r")rrr8r8r9rrz$TarFile.getnames..)rrr8r8r9getnamesszTarFile.getnamesc CsZ|d|dur|j}|dur$|}tj|\}}|tjd}|d}|}||_ |dur|j stt |}qt |}nt |}d}|j}t |r|j|jf} |j s|jdkr| |jvr||j| krt} |j| }nt} | dr||j| <nht |rt} nVt |r"t} nDt |r>t} t|}n(t |rPt} nt |rbt!} ndS||_||_"|j#|_$|j%|_&| tkr|j'|_(nd|_(|j)|_*| |_+||_,t-rzt-.|j$d|_/Wnt0yYn0t1rzt12|j&d|_3Wnt0yYn0| tt!fvrVt4tdrVt4tdrVt5|j6|_7t8|j6|_9|S) 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. awxNrrr#rmajorminor):rrr}r% splitdriverrrrrrlstatstatfstatfilenost_modeS_ISREGst_inost_devst_nlinkrrr S_ISDIRr+S_ISFIFOrS_ISLNKrreadlinkS_ISCHRrQS_ISBLKrRrst_uidr)st_gidr*st_sizer'st_mtimer(rr pwdgetpwuidr+rgrpgetgrgidr,rrst_rdevrrr) rrarcnamerdrvrZstatresr Zstmdinoderr8r8r9 gettarinfos                 zTarFile.gettarinfoT)rcCs*||dur|}|D] }|r|jdur6tdntt|jtd|jpT|j|jp^|jf| sv| rtdd|j |j fntd|j |jdurtdntdt|jdd t|j|rd nd |r|rtd |j|rtd |jtqdS)aPrint a table of contents to sys.stdout. If `verbose' is False, only the names of the members are printed. If it is True, an `ls -l'-like output is produced. `members' is optional and must be a subset of the list returned by getmembers(). Nz ??????????z%s/%sz%10sz%d,%dz%10dz????-??-?? ??:??:??z%d-%02d-%02d %02d:%02d:%02drrrz-> zlink to )rrrnrrr+r)r,r*rrrrr'r(r localtimerr r r r rm)rverboserrr8r8r9r)s8        z TarFile.listfiltercCsL|d|dur|}|jdurFtj||jkrF|dd|dS|d||||}|durz|dd|dS|dur||}|dur|dd|dS|rt|d}| ||Wdn1s0Ynb| r>| ||rHt t |D],}|j tj||tj||||d qn | |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 %rrr)rrr}r%r_dbgrr raddfiler rlistdiraddr)rrr recursiverrfr8r8r9rOs6    ,   z TarFile.addcCs|dt|}||j|j|j}|j||jt |7_|j }|durt ||j|j |dt |j t\}}|dkr|jtt||d7}|j|t7_|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)rcrr#)rr'r4rSr6r7rr_rr2rr\r'r]rr3rr)rrrrXrcrdrer8r8r9rs   zTarFile.addfilecCsp|dur0|j}|durtSt|tr,td|St|r<|Sz t|WStyjtd|ddYn0dS)NzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z not found) extraction_filterrrCrF TypeErrorcallable_NAMED_FILTERSrr0)rrr8r8r9_get_filter_functions   zTarFile._get_filter_function.) numeric_ownerrc Csg}||}|dur|}|D]F}||||}|dur:q|rL|||j||| |dq|jdddd|D]p}tj||j } z,|j || |d| || | || Wq|t y} z|| WYd} ~ q|d} ~ 00q|dS)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_attrsrcSs|jSrr")rr8r8r9rz$TarFile.extractall..T)rreverse)r)r_get_extract_tarinfor r _extract_onesortr}r%rrchownutimechmodr _handle_nonfatal_error) rr%rrrZ directoriesfilter_functionrrdirpathrr8r8r9 extractalls,   zTarFile.extractallrcCs4||}||||}|dur0|||||dS)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)rrr%rrrrrr8r8r9extracts zTarFile.extractc Cst|tr||}n|}|}z|||}Wn^ttfy^}z||WYd}~n6d}~0ty}z||WYd}~n d}~00|dur|dd|j dS| rt |}t j ||j|_|S)z@Get filtered TarInfo (or None) from member, which might be a strNr$r)rCrFrrr_handle_fatal_errorr rrrr r'r}r%rr r)rrrr%rZ unfilteredrr8r8r9rs"    zTarFile._get_extract_tarinfoc Cs|dz"|j|tj||j||dWnZtyZ}z||WYd}~n6d}~0ty}z| |WYd}~n d}~00dS)z%Extract from filtered tarinfo to diskrzrN) r_extract_memberr}r%rrrr!r r)rrr%rrrr8r8r9r s  zTarFile._extract_onecCs"|jdkrn|dd|dS)z=Handle non-fatal error (ExtractError) according to errorlevelr# tarfile: %sN)rrrrr8r8r9r s zTarFile._handle_nonfatal_errorcCsn|jdkrn\t|trP|jdur6|dd|jqj|dd|j|jfn|ddt|j|fdS)z1Handle "fatal" error according to self.errorlevelrNr#r#ztarfile: %s %rztarfile: %s %s)rrCrfilenamerstrerrorrrpr$r8r8r9r! s   zTarFile._handle_fatal_errorcCs|dt|tr ||}n|}|s6|jtvrB|||S|sR| rzt|j t rht dq~| ||SndSdS)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. rzz'cannot extract (sym)link as file objectN)rrCrFrr rrx fileobjectr r rrr extractfile_find_link_target)rrrr8r8r9r($ s      zTarFile.extractfilecCsT|d}|dtj}tj|}|r>tj|s>t||sN| rh| dd|j |j fn| d|j | r|||n|r|||nx|r|||nb|s|r|||nD|s| r|||n&|jtvr|||n ||||rP||||| sP||||||dS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. rr#z%s -> %sN)rirr}rr%rrmakedirsr r rrr r makefiler makedirrmakefiforrmakedevmakelinkrrx makeunknownrrr)rr targetpathrrZ upperdirsr8r8r9r"D s4       zTarFile._extract_membercCs>z&|jdurt|n t|dWnty8Yn0dS)z,Make a directory called targetpath. Ni)rr}mkdirFileExistsErrorrrr1r8r8r9r,u s    zTarFile.makedircCs|j}||j|j}t|dl}|jdurn|jD]"\}}||t|||t|q4||j| nt|||jt|Wdn1s0YdS)z'Make a file called targetpath. rN) rrrrrrr\rr'truncate)rrr1sourcerctargetrr'r8r8r9r+ s      zTarFile.makefilecCs"||||dd|jdS)zYMake a file from a TarInfo object with an unknown type at targetpath. r#z9tarfile: Unknown file type %r, extracted as regular file.N)r+rrr4r8r8r9r0 s zTarFile.makeunknowncCs"ttdrt|ntddS)z'Make a fifo called targetpath. mkfifozfifo not supported by systemN)rr}r8r r4r8r8r9r- s  zTarFile.makefifocCsjttdrttdstd|j}|dur.d}|rB|tjO}n |tjO}t||t |j |j dS)zrprqrrrsrrrrrrSr r6r7rrrr'r rrrrrrrrrrrrrrrrrrrr rrrr!r(r"r,r+r0r-r.r/rrrr|rrrr)rOrrUrWr8r8r8r9rDs oZ        c&3  -     1! ? ( rcCsFz,t|drt|d}nt|}|WdSty@YdS0dS)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. r^)rTFN)rrrr)rrr8r8r9r s   rc Cs`ddl}d}|j|d}|jdddddd |jd d td d |jdd}|jddddd|jdddddd|jdddddd|jdd dd!d|}|jr|jdur|d"d#|j durJ|j }t |r4t |d$*}| t | tjd%Wdn1s0Y|jrFt d&|n|d"d'|n|jdur|j}t |rt |d(}|j|jd)Wdn1s0Yn|d"d'|n|jdurt|jd"kr|jd}tj}n,t|jd*kr|j\}}n|d"|t |rt |d( }|j||jd+Wdn1sR0Y|jr|d,krzd-|} n d.||} t | n|d"d'|n|jdur\|jd} tj| \} } d/d/d0d0d1d1d1d1d2} | | vrd3| | nd4}|j}t | |&}|D]}||qWdn1s<0Y|jr\t d5| dS)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 rzrPz{!r} is a tar archive.z{!r} is not a tar archive. r)rr$)r%rrz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.rrr)rz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:r{z{!r} file created.)argparseArgumentParser add_argumentradd_mutually_exclusive_group parse_argsrr exittestrrrrmrkrRrrSrrr2r}curdir format_helprZcreatepopr%splitextr)rcrXparserrargsr`rZtfrjrTZtar_name_extZ compressionsZtar_modeZ tar_files file_namer8r8r9main s           2  0    0      .rs__main__)T)krsversion __author__ __credits__builtinsrrrkr}rr[rrrVr'rwarningsrrrAttributeErrorNotImplementedErrorr@r NameError__all__r3rrr<r7r9r8rNr rfrrrQrRr+rZCONTTYPEr?r>rgrHrJrur rrrrxrrjrrrDrIrrr getfilesystemencodingr:r?rNrTrYr\rnrGrr rrr r rtrurvrKrwrxrobjectrrBufferedReaderrrrrrrrrrrrrr&rrrrsrpr8r8r8r9s           sh  ? ~_