/snap/core18/2979/usr/lib/python3.6/__pycache__
NameSizeModeActions
abc.cpython-36.pyc75150644editdlrm
aifc.cpython-36.pyc259430644editdlrm
antigravity.cpython-36.pyc7790644editdlrm
argparse.cpython-36.pyc604560644editdlrm
ast.cpython-36.pyc117040644editdlrm
asynchat.cpython-36.pyc68150644editdlrm
asyncore.cpython-36.pyc158380644editdlrm
base64.cpython-36.pyc170590644editdlrm
bdb.cpython-36.pyc170330644editdlrm
binhex.cpython-36.pyc120860644editdlrm
bisect.cpython-36.pyc26760644editdlrm
bz2.cpython-36.pyc112820644editdlrm
calendar.cpython-36.pyc258820644editdlrm
cgi.cpython-36.pyc284160644editdlrm
cgitb.cpython-36.pyc100800644editdlrm
chunk.cpython-36.pyc49000644editdlrm
cmd.cpython-36.pyc125750644editdlrm
code.cpython-36.pyc98360644editdlrm
codecs.cpython-36.pyc339000644editdlrm
codeop.cpython-36.pyc62700644editdlrm
colorsys.cpython-36.pyc33110644editdlrm
compileall.cpython-36.pyc82780644editdlrm
configparser.cpython-36.pyc452440644editdlrm
contextlib.cpython-36.pyc111580644editdlrm
copy.cpython-36.pyc70790644editdlrm
copyreg.cpython-36.pyc42440644editdlrm
cProfile.cpython-36.pyc42940644editdlrm
crypt.cpython-36.pyc22420644editdlrm
csv.cpython-36.pyc118550644editdlrm
datetime.cpython-36.pyc545110644editdlrm
decimal.cpython-36.pyc3510644editdlrm
difflib.cpython-36.pyc596420644editdlrm
dis.cpython-36.pyc141810644editdlrm
doctest.cpython-36.pyc755890644editdlrm
dummy_threading.cpython-36.pyc11020644editdlrm
enum.cpython-36.pyc234530644editdlrm
filecmp.cpython-36.pyc83050644editdlrm
fileinput.cpython-36.pyc131520644editdlrm
fnmatch.cpython-36.pyc28740644editdlrm
formatter.cpython-36.pyc175790644editdlrm
fractions.cpython-36.pyc184260644editdlrm
ftplib.cpython-36.pyc283570644editdlrm
functools.cpython-36.pyc240620644editdlrm
genericpath.cpython-36.pyc37260644editdlrm
getopt.cpython-36.pyc62170644editdlrm
getpass.cpython-36.pyc41770644editdlrm
gettext.cpython-36.pyc143060644editdlrm
glob.cpython-36.pyc42590644editdlrm
gzip.cpython-36.pyc162260644editdlrm
hashlib.cpython-36.pyc66920644editdlrm
heapq.cpython-36.pyc142920644editdlrm
hmac.cpython-36.pyc48360644editdlrm
imaplib.cpython-36.pyc421380644editdlrm
imghdr.cpython-36.pyc41500644editdlrm
imp.cpython-36.pyc96960644editdlrm
inspect.cpython-36.pyc797390644editdlrm
io.cpython-36.pyc33870644editdlrm
ipaddress.cpython-36.pyc623860644editdlrm
keyword.cpython-36.pyc17650644editdlrm
linecache.cpython-36.pyc37780644editdlrm
locale.cpython-36.pyc340300644editdlrm
lzma.cpython-36.pyc119920644editdlrm
macpath.cpython-36.pyc56410644editdlrm
macurl2path.cpython-36.pyc18670644editdlrm
mailbox.cpython-36.pyc637520644editdlrm
mailcap.cpython-36.pyc72090644editdlrm
mimetypes.cpython-36.pyc155530644editdlrm
modulefinder.cpython-36.pyc153660644editdlrm
netrc.cpython-36.pyc38360644editdlrm
nntplib.cpython-36.pyc337800644editdlrm
ntpath.cpython-36.pyc131900644editdlrm
nturl2path.cpython-36.pyc14990644editdlrm
numbers.cpython-36.pyc121420644editdlrm
opcode.cpython-36.pyc54130644editdlrm
operator.cpython-36.pyc139130644editdlrm
optparse.cpython-36.pyc480540644editdlrm
os.cpython-36.pyc296280644editdlrm
pathlib.cpython-36.pyc420070644editdlrm
pdb.cpython-36.pyc460940644editdlrm
pickle.cpython-36.pyc426910644editdlrm
pickletools.cpython-36.pyc660200644editdlrm
pipes.cpython-36.pyc78080644editdlrm
pkgutil.cpython-36.pyc162610644editdlrm
platform.cpython-36.pyc291970644editdlrm
plistlib.cpython-36.pyc280550644editdlrm
poplib.cpython-36.pyc133290644editdlrm
posixpath.cpython-36.pyc104560644editdlrm
pprint.cpython-36.pyc158240644editdlrm
profile.cpython-36.pyc139010644editdlrm
pstats.cpython-36.pyc218570644editdlrm
pty.cpython-36.pyc38610644editdlrm
pyclbr.cpython-36.pyc83650644editdlrm
pydoc.cpython-36.pyc837750644editdlrm
py_compile.cpython-36.pyc65440644editdlrm
queue.cpython-36.pyc87550644editdlrm
quopri.cpython-36.pyc57730644editdlrm
random.cpython-36.pyc193300644editdlrm
re.cpython-36.pyc140580644editdlrm
reprlib.cpython-36.pyc54000644editdlrm
rlcompleter.cpython-36.pyc57800644editdlrm
runpy.cpython-36.pyc79820644editdlrm
sched.cpython-36.pyc65640644editdlrm
secrets.cpython-36.pyc21620644editdlrm
selectors.cpython-36.pyc176970644editdlrm
shelve.cpython-36.pyc94580644editdlrm
shlex.cpython-36.pyc69700644editdlrm
shutil.cpython-36.pyc307040644editdlrm
signal.cpython-36.pyc25150644editdlrm
site.cpython-36.pyc165600644editdlrm
sitecustomize.cpython-36.pyc2120644editdlrm
smtpd.cpython-36.pyc266830644editdlrm
smtplib.cpython-36.pyc353400644editdlrm
sndhdr.cpython-36.pyc69130644editdlrm
socket.cpython-36.pyc220130644editdlrm
socketserver.cpython-36.pyc242500644editdlrm
sre_compile.cpython-36.pyc102780644editdlrm
sre_constants.cpython-36.pyc59720644editdlrm
sre_parse.cpython-36.pyc203580644editdlrm
ssl.cpython-36.pyc369390644editdlrm
stat.cpython-36.pyc38510644editdlrm
statistics.cpython-36.pyc181740644editdlrm
string.cpython-36.pyc79640644editdlrm
stringprep.cpython-36.pyc100300644editdlrm
struct.cpython-36.pyc3120644editdlrm
subprocess.cpython-36.pyc354850644editdlrm
sunau.cpython-36.pyc169380644editdlrm
symbol.cpython-36.pyc25170644editdlrm
symtable.cpython-36.pyc104280644editdlrm
sysconfig.cpython-36.pyc159160644editdlrm
tabnanny.cpython-36.pyc69750644editdlrm
tarfile.cpython-36.pyc630850644editdlrm
telnetlib.cpython-36.pyc180970644editdlrm
tempfile.cpython-36.pyc253090644editdlrm
textwrap.cpython-36.pyc136840644editdlrm
this.cpython-36.pyc12650644editdlrm
threading.cpython-36.pyc372340644editdlrm
timeit.cpython-36.pyc116030644editdlrm
token.cpython-36.pyc33200644editdlrm
tokenize.cpython-36.pyc186470644editdlrm
trace.cpython-36.pyc194950644editdlrm
traceback.cpython-36.pyc196460644editdlrm
tracemalloc.cpython-36.pyc172290644editdlrm
tty.cpython-36.pyc10720644editdlrm
turtle.cpython-36.pyc1317510644editdlrm
types.cpython-36.pyc82010644editdlrm
typing.cpython-36.pyc733060644editdlrm
uu.cpython-36.pyc34980644editdlrm
uuid.cpython-36.pyc209180644editdlrm
warnings.cpython-36.pyc132580644editdlrm
wave.cpython-36.pyc178850644editdlrm
weakref.cpython-36.pyc191430644editdlrm
webbrowser.cpython-36.pyc157970644editdlrm
xdrlib.cpython-36.pyc83020644editdlrm
zipapp.cpython-36.pyc55340644editdlrm
zipfile.cpython-36.pyc497280644editdlrm
_bootlocale.cpython-36.pyc9800644editdlrm
_collections_abc.cpython-36.pyc287970644editdlrm
_compat_pickle.cpython-36.pyc65660644editdlrm
_compression.cpython-36.pyc41040644editdlrm
_dummy_thread.cpython-36.pyc48510644editdlrm
_markupbase.cpython-36.pyc79910644editdlrm
_osx_support.cpython-36.pyc96840644editdlrm
_pydecimal.cpython-36.pyc1634020644editdlrm
_pyio.cpython-36.pyc713860644editdlrm
_sitebuiltins.cpython-36.pyc34350644editdlrm
_strptime.cpython-36.pyc159630644editdlrm
_sysconfigdata_m_linux_x86_64-linux-gnu.cpython-36.pyc187790644editdlrm
_threading_local.cpython-36.pyc64250644editdlrm
_weakrefset.cpython-36.pyc78280644editdlrm
__future__.cpython-36.pyc41670644editdlrm
__phello__.foo.cpython-36.pyc1190644editdlrm
Edit: /snap/core18/2979/usr/lib/python3.6/__pycache__/tarfile.cpython-36.pyc (63085B)
3 Nqir'@sdZdZdZdZdZdZddlmZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZy ddlZWnek rdZYnXy ddlZWnek rdZYnXeefZyeef7ZWnek rYnXd d d d d ddddddddddgZdZdZedZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d*Z/d+Z0d,Z1dZ2d-Z3d.Z4e3Z5e#e$e%e&e)e*e+e'e(e,e-e.f Z6e#e$e+e.fZ7e,e-e.fZ8dlZ9d/d0d5d6hZ:e;e;e;ed8krd9Z?ne j@Z?d:d;ZAdd?ZCd@e5fdAdBZDdCdDZEdedfdEdFZFdGdHZGdIdJZHGdKd d eIZJGdLddeJZKGdMd d eJZLGdNddeJZMGdOddeJZNGdPddeJZOGdQdRdReOZPGdSdTdTeOZQGdUdVdVeOZRGdWdXdXeOZSGdYdZdZeOZTGd[d\d\ZUGd]d^d^ZVGd_d`d`eWZXGdadbdbeWZYGdcdddde jZZ[ej\deZ]Gdfd d eWZ^Gdgd d eWZ_dhd Z`e_jZdidjZaebdkkreadS)mz,Read from and write to tar format archives. 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.)openNTarFileTarInfo is_tarfileTarError ReadErrorCompressionError StreamError ExtractError HeaderErrorENCODING USTAR_FORMAT GNU_FORMAT PAX_FORMATDEFAULT_FORMATrisustar sustar00d01234567LKSxgXpathlinkpathsizemtimeuidgidunamegname)ZatimeZctimer(r)r*r'ntzutf-8cCs(|j||}|d||t|tS)z8Convert a string to a null-terminated bytes object. N)encodelenNUL)slengthencodingerrorsr5/usr/lib/python3.6/tarfile.pystns r7cCs*|jd}|dkr|d|}|j||S)z8Convert a null-terminated bytes object to a string. rr#N)finddecode)r1r3r4pr5r5r6ntss  r<c Cs|dd krfd}x0tt|dD]}|dK}|||d7}q"W|ddkrdt|d| }n@y"t|dd}t|jpd d}Wntk rtd YnX|S) z/Convert a number field to a python number. rr#asciistrict0zinvalid header)r=r>)ranger/r<intstrip ValueErrorInvalidHeaderError)r1nir5r5r6ntis   rKr?cCst|}d|ko"d|dknrDtd|d|fdt}n|tkrd|d |kopd|dknr|dkrtdg}ntdg}d||}x6t|dD]}|jd|d@|dL}qWntd |S) z/Convert a python number to a number field. rr?r#z%0*orAr@r=r>zoverflow in number field)rEbytesr0r bytearrayrDinsertrG)rIdigitsformatr1rJr5r5r6itns  2   rQcCs0dttjd|}dttjd|}||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. r@Z 148B8x356BZ 148b8x356b)sumstructZ unpack_from)bufZunsigned_chksumZ signed_chksumr5r5r6 calc_chksumss rUc Cs|pd}|dkrdS|dkr.tj|||dSt||\}}x8t|D],}|j|}t||krh|d|j|qFW|dkr|j|}t||kr|d|j|dS)zjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. irNzunexpected end of datai@)shutil copyfileobjdivmodrDreadr/write) srcdstr2 exceptionbufsizeblocks remainderbrTr5r5r6rXs$     rXcCs ddl}|jdtdtj|S)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder$)warningswarnDeprecationWarningstatfilemode)modercr5r5r6rgsrgcCs8ttjdd}|dk r(|j|dj|}t|dddS)Nr3backslashreplace )end)getattrsysstdoutr.r:print)r1r3r5r5r6 _safe_print srpc@seZdZdZdS)rzBase exception.N)__name__ __module__ __qualname____doc__r5r5r5r6rsc@seZdZdZdS)r z%General exception for extract errors.N)rqrrrsrtr5r5r5r6r sc@seZdZdZdS)rz&Exception for unreadable tar archives.N)rqrrrsrtr5r5r5r6rsc@seZdZdZdS)rz.Exception for unavailable compression methods.N)rqrrrsrtr5r5r5r6rsc@seZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.N)rqrrrsrtr5r5r5r6r sc@seZdZdZdS)r z!Base exception for header errors.N)rqrrrsrtr5r5r5r6r "sc@seZdZdZdS)EmptyHeaderErrorzException for empty headers.N)rqrrrsrtr5r5r5r6ru%sruc@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.N)rqrrrsrtr5r5r5r6rv(srvc@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.N)rqrrrsrtr5r5r5r6rw+srwc@seZdZdZdS)rHzException for invalid headers.N)rqrrrsrtr5r5r5r6rH.srHc@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rqrrrsrtr5r5r5r6rx1srxc@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}tj||d|_dS)N)rwO_BINARYi) osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrr|rfd)selfnamerhr5r5r6__init__>s   z_LowLevelFile.__init__cCstj|jdS)N)r}closer)rr5r5r6rGsz_LowLevelFile.closecCstj|j|S)N)r}rZr)rr'r5r5r6rZJsz_LowLevelFile.readcCstj|j|dS)N)r}r[r)rr1r5r5r6r[Msz_LowLevelFile.writeN)rqrrrsrtrrrZr[r5r5r5r6ry8s  ryc@steZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dddZ dddZ 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|_|dkrt||}d|_|dkr6t|}|j}|pt|j|jkrL|jj|jd|j|j|jd|_qWdS)z]Write string s to the stream if a whole new block is ready to be written. N)rTr/r_rr[)rr1r5r5r6Z__writesz_Stream.__writec Cs|jr dSd|_z|jdkr:|jdkr:|j|jj7_|jdkr|jr|jj|jd|_|jdkr|jjtj d|j |jjtj d|j d@Wd|j s|jj XdS) z[Close the _Stream object. No operation should be done on it afterwards. NTr{rrrzd|fg}d|_g|_d}|j}xT|D]L\}}||kr~|jj d||df|jj d||||f||7}||}qZW||jkr|jj d||jdfdS)NrrFT) roffsetr'positionrlrr map_indexmapr)rrrr'Z blockinfoZlastposZrealposr5r5r6rjs(   z_FileInFile.__init__cCsdS)Nr5)rr5r5r6rsz_FileInFile.flushcCsdS)NTr5)rr5r5r6readablesz_FileInFile.readablecCsdS)NFr5)rr5r5r6writablesz_FileInFile.writablecCs |jjS)N)rseekable)rr5r5r6rsz_FileInFile.seekablecCs|jS)z*Return the current file position. )r)rr5r5r6rsz_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_ENDrG)rrwhencer5r5r6rs   z_FileInFile.seekc Cs|dkr|j|j}nt||j|j}d}x|dkr xZ|j|j\}}}}||jkob|knrlPq:|jd7_|jt|jkr:d|_q:Wt|||j}|r|jj||j||jj|}t||krt d||7}n |t |7}||8}|j|7_q.W|S)z!Read data from the file. Nrrr#zunexpected end of data) r'rrrrr/rrrZrr0) rr'rTdatastartstoprr2rbr5r5r6rZs.      z_FileInFile.readcCs&|jt|}||dt|<t|S)N)rZr/)rrbrTr5r5r6readintosz_FileInFile.readintocCs d|_dS)NT)r)rr5r5r6rsz_FileInFile.close)N)N)rqrrrsrtrrrrrrrrrrZrrr5r5r5r6rds  rcseZdZfddZZS) ExFileObjectcs&t|j|j|j|j}tj|dS)N)rr offset_datar'sparsesuperr)rtarfiletarinfor) __class__r5r6rs  zExFileObject.__init__)rqrrrsr __classcell__r5r5)rr6rsrs([0-9]{1,20}) c@seZdZdZdiZdjddZddZddZeeeZ ddZ dd Z ee e Z d!d"Z d#d$Zeed%fd&d'Zd(d)Zd*d+Zd,d-Zed.d/Zd0d1Zed2d3Zed4d5Zed6d7Zed8d9Zed:d;Zedd?Zd@dAZ dBdCZ!dDdEZ"dFdGZ#dHdIZ$dJdKZ%dLdMZ&dNdOZ'dPdQZ(dRdSZ)dTdUZ*dVdWZ+dXdYZ,dZd[Z-d\d]Z.d^d_Z/d`daZ0dbdcZ1dddeZ2dfdgZ3dhS)kraInformational 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. rrhr)r*r'r(chksumtypelinknamer+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)rrhr)r*r'r(rREGTYPErrr+r,rrrrrr)rrr5r5r6rs"zTarInfo.__init__cCs|jS)N)r)rr5r5r6_getpathszTarInfo._getpathcCs ||_dS)N)r)rrr5r5r6_setpathszTarInfo._setpathcCs|jS)N)r)rr5r5r6 _getlinkpathszTarInfo._getlinkpathcCs ||_dS)N)r)rrr5r5r6 _setlinkpath szTarInfo._setlinkpathcCsd|jj|jt|fS)Nz<%s %r at %#x>)rrqrid)rr5r5r6__repr__szTarInfo.__repr__cCsn|j|jd@|j|j|j|j|j|j|j|j |j |j |j d }|dt krj|djd rj|dd7<|S)z9Return the TarInfo's attributes as a dictionary. i) rrhr)r*r'r(rrrr+r,rrrr/)rrhr)r*r'r(rrrr+r,rrDIRTYPEr)rinfor5r5r6get_infos  zTarInfo.get_infosurrogateescapecCsT|j}|tkr|j|||S|tkr4|j|||S|tkrH|j||StddS)ztdt|dd}|t|krbt 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 jdrt|_|jtkr6d}g}xrtdD]f} y0t|||d} t||d|d} Wntk rPYnX|j| | f|d7}qWt|d} t|dd} || | f|_ |j!rN|j j"d|_ |rp|jt#krp|d|j |_ |S)zAConstruct a TarInfo object from a 512 byte bytes object. rz empty headerztruncated headerzend of file headerz bad checksumrlt|ii i)iIiQiYirirriii)$r/rurrvcountr0rwrKrUrHr<rrhr)r*r'r(rrrr+r,rrAREGTYPErrGNUTYPE_SPARSErDrGrboolrisdirrstrip GNU_TYPES)rrTr3r4robjrrstructsrJrnumbytes isextendedorigsizer5r5r6frombufsZ       zTarInfo.frombufcCs8|jjt}|j||j|j}|jjt|_|j|S)zOReturn the next TarInfo object from TarFile object tarfile. ) rrZrr0r3r4rr _proc_member)rrrTr+r5r5r6 fromtarfileBs zTarInfo.fromtarfilecCsT|jttfkr|j|S|jtkr,|j|S|jtttfkrF|j |S|j |SdS)zYChoose the right processing method depending on the type and call it. N) rrr _proc_gnulongr& _proc_sparser r SOLARIS_XHDTYPE _proc_pax _proc_builtin)rrr5r5r6r1Ws    zTarInfo._proc_membercCsR|jj|_|j}|js$|jtkr4||j|j7}||_|j |j |j |j |S)zfProcess a builtin type or an unknown type which will be treated as a regular file. ) rrrisregrSUPPORTED_TYPES_blockr'r_apply_pax_inforr3r4)rrrr5r5r6r7ds zTarInfo._proc_builtinc Cs|jj|j|j}y|j|}Wntk r>tdYnX|j|_|jt krft ||j |j |_ n|jtkrt ||j |j |_|S)zSProcess the blocks that hold a GNU longname or longlink member. z missing or bad subsequent header)rrZr:r'r2r rxrrrr<r3r4rrr)rrrTnextr5r5r6r3us  zTarInfo._proc_gnulongc Cs|j\}}}|`x|r|jjt}d}xvtdD]j}y0t|||d}t||d|d} Wntk rzPYnX|r| r|j|| f|d7}q0Wt|d}qW||_ |jj |_ |j |j |j |_||_ |S)z8Process a GNU sparse header plus extra headers. rrr#i)rrrZrrDrKrGrr'rrrr:r'r) rrr,r.r/rTrrJrr-r5r5r6r4s(    zTarInfo._proc_sparsec Cs|jj|j|j}|jtkr&|j}n |jj}d}d}g}x0t||koV||dkrnt j ||}|srt dyt |j d}Wntk rt dYnX|dkrt d||t|krt d|jd|d} ||jdd| } | jd\} } } | s"| dks"|| dkr*t d|j|| | f| dkrd|dkrd| d kr`|j}nd }||7}q@W|dkr~d }x`|D]X\}} } |j| d d |j}|tkr|j| ||j|j}n|j| d d |j}|||<qWy|j|}Wntk r td YnXd |kr&|j||nFd |kr>|j||n.|jddkrl|jddkrl|j||||jttfkr|j ||j|j|j!|_!d|kr|j"}|j#s|jt$kr||j|j7}||_!|S)zVProcess an extended or global header as described in POSIX.1-2008. rNzinvalid headerr#rrs hdrcharsetsBINARYzutf-8z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrCr')%rrZr:r'rr rrr/_header_length_prefix_rematchrHrEgrouprGrrk partitionrr3_decode_pax_fieldr4PAX_NAME_FIELDSr2r rx_proc_gnusparse_01_proc_gnusparse_00r_proc_gnusparse_10r r5r;rrr8r9)rrrTrrr3 raw_headersrAr2Zheader_value_end_offsetZkeyword_and_valueZ raw_keywordZequalsZ raw_valuerrr<rr5r5r6r6sx                 zTarInfo._proc_paxc Csg}g}x|D]\}}}|dkrVy|jt|jWqtk rRtdYqXq|dkry|jt|jWqtk rtdYqXqWtt|||_dS)z?Process a GNU tar extended sparse header, version 0.0. sGNU.sparse.offsetzinvalid headersGNU.sparse.numbytesN)rrEr:rGrHlistzipr)rr<rIZoffsetsr-_rrr5r5r6rG!szTarInfo._proc_gnusparse_00cCs@dd|djdD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|qSr5)rE).0xr5r5r6 8sz.TarInfo._proc_gnusparse_01..zGNU.sparse.map,Nr$r#)rrJrKr)rr<rrr5r5r6rF5szTarInfo._proc_gnusparse_01cCsd}g}|jjt}|jdd\}}t|}xJt||dkrvd|krV||jjt7}|jdd\}}|jt|q.W|jj|_t t |ddd|ddd|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Nrr#r$) rrZrrrEr/rrrrJrKr)rr<rrZfieldsrrTZnumberr5r5r6rH;s  zTarInfo._proc_gnusparse_10c Csx|jD]\}}|dkr(t|d|q |dkrBt|dt|q |dkr\t|dt|q |tkr |tkryt||}Wntk rd}YnX|dkr|jd}t|||q W|j|_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerrN) rsetattrrE PAX_FIELDSPAX_NUMBER_FIELDSrGr)rr)rrr3r4rrr5r5r6r;Ks"  zTarInfo._apply_pax_infoc Cs.y |j|dStk r(|j||SXdS)z1Decode a single field from a pax record. rBN)r:UnicodeDecodeError)rrr3Zfallback_encodingZfallback_errorsr5r5r6rDbs zTarInfo._decode_pax_fieldcCs2|dkrtdt|t\}}|r*|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. rzinvalid offsetr#)rHrYr)rr$r`rar5r5r6r:js zTarInfo._blockcCs |jtkS)N)r REGULAR_TYPES)rr5r5r6r8vsz TarInfo.isregcCs|jS)N)r8)rr5r5r6isfilexszTarInfo.isfilecCs |jtkS)N)rr)rr5r5r6r(zsz TarInfo.isdircCs |jtkS)N)rSYMTYPE)rr5r5r6issym|sz TarInfo.issymcCs |jtkS)N)rLNKTYPE)rr5r5r6islnk~sz TarInfo.islnkcCs |jtkS)N)rCHRTYPE)rr5r5r6ischrsz TarInfo.ischrcCs |jtkS)N)rBLKTYPE)rr5r5r6isblksz TarInfo.isblkcCs |jtkS)N)rFIFOTYPE)rr5r5r6isfifoszTarInfo.isfifocCs |jdk S)N)r)rr5r5r6issparseszTarInfo.issparsecCs|jtttfkS)N)rr[r]r_)rr5r5r6isdevsz TarInfo.isdevN)rrhr)r*r'r(rrrr+r,rrrrrrrrr)r)4rqrrrsrt __slots__rrrpropertyr%rrr&rrrr rrrr classmethodrr staticmethodrrrr r0r2r1r7r3r4r6rGrFrHr;rDr:r8rVr(rXrZr\r^r`rarbr5r5r5r6rs`    1    3 ?  z c @seZdZdZdZdZdZdZeZ e Z dZ e ZeZd\dd Zedddefd d Zed]d d Zed^ddZed_ddZed`ddZdddddZddZddZddZd d!Zdad"d#Zdbdd%d&d'Zdcdd(d)d*Z ddd+d,Z!dedd.d/d0Z"dfdd.d2d3Z#d4d5Z$dgd6d7Z%d8d9Z&d:d;Z'dd?Z)d@dAZ*dBdCZ+dDdEZ,dFdGZ-dHdIZ.dJdKZ/dhdLdMZ0dNdOZ1didPdQZ2dRdSZ3dTdUZ4dVdWZ5dXdYZ6dZd[Z7dS)jrz=The TarFile Class provides an interface to tar archives. rFr#NrzrcCsddddd}||krtd||_|||_|sj|jdkrVtjj| rVd|_d|_t||j}d |_n@|d krt|d rt |j t t fr|j }t|d r|j|_d |_|rtjj |nd |_ ||_|d k r||_|d k r||_|d k r||_|d k r||_|d k r||_| |_| d k r4|jtkr4| |_ni|_| d k rJ| |_| d k rZ| |_| |_d |_g|_d |_|jj|_i|_y|jdkrd |_ |j!|_ |jdkr8x|jj"|jy|jj#|}|jj$|WnTt%k r|jj"|jPYn0t&k r0}zt't |WYd d }~XnXqW|jdkrd |_|jr|jj(|jj)}|jj*||jt+|7_Wn&|js|jj,d |_YnXd 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. rbzr+bwbZxb)rzar{rNz!mode must be 'r', 'a', 'w' or 'x'rir{FNrrhTrzrN)rir{rN)-rGrh_moder}r%exists bltn_openrrrrr rLabspathrrPr dereference ignore_zerosr3r4rrdebug errorlevel copybufsizermembers_loadedrrinodes firstmemberr<rr2rrwr rrrr[r/r)rrrhrrPrrnror3r4rrprqrrZmodeserTr5r5r6rs             $   zTarFile.__init__c s| r| rtd|dkrfdd}xttj|dD]b}tj|}|dk r\|j} y||d|f|Sttfk r|dk r|j| w8Yq8Xq8Wtdnd |kr |jd d \} }| pd} |pd }|jkrtj|}n td |||| |f|Sd |kr|jd d \} }| p.d} |p8d }| dkrLtdt || |||} y|| | f|} Wn| j YnXd| _ | S|dkrj |||f|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 openrzr:*csj|dkS)Ntaropen) OPEN_METH)r)rr5r6not_compressed?sz$TarFile.open..not_compressed)keyNz%file could not be opened successfully:r#rzunknown compression type %r|r{zmode must be 'r' or 'w'FrirNzundiscernible mode)rzrx)rzr{)rir{rN) rGsortedrzrlrrrrrrrrry) rrrhrr_kwargsr{rfuncZ saved_posrgstreamrr5)rr6rsP%             z TarFile.opencKs |dkrtd||||f|S)zCOpen uncompressed tar archive name for reading or writing. rzrir{rNz!mode must be 'r', 'a', 'w' or 'x')rzrir{rN)rG)rrrhrrr5r5r6rypszTarFile.taropenrcKs|d krtdyddl}|jWn ttfk rBtdYnXy|j||d||}Wn.tk r|dk r|dkrtd YnXy|j|||f|}WnBtk r|j |dkrtd Yn|j YnXd |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rzr{rNzmode must be 'r', 'w' or 'x'rNzgzip module is not availablerbznot a gzip fileF)rzr{rN) rGgzipZGzipFilerAttributeErrorrrrryrr)rrrhr compresslevelrrrr5r5r6gzopenxs2 zTarFile.gzopencKs|d krtdy ddl}Wntk r8tdYnX|j|pD|||d}y|j|||f|}WnFttfk r|j|dkrt d Yn|jYnXd |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rzr{rNzmode must be 'r', 'w' or 'x'rNzbz2 module is not available)rznot a bzip2 fileF)rzr{rN) rGrrrZBZ2FileryrEOFErrorrrr)rrrhrrrrrr5r5r6bz2opens(  zTarFile.bz2opencKs|d krtdy ddl}Wntk r8tdYnX|j|pD|||d}y|j|||f|}WnH|jtfk r|j|dkrt d Yn|jYnXd |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rzr{rNzmode must be 'r', 'w' or 'x'rNzlzma module is not available)presetznot an lzma fileF)rzr{rN) rGrrrZLZMAFileryrrrrr)rrrhrrrrrr5r5r6xzopens& zTarFile.xzopenryrrr)rrrrc Cs|jr dSd|_z`|jdkrn|jjttd|jtd7_t|jt\}}|dkrn|jjtt|Wd|j s|jj XdS) zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTrir{rNr$r)rir{rN) rrhrr[r0rrrY RECORDSIZErr)rr`rar5r5r6rs z TarFile.closecCs"|j|}|dkrtd||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)rrrr5r5r6 getmembers  zTarFile.getmembercCs|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. )_checkrt_loadrs)rr5r5r6 getmembersszTarFile.getmemberscCsdd|jDS)zReturn the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). cSsg|] }|jqSr5)r)rMrr5r5r6rO sz$TarFile.getnames..)r)rr5r5r6getnamesszTarFile.getnamesc Csp|jd|dk r|j}|dkr$|}tjj|\}}|jtjd}|jd}|j}||_ |dkrt tdr|j rtj |}qtj |}ntj|j}d}|j}t j|r|j|jf} |j r|jdkr| |jkr||j| krt} |j| }nt} | drx||j| <nht j|r"t} nVt j|r4t} nDt j|rPt} tj|}n(t j|rbt } nt j!|rtt"} ndS||_||_#|j$|_%|j&|_'| tkr|j(|_)nd|_)|j*|_+| |_,||_-t.ryt.j/|j%d|_0Wnt1k rYnXt2r*yt2j3|j'd|_4Wnt1k r(YnX| t t"fkrlt tdrlt td rltj5|j6|_7tj8|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. awxNrlstatrr#rmajorminor):rrr}r% splitdriverseplstriprrrrnrrffstatfilenost_modeS_ISREGst_inost_devst_nlinkrurYrS_ISDIRrS_ISFIFOr_S_ISLNKrWreadlinkS_ISCHRr[S_ISBLKr]rhst_uidr)st_gidr*st_sizer'st_mtimer(rrpwdgetpwuidr+rgrpZgetgrgidr,rst_rdevrrr) rrarcnamerZdrvrZstatresrZstmdinoderr5r5r6 gettarinfos~                 zTarFile.gettarinfoT)rscCs|j|dkr|}x|D]}|rttj|jtd|jp@|j|jpJ|jf|j sb|j r|tdd|j |j fntd|j tdtj|jddt|j|jrdnd |r|jrtd |j|jrtd |jtqWdS) 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%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02drrrz-> zlink to )rrprfrgrhr+r)r,r*r\r^rrr'rZ localtimer(rr(rXrrZro)rverbosersrr5r5r6rJrs* z TarFile.list)filterc Csv|jd|dkr|}|dk rPddl}|jdtd||rP|jdd|dS|jdk rtjj||jkr|jdd|dS|jd||j ||}|dkr|jdd |dS|dk r||}|dkr|jdd|dS|j rt |d }|j ||WdQRXnd|j rh|j ||rrxHtj|D].}|jtjj||tjj|||||d q4Wn |j |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 insteadr$ztarfile: Excluded %rztarfile: Skipped %rr#ztarfile: Unsupported type %rrg)r)rrcrdre_dbgrr}r%rmrr8rladdfiler(listdiraddr) rrr recursiveZexcluderrcrfr5r5r6rsB       z TarFile.addcCs|jdtj|}|j|j|j|j}|jj||jt |7_|j }|dk rt ||j|j |dt |j t\}}|dkr|jjtt||d7}|j|t7_|jj|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)r_rr#)rrrrPr3r4rr[rr/rrrXr'rYrr0rsr)rrrrTr_r`rar5r5r6rs   zTarFile.addfile.) numeric_ownercCsg}|dkr|}xF|D]>}|jr<|j|tj|}d|_|j|||j |dqW|jddd|jx|D]}tjj ||j }y,|j |||d|j |||j ||Wqvtk r}z$|jdkrւn|jdd |WYdd}~XqvXqvWdS) 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. Ni) set_attrsrcSs|jS)N)r)rir5r5r6sz$TarFile.extractall..)r|)rr#z tarfile: %s)r(rrrhextractsortreverser}r%rrchownutimechmodr rqr)rr%rsrZ directoriesrdirpathrwr5r5r6 extractalls,       zTarFile.extractallrcCs |jdt|tr |j|}n|}|jr>tjj||j|_ y"|j |tjj||j ||dWnt k r}zJ|j dkrn6|jdkr|jdd|jn|jdd|j|jfWYdd}~XnBtk r}z$|j dkrn|jdd|WYdd}~XnXdS)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. rz)rrrNr#z tarfile: %sztarfile: %s %r)rrr rrZr}r%rrr_extract_memberrrrqfilenamerstrerrorr )rmemberr%rrrrwr5r5r6rs(      ( zTarFile.extractcCs|jdt|tr |j|}n|}|js6|jtkrB|j||S|jsR|j rzt|j t rht dq~|j |j|SndSdS)zExtract 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. Otherwise, None is returned. rzz'cannot extract (sym)link as file objectN)rrr rr8rr9 fileobjectrZrXrrr extractfile_find_link_target)rrrr5r5r6r6s      zTarFile.extractfilecCsV|jd}|jdtj}tjj|}|r@tjj| r@tj||jsP|j rj|j dd|j |j fn|j d|j |j r|j||n|jr|j||nx|jr|j||nb|js|jr|j||nD|js|j r|j||n&|jtkr|j||n |j|||rR|j||||j sR|j|||j||dS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. rr#z%s -> %sN)r)rr}rr%dirnamerkmakedirsrZrXrrrr8makefiler(makedirr`makefifor\r^makedevmakelinkrr9 makeunknownrrr)rr targetpathrrZ upperdirsr5r5r6rUs4       zTarFile._extract_memberc Cs*ytj|dWntk r$YnXdS)z,Make a directory called targetpath. iN)r}mkdirFileExistsError)rrrr5r5r6rszTarFile.makedircCs|j}|j|j|j}t|df}|jdk rrx,|jD]"\}}|j|t|||t|q6W|j|j|j nt|||jt|WdQRXdS)z'Make a file called targetpath. rhN) rrrrrrlrrXrr'truncate)rrrsourcer_targetrr'r5r5r6rs      zTarFile.makefilecCs"|j|||jdd|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)rrr)rrrr5r5r6rs zTarFile.makeunknowncCs"ttdrtj|ntddS)z'Make a fifo called targetpath. mkfifozfifo not supported by systemN)rr}rr )rrrr5r5r6rs  zTarFile.makefifocCsbttd sttd r td|j}|jr:|tjO}n |tjO}tj||tj |j |j dS)zttdr:ytj||jWntk r8tdYnXdS)zASet file permissions of targetpath according to tarinfo. rzcould not change modeN)rr}rrhrr )rrrr5r5r6rs  z TarFile.chmodc CsHttdsdSytj||j|jfWntk rBtdYnXdS)zBSet modification time of targetpath according to tarinfo. rNz"could not change modification time)rr}rr(rr )rrrr5r5r6rs  z TarFile.utimecCs|jd|jdk r$|j}d|_|S|j|jjkrZ|jj|jd|jjdsZtdd}xby|jj |}WnHt k r}z2|j r|j dd|j|f|jt 7_wbWYdd}~Xntk r,}zN|j r|j dd|j|f|jt 7_wbn|jdkrtt|WYdd}~Xntk rT|jdkrPtdYnjtk r}z|jdkr~tt|WYdd}~Xn0tk r}ztt|WYdd}~XnXPqbW|dk r|jj|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. ZraNr#zunexpected end of datar$z0x%X: %srz empty fileT)rrvrrrrrZrrr2rwrorrrHr rurvrxrsrrt)rmrrwr5r5r6r< sL        z TarFile.nextcCsn|j}|dk r"|d|j|}|r2tjj|}x6t|D]*}|rTtjj|j}n|j}||kr<|SqzShow listing of a tarfile)metavarrz-ez --extract+ zExtract tarfile into target dir)nargsrrz-cz--createzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validrz)rz{!r} is a tar archive.r#z{!r} is not a tar archive. zr:*)rr$)r%rz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.rrr)z.gzz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:r{z{!r} file created.)rr)rr)argparseArgumentParser add_argumentZadd_mutually_exclusive_group parse_argsZtestrrrrormrrrPexitrJrrr/r}curdirZ format_helprZcreatepopr%splitextr)rrparserrBargsr\rZtfrrZtar_namerLZextZ compressionsZtar_modeZ tar_files file_namer5r5r6main s                r __main__)r%r&r'r(r)r*r+r,)crtversion __author__Z__date__Z __cvsid__ __credits__builtinsrrlrmr}rrWrfrrSrrerrrrNotImplementedErrorrr NameError__all__r0rrrrrrrrr%rYrWr[r]rr_ZCONTTYPErrr&r r r5r rrrr9rUr*rRrErrErSrr getfilesystemencodingr7r<rKrQrUrXrgrp Exceptionrr rrr r rurvrwrHrxryrobjectrrBufferedReaderrcompiler@rrrr rqr5r5r5r6s         wh 7, Z