a lji @sFddlmZdZdZdZdZdZdZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZzddlZddlZWneydZZYn0eefZzeef7ZWneyYn0gd Zejdd krddlZnddlZejZd Zd Zed Z dZ!dZ"dZ#dZ$dZ%dZ&d Z'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5d Z6d!Z7e6Z8e&e'e(e)e,e-e.e*e+e/e0e1f Z9e&e'e.e1fZ:e/e0e1fZ;d"Ze?e?e?e@e@e@d$ZAd%ZBd&ZCd'ZDd(ZEd)ZFd*ZGd+ZHd,ZId ZJd-ZKd.ZLd/ZMd0ZNd1ZOd2ZPd3ZQd!ZRd ZSe jTd4vrd5ZUneVZUd6d7ZWd8d9ZXd:d;ZYd2e8fdd?Z[d{d@dAZ\eBdBfeCdCfeDdDfeEdEfeFdFfeGdGffeKdHffeLdIffeMeHBdJfeHdKfeMdLffeNdHffeOdIffePeIBdJfeIdKfePdLffeQdHffeRdIffeSeJBdMfeJdNfeSdLfff Z]dOdPZ^GdQdRdRe_Z`GdSdTdTe`ZaGdUdVdVe`ZbGdWdXdXe`ZcGdYdZdZe`ZdGd[d\d\e`ZeGd]d^d^eeZfGd_d`d`eeZgGdadbdbeeZhGdcddddeeZiGdedfdfeeZjGdgdhdhekZlGdidjdjekZmGdkdldlekZnGdmdndnekZoGdodpdpekZpGdqdrdrekZqGdsdtdtekZrGdudvdvekZsGdwdxdxekZtdydzZueZvesjZdS)|)print_functionz $Revision$z0.9.0u"Lars Gustäbel (lars@gustaebel.de)z5$Date: 2011-02-25 17:42:01 +0200 (Fri, 25 Feb 2011) $z?$Id: tarfile.py 88586 2011-02-25 15:42:01Z marc-andre.lemburg $u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.N)TarFileTarInfo is_tarfileTarErrorsustar sustar00d01234567LKSxgX)pathlinkpathsizemtimeuidgidunamegname)rrr#r$)Zatimectimer r!r"riii`@i ii@ )ntZcezutf-8cCs(|||}|d||t|tS)z8Convert a string to a null-terminated bytes object. N)encodelenNUL)slengthencodingerrorsr7I/usr/lib/python3.9/site-packages/pip/_vendor/distlib/_backport/tarfile.pystns r9cCs*|d}|dkr|d|}|||S)z8Convert a null-terminated bytes object to a string. rN)finddecode)r3r5r6pr7r7r8ntss  r>cCs|dtdkrHztt|ddp"dd}Wq~tyDtdYq~0n6d}tt|dD] }|dK}|t||d7}q\|S) z/Convert a number field to a python number. rr)asciistrict0r-zinvalid headerr)chrintr> ValueErrorInvalidHeaderErrorranger1ord)r3nir7r7r8ntis rJcCsd|krd|dkrZ(d?d@Z)dAdBZ*dCdDZ+dEdFZ,dGdHZ-dIdJZ.dKdLZ/dMdNZ0dOdPZ1dQdRZ2dSdTZ3dUS)WraInformational class which holds the details about an archive member given by a tar header block. TarInfo objects are returned by TarFile.getmember(), TarFile.getmembers() and TarFile.gettarinfo() and are usually created internally. )rrtr!r"rr chksumtypelinknamer#r$devmajordevminorrr pax_headersrr_sparse_structs _link_targetrpcCsj||_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. irrpN)rrtr!r"rr rREGTYPErrr#r$rrrrrrrrr7r7r8rs"zTarInfo.__init__cCs|jSrrrr7r7r8_getpathszTarInfo._getpathcCs ||_dSrrrr7r7r8_setpathszTarInfo._setpathcCs|jSrrrr7r7r8 _getlinkpathszTarInfo._getlinkpathcCs ||_dSrr)rrr7r7r8 _setlinkpathszTarInfo._setlinkpathcCsd|jj|jt|fS)Nz<%s %r at %#x>) __class__rzridrr7r7r8__repr__szTarInfo.__repr__cCsl|j|jd@|j|j|j|j|j|j|j|j |j |j |j d }|dt krh|ddsh|dd7<|S)z9Return the TarInfo's attributes as a dictionary. ) rrtr!r"rr rrrr#r$rrrr/)rrtr!r"rr rrrr#r$rrDIRTYPEr)rinfor7r7r8get_infos"zTarInfo.get_infosurrogateescapecCsT|}|tkr||||S|tkr4||||S|tkrH|||StddS)zq*z||dd Wn"tyt||||<Yq*Yn0t|||kr*||||<q*d D]`\}}||vrd ||<q||}d |krd |d krnn t|t rt |||<d ||<q|r| |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. rrrrr)r#r#r+)r$r$r+r?r@))r!r-)r"r-)r )r r!rr-rrr)rrcopyrrr0UnicodeEncodeErrorr1 isinstancefloatstr_create_pax_generic_headerXHDTYPErr) rr r5rrZhnamer4rTvalrZr7r7r8rs4     *  zTarInfo.create_pax_headercCs||tdS)zAReturn the object as a pax global header block sequence. utf8)r'XGLTYPE)clsrr7r7r8create_pax_global_headerDsz TarInfo.create_pax_global_headercCsj|dtd}|r.|ddkr.|dd}q|t|d}|dd}|rZt|tkrbtd||fS)zUSplit a name longer than 100 chars into a prefix and a name part. Nrr:r zname is too long) LENGTH_PREFIXr1rrD)rrrr7r7r8rJs zTarInfo._posix_split_namecCsVt|ddd||t|ddd@d|t|ddd|t|d dd|t|d dd |t|d dd |d |dtt|ddd|||dtt|ddd||t|ddd||t|ddd|t|ddd|t|ddd||g}tdtd|}t |t dd}|ddd| d|dd}|S)zReturn a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants. rrpr rtrr r-r!r"rr!r s rrrr#r+r$rrrr z%dsrNiz%06or?i) r9getrVrrrOrQrrsr[r0)r rUr5r6partsrZrr7r7r8rYs(  &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^r1rr2)Zpayloadrcrdr7r7r8_create_payloaduszTarInfo._create_payloadcCsR|||t}i}d|d<||d<t||d<t|d<||t||||S)zTReturn a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence for name. z ././@LongLinkrrrr)r0r2r1rrrr1)r,rrr5r6r r7r7r8rs 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*r@Trs21 hdrcharset=BINARY rrrr? =rz././@PaxHeaderrrrrr) itemsr0r#r1r&bytesrrrr1) r,rrr5ZbinarykeywordvalueZrecordsrLrHr=r r7r7r8r's<   ( 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 headerrWrXz bad checksumr lt|ii i)iIiQiYir ir.r!iii)$r1rrrcountr2rrJr[rEr>rrtr!r"rr rrrr#r$rrAREGTYPErr GNUTYPE_SPARSErFrDrrboolrisdirrstrip GNU_TYPES)r,rZr5r6robjrrstructsrIrnumbytes isextendedorigsizer7r7r8frombufsZ         zTarInfo.frombufcCs8|jt}|||j|j}|jt|_||S)zOReturn the next TarInfo object from TarFile object tarfile. ) rr\rrJr5r6rr _proc_member)r,rrZrEr7r7r8 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_gnulongr@ _proc_sparser(r+SOLARIS_XHDTYPE _proc_pax _proc_builtinrrr7r7r8rKs    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. ) rrrisregrSUPPORTED_TYPES_blockrr_apply_pax_inforr5r6)rrrr7r7r8rQ$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\rUrrLrrrrr r>r5r6rrr)rrrZnextr7r7r8rM5s   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. rr!r=i)rrr\rrFrJrDrrrArrrrUrr) rrrFrHrIrZrrIrrGr7r7r8rNKs(       zTarInfo._proc_sparsecCs|j||j}|jtkr&|j}n |j}t d|}|durX| d d|d<| d}|dkrr|j }nd}td}d}|||}|sq&|\} } t| } ||d d|d| d} || dd|j} | tvr|| ||j |j} n|| dd|j} | || <|| 7}qz||} WntyPtd Yn0d |vrj|| |nHd |vr|| ||n.| d dkr| 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]+)\nNrr* hdrcharsetZBINARYs(\d+) ([^=]+)=rrrWGNU.sparse.mapGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrAr)$rr\rUrrr+rr"researchgroupr<r/r5compilematchgroupsrCendr_decode_pax_fieldr6PAX_NAME_FIELDSrLrr_proc_gnusparse_01_proc_gnusparse_00_proc_gnusparse_10r(rOrVrrrSrT)rrrZrrbrZr5Zregexrr4r6r7rXrr7r7r8rPgsd       $         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+)\nrs\d+ GNU.sparse.numbytes=(\d+)\nN)r^finditerrrrCr`listzipr)rrXrrZZoffsetsrbrGr7r7r8rhszTarInfo._proc_gnusparse_00cCs@dd|ddD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|qSr7)rC).0rmr7r7r8 rz.TarInfo._proc_gnusparse_01..r[,Nrr)splitrkrlr)rrXrrr7r7r8rgszTarInfo._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. Nrrr) rr\rrprCr1rrrrrkrlr)rrXrrfieldsrrZnumberr7r7r8ris  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.namerr\rzGNU.sparse.realsizerr N) r4setattrrC PAX_FIELDSPAX_NUMBER_FIELDSrDrCr"r)rrr5r6r6r7r7r7r8rVs"   zTarInfo._apply_pax_infocCs2z||dWSty,|||YS0dS)z1Decode a single field from a pax record. r@N)r<UnicodeDecodeError)rr7r5Zfallback_encodingZfallback_errorsr7r7r8res 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)rr>rcrdr7r7r8rU szTarInfo._blockcCs |jtvSr)r REGULAR_TYPESrr7r7r8rSsz TarInfo.isregcCs|Sr)rSrr7r7r8isfileszTarInfo.isfilecCs |jtkSr)rr rr7r7r8rBsz TarInfo.isdircCs |jtkSr)rSYMTYPErr7r7r8issymsz TarInfo.issymcCs |jtkSr)rLNKTYPErr7r7r8islnksz TarInfo.islnkcCs |jtkSr)rCHRTYPErr7r7r8ischr sz TarInfo.ischrcCs |jtkSr)rBLKTYPErr7r7r8isblk"sz TarInfo.isblkcCs |jtkSr)rFIFOTYPErr7r7r8isfifo$szTarInfo.isfifocCs |jduSr)rrr7r7r8issparse&szTarInfo.issparsecCs|jtttfvSr)rr}rrrr7r7r8isdev(sz TarInfo.isdevN)rp)4rzr{r|r} __slots__rrrpropertyrrrrr rDEFAULT_FORMATENCODINGrrrr classmethodr-r staticmethodrr1rr'rJrLrKrQrMrNrPrhrgrirVrerUrSrxrBrzr|r~rrrrr7r7r7r8rsf    1     2 >  f  rc @seZdZdZdZdZdZdZeZ e Z dZ e ZeZdVdd Zedddefd d ZedWd d ZedXddZedYddZddddZddZddZddZddZdZdd Zd[d"d#Zd\d$d%Zd]d&d'Z d^d)d*Z!d_d,d-Z"d.d/Z#d`d0d1Z$d2d3Z%d4d5Z&d6d7Z'd8d9Z(d:d;Z)dd?Z+d@dAZ,dBdCZ-dDdEZ.dadFdGZ/dHdIZ0dbdJdKZ1dLdMZ2dNdOZ3dPdQZ4dRdSZ5dTdUZ6dS)crz=The TarFile Class provides an interface to tar archives. rFrNrjrc  Cst|dks|dvrtd||_dddd||_|sn|jdkrZtj|sZd |_d|_t||j}d |_n0|d urt |d r|j }t |d r|j|_d|_|rtj |nd |_ ||_ |d ur||_ |d ur||_|d ur||_|d ur||_|d ur||_| |_| d ur&|j tkr&| |_ni|_| d ur<| |_| d urL| |_d |_g|_d |_|j |_i|_z|jdkrd |_||_|jdkr"|j |jz|j |}|j!|WnXt"y|j |jYq"Yn2t#y} zt$t%| WYd } ~ n d } ~ 00q|jdvrld|_|jrl|j&|j'}|j (||jt|7_Wn&|js|j )d|_Yn0d S)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. rrmode must be 'r', 'a' or 'w'rbzr+bwb)rjarkrrkFNrrtTrjaw)*r1rDrt_moderrexists bltn_openrrrabspathrrUr dereference ignore_zerosr5r6rrdebug errorlevelrmembers_loadedrrinodes firstmemberrXrrLrrrrrr&r-r"r]r)rrrtrrUrrrr5r6rrrerZr7r7r8rFs            &   zTarFile.__init__c Ks|s|std|dvr|jD]}t||j|}|durB|}z||d|fi|WSttfy} z*|dur||WYd} ~ qWYd} ~ qd} ~ 00qtdnd|vr|dd\} }| pd} |pd}||jvrt||j|}n td |||| |fi|Sd |vr|d d\} }| p:d} |pDd}| d vrXtd t|| |||} z||| | fi|} Wn| Yn0d | _ | S|dvr|j |||fi|StddS)a|Open 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 '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 '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 '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 znothing to open)rjzr:*Nrjz%file could not be opened successfully:rrzunknown compression type %r|rwmode must be 'r' or 'w'Frzundiscernible mode) rD OPEN_METHrrrrrrprrrtaropen) r,rrtrrkwargsrfuncZ saved_posrrxstreamrnr7r7r8rsN  $         z TarFile.opencKs0t|dks|dvrtd||||fi|S)zCOpen uncompressed tar archive name for reading or writing. rrr)r1rD)r,rrtrrr7r7r8rszTarFile.taropenrc Kst|dks|dvrtdzddl}|jWnttfyLtdYn0|du}z.|||d||}|j|||fi|}WnXty|s|dur| |durt dYn"|s|dur| Yn0||_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rrrrNzgzip module is not availablerer) r1rDgzipZGzipFilerAttributeErrorrrr_rrr) r,rrtr compresslevelrrZ extfileobjrnr7r7r8gzopens.     zTarFile.gzopenc Kst|dks|dvrtdz ddl}WntyBtdYn0|durXt||}n|j|||d}z|j|||fi|}Wn&tt fy| t dYn0d |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rrzmode must be 'r' or 'w'.rNr)rznot a bzip2 fileF) r1rDrrrrBZ2Filerr_EOFErrorrrr)r,rrtrrrrrnr7r7r8bz2open$s    zTarFile.bz2openrrr)rrrcCs|jr dS|jdvrf|jttd|jtd7_t|jt\}}|dkrf|jtt||j sv|j d|_dS)zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NrrrT) rrtrr]r2rrr^ RECORDSIZErr)rrcrdr7r7r8rHs  z TarFile.closecCs"||}|durtd||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. Nzfilename %r not found) _getmemberKeyError)rrrr7r7r8 getmember\s  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_loadrrr7r7r8 getmembersgszTarFile.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|] }|jqSr7r)rmrr7r7r8rnurz$TarFile.getnames..)rrr7r7r8getnamesqszTarFile.getnamesc Csh|d|dur|j}|dur$|}tj|\}}|tjd}|d}|}||_ |durt tdr~|j s~t |}qt |}nt|}d}|j}t |r |j|jf} |j s|jdkr| |jvr||j| krt} |j| }nt} | drt||j| <nht |rt} nVt |r0t} nDt |rLt} t|}n(t |r^t } nt !|rpt"} ndS||_||_#|j$|_%|j&|_'| tkr|j(|_)nd|_)|j*|_+| |_,||_-t.rzt./|j%d|_0Wnt1yYn0t2r"zt23|j'd|_4Wnt1y Yn0| t t"fvrdt tdrdt td rdt5|j6|_7t8|j6|_9|S) aOCreate a TarInfo object for either the file `name' or the file object `fileobj' (using os.fstat on its file descriptor). You can modify some of the TarInfo's attributes before you add it using addfile(). If given, `arcname' specifies an alternative name for the file in the archive. rNr lstatrprrmajorminor):rrrr splitdriverseplstriprrrrrstatfstatfilenost_modeS_ISREGst_inost_devst_nlinkrr{rS_ISDIRr S_ISFIFOrS_ISLNKryreadlinkS_ISCHRr}S_ISBLKrrtst_uidr!st_gidr"st_sizerst_mtimer rrpwdgetpwuidr#rgrpgetgrgidr$rst_rdevrrr) rrarcnamerdrvrZstatresrZstmdinoderr7r7r8 gettarinfows                  zTarFile.gettarinfoTcCs||D]}|rtt|jddtd|jp4|j|jp>|jfdd|sZ| rxtdd|j |j fddntd|j ddtdt |jdd ddt|j|rd nd dd|r|rtd |jdd|rtd |jddtq dS)zPrint 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.  )rdz%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02dNrr rpz->zlink to)rprintrxrtr#r!r$r"r~rrrrr localtimer rrBrzrr|)rverboserr7r7r8rks8  z TarFile.listc Csn|d|dur|}|durPddl}|dtd||rP|dd|dS|jdurtj||jkr|dd|dS|d|| ||}|dur|dd |dS|dur||}|dur|dd|dS| r t |d }| ||| n`|r`| ||rjt|D].}|jtj||tj|||||d q.n | |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. `exclude' is a function that should return True for each filename to be excluded. `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. rNrzuse the filter argument insteadrztarfile: Excluded %rztarfile: Skipped %rrztarfile: Unsupported type %rr)filter)rwarningswarnDeprecationWarning_dbgrrrrrrSraddfilerrBlistdiraddrs) rrr recursiveZexcluderrrfr7r7r8rsH          z TarFile.addcCs|dt|}||j|j|j}|j||jt |7_|durt ||j|j t |j t \}}|dkr|jtt ||d7}|j|t 7_|j|dS)a]Add the TarInfo object `tarinfo' to the archive. If `fileobj' is given, tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects using gettarinfo(). On Windows platforms, `fileobj' should always be opened with mode 'rb' to avoid irritation about the file size. rNrr)rr"rrUr5r6rr]rr1rfrr^rr2rrr)rrrrZrcrdr7r7r8r4s   zTarFile.addfile.c Csg}|dur|}|D]<}|r:||t|}d|_|j||| dq|jddd||D]}tj ||j }z(| ||| ||| ||Wqnty}z*|jdkrȂn|dd|WYd}~qnd}~00qndS) aMExtract 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(). N set_attrscSs|jSrr)rr7r7r8drz$TarFile.extractall..)keyr tarfile: %s)rBrrr"rtextractsortreverserrrsrchownutimechmodr~rr)rrrZ directoriesrdirpathrr7r7r8 extractallNs*     zTarFile.extractallrpc Cs|dt|tr ||}n|}|r>tj||j|_ z |j |tj||j |dWnt y}zP|j dkr|n6|jdur|dd|jn|dd|j|jfWYd}~nLd}~0ty}z*|j dkrn|dd|WYd}~n d}~00dS)axExtract 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. rjrrNrrztarfile: %s %r)rr$r&rr|rrrsrr_extract_memberrEnvironmentErrorrfilenamerstrerrorr~)rmemberrrrrr7r7r8rts(      , zTarFile.extractcCs|dt|tr ||}n|}|r8|||S|jtvrN|||S|s^| rt|j t rtt dq| ||SndSdS)aExtract a member from the archive as a file object. `member' may be a filename or a TarInfo object. If `member' is a regular file, a file-like object is returned. If `member' is a link, a file-like object is constructed from the link's target. If `member' is none of the above, None is returned. The file-like object is read-only and provides the following methods: read(), readline(), readlines(), seek() and tell() rjz'cannot extract (sym)link as file objectN)rr$r&rrS fileobjectrrTr|rzrrr extractfile_find_link_target)rrrr7r7r8rs        zTarFile.extractfilecCsR|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 ||||rN|||| sN||||||dS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. r rz%s -> %sN)rCrrrrdirnamermakedirsr|rzrrrrSmakefilerBmakedirrmakefifor~rmakedevmakelinkrrT makeunknownrrr)rr targetpathrZ upperdirsr7r7r8rs4        zTarFile._extract_memberc CsHzt|dWn2tyB}z|jtjkr.WYd}~n d}~00dS)z,Make a directory called targetpath. rN)rmkdirrerrnoZEEXISTrrrrr7r7r8rs  zTarFile.makedircCs||j}||jt|d}|jdurN|jD]\}}||t|||q,nt|||j||j||dS)z'Make a file called targetpath. rN) rrrrrrfrtruncater)rrrsourcetargetrrr7r7r8rs     zTarFile.makefilecCs"||||dd|jdS)zYMake a file from a TarInfo object with an unknown type at targetpath. rz9tarfile: Unknown file type %r, extracted as regular file.N)rrrrrrr7r7r8r s zTarFile.makeunknowncCs"ttdrt|ntddS)z'Make a fifo called targetpath. mkfifozfifo not supported by systemN)rrr r~r r7r7r8r s  zTarFile.makefifocCs^ttdrttdstd|j}|r6|tjO}n |tjO}t||t |j |j dS)z| rttdrt |||ntjdkrt|||Wn,ty}ztdWYd}~n d}~00dS)z6Set owner of targetpath according to tarinfo. geteuidrrlchownZos2emxzcould not change ownerN)rrrrrgetgrnamr$rr"getpwnamr#r!rzrsysplatformrrr~)rrrgurr7r7r8rD s      z TarFile.chownc CsNttdrJzt||jWn,tyH}ztdWYd}~n d}~00dS)zASet file permissions of targetpath according to tarinfo. rzcould not change modeN)rrrrtrr~rr7r7r8rZ s  z TarFile.chmodc CsXttdsdSzt||j|jfWn,tyR}ztdWYd}~n d}~00dS)zBSet modification time of targetpath according to tarinfo. rNz"could not change modification time)rrrr rr~rr7r7r8rc s  z TarFile.utimec Cs|d|jdur$|j}d|_|S|j|jd}z|j|}Wqty}zD|jr| dd|j|f|jt 7_WYd}~q6WYd}~qd}~0t y}z\|jr| dd|j|f|jt 7_WYd}~q6n|jdkrt t |WYd}~nd}~0ty>|jdkr:t dYnntyz}z$|jdkrft t |WYd}~n:d}~0ty}zt t |WYd}~n d}~00qq6|dur|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. ZraNrz0x%X: %srz empty fileT)rrrrrrrLrrrrrErr&rrrrrrr)rmrrr7r7r8rXn sD  "      " z TarFile.nextcCsn|}|dur"|d||}|r2tj|}t|D].}|rRtj|j}n|j}||kr:|Sq:dS)z}Find an archive member by name from bottom to top. If tarinfo is given, it is used as the starting point. N)rindexrrnormpathreversedr)rrr normalizerr member_namer7r7r8r s  zTarFile._getmembercCs|}|durqqd|_dS)zWRead through the entire archive file and look for readable members. NT)rXrrrr7r7r8r sz TarFile._loadcCs:|jrtd|jj|dur6|j|vr6td|jdS)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)rr_rrzrt)rrtr7r7r8r szTarFile._checkcCsX|r&tj|jd|j}d}n |j}|}|j||dd}|durTtd||S)zZFind the target member of a symlink or hardlink member in the archive. r NT)rrzlinkname %r not found)rzrrrrrrr)rrrlimitrr7r7r8r s zTarFile._find_link_targetcCs|jrt|jSt|SdS)z$Provide an iterator object. N)riterrTarIterrr7r7r8r s zTarFile.__iter__cCs||jkrt|tjddS)z.Write debugging output to sys.stderr. )fileN)rrrstderr)rlevelmsgr7r7r8r s z TarFile._dbgcCs ||Sr)rrr7r7r8 __enter__ szTarFile.__enter__cCs,|dur|n|js"|jd|_dSr)rrrr)rrr7 tracebackr7r7r8__exit__ s   zTarFile.__exit__) NrjNNNNNNrNNN)rjN)rjNr)rjNr)NNN)T)NTNN)N)rN)rpT)T)NF)N)7rzr{r|r}rrrrrrUrr5r6rrrrrrrrrrrrrrrrrrkrrrrrrrrrrrrrrrrXrrrrrrr(r*r7r7r7r8r,sp kK       b  >  & #& 0   1  rc@s,eZdZdZddZddZddZeZdS) r#zMIterator Class. for tarinfo in TarFile(...): suite... cCs||_d|_dS)z$Construct a TarIter object. rN)rrrRr7r7r8r szTarIter.__init__cCs|S)z Return iterator object. r7rr7r7r8r szTarIter.__iter__cCs`|jjs$|j}|sNd|j_tn*z|jj|j}WntyLtYn0|jd7_|S)zReturn the next item using TarFile's next() method. When all members have been read, set TarFile as _loaded. Tr)rrrX StopIterationrr IndexErrorr r7r7r8__next__ s   zTarIter.__next__N)rzr{r|r}rrr-rXr7r7r7r8r# s r#cCs0zt|}|WdSty*YdS0dS)zfReturn True if name points to a tar archive that we are able to handle, else return False. TFN)rrr)rrnr7r7r8r# s  r)N)wZ __future__r __version__version __author__Z__date__Z __cvsid__ __credits__rrrrrrOr"r^rrrrNotImplementedErrorrZ WindowsError NameError__all__ version_infoZ __builtin__builtinsrZ_openr2rrrrrrr.rr?r{ryr}rr rZCONTTYPEr rr@r(r+rOrrNrrrTrwrDrtsetrfr%rCruS_IFLNKS_IFREGr S_IFDIRrS_IFIFOZTSUIDZTSGIDZTSVTXZTUREADZTUWRITEZTUEXECZTGREADZTGWRITEZTGEXECZTOREADZTOWRITEZTOEXECrrgetfilesystemencodingr9r>rJrVr[rfrqrx Exceptionrr~rrrrrrrrErobjectrrrrrrrrr#rrr7r7r7r8sN          i?KT*