OpenQuizz
Une application de gestion des contenus pédagogiques
TarFile Class Reference
Inheritance diagram for TarFile:
Collaboration diagram for TarFile:

Public Member Functions

def __init__ (self, name=None, mode="r", fileobj=None, format=None, tarinfo=None, dereference=None, ignore_zeros=None, encoding=None, errors="surrogateescape", pax_headers=None, debug=None, errorlevel=None)
 
def open (cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs)
 
def taropen (cls, name, mode="r", fileobj=None, **kwargs)
 
def gzopen (cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs)
 
def bz2open (cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs)
 
def close (self)
 
def getmember (self, name)
 
def getmembers (self)
 
def getnames (self)
 
def gettarinfo (self, name=None, arcname=None, fileobj=None)
 
def list (self, verbose=True)
 
def add (self, name, arcname=None, recursive=True, exclude=None, filter=None)
 
def addfile (self, tarinfo, fileobj=None)
 
def extractall (self, path=".", members=None)
 
def extract (self, member, path="", set_attrs=True)
 
def extractfile (self, member)
 
def makedir (self, tarinfo, targetpath)
 
def makefile (self, tarinfo, targetpath)
 
def makeunknown (self, tarinfo, targetpath)
 
def makefifo (self, tarinfo, targetpath)
 
def makedev (self, tarinfo, targetpath)
 
def makelink (self, tarinfo, targetpath)
 
def chown (self, tarinfo, targetpath)
 
def chmod (self, tarinfo, targetpath)
 
def utime (self, tarinfo, targetpath)
 
def next (self)
 
def __iter__ (self)
 
def __enter__ (self)
 
def __exit__ (self, type, value, traceback)
 

Data Fields

 mode
 
 name
 
 fileobj
 
 pax_headers
 
 closed
 
 members
 
 offset
 
 inodes
 
 firstmember
 

Static Public Attributes

 debug
 
 dereference
 
 ignore_zeros
 
 errorlevel
 
 format
 
 encoding
 
 errors
 
 tarinfo
 
 fileobject
 
 OPEN_METH
 

Detailed Description

The TarFile Class provides an interface to tar archives.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name = None,
  mode = "r",
  fileobj = None,
  format = None,
  tarinfo = None,
  dereference = None,
  ignore_zeros = None,
  encoding = None,
  errors = "surrogateescape",
  pax_headers = None,
  debug = None,
  errorlevel = None 
)
Open 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.

Member Function Documentation

◆ __enter__()

def __enter__ (   self)

◆ __exit__()

def __exit__ (   self,
  type,
  value,
  traceback 
)

◆ __iter__()

def __iter__ (   self)
Provide an iterator object.

◆ add()

def add (   self,
  name,
  arcname = None,
  recursive = True,
  exclude = None,
  filter = None 
)
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.

◆ addfile()

def addfile (   self,
  tarinfo,
  fileobj = None 
)
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.

◆ bz2open()

def bz2open (   cls,
  name,
  mode = "r",
  fileobj = None,
  compresslevel = 9,
**  kwargs 
)
Open bzip2 compressed tar archive name for reading or writing.
   Appending is not allowed.

◆ chmod()

def chmod (   self,
  tarinfo,
  targetpath 
)
Set file permissions of targetpath according to tarinfo.

◆ chown()

def chown (   self,
  tarinfo,
  targetpath 
)
Set owner of targetpath according to tarinfo.

◆ close()

def close (   self)
Close the TarFile. In write-mode, two finishing zero blocks are
   appended to the archive.

◆ extract()

def extract (   self,
  member,
  path = "",
  set_attrs = True 
)
Extract 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.

◆ extractall()

def extractall (   self,
  path = ".",
  members = None 
)
Extract 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().

◆ extractfile()

def extractfile (   self,
  member 
)
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, 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()

◆ getmember()

def getmember (   self,
  name 
)
Return 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.

◆ getmembers()

def getmembers (   self)
Return the members of the archive as a list of TarInfo objects. The
   list has the same order as the members in the archive.

◆ getnames()

def getnames (   self)
Return the members of the archive as a list of their names. It has
   the same order as the list returned by getmembers().

◆ gettarinfo()

def gettarinfo (   self,
  name = None,
  arcname = None,
  fileobj = None 
)
Create 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.

◆ gzopen()

def gzopen (   cls,
  name,
  mode = "r",
  fileobj = None,
  compresslevel = 9,
**  kwargs 
)
Open gzip compressed tar archive name for reading or writing.
   Appending is not allowed.

◆ list()

def list (   self,
  verbose = True 
)
Print 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.

◆ makedev()

def makedev (   self,
  tarinfo,
  targetpath 
)
Make a character or block device called targetpath.

◆ makedir()

def makedir (   self,
  tarinfo,
  targetpath 
)
Make a directory called targetpath.

◆ makefifo()

def makefifo (   self,
  tarinfo,
  targetpath 
)
Make a fifo called targetpath.

◆ makefile()

def makefile (   self,
  tarinfo,
  targetpath 
)
Make a file called targetpath.

◆ makelink()

def makelink (   self,
  tarinfo,
  targetpath 
)
Make 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.

◆ makeunknown()

def makeunknown (   self,
  tarinfo,
  targetpath 
)
Make a file from a TarInfo object with an unknown type
   at targetpath.

◆ next()

def next (   self)
Return the next member of the archive as a TarInfo object, when
   TarFile is opened for reading. Return None if there is no more
   available.

◆ open()

def open (   cls,
  name = None,
  mode = "r",
  fileobj = None,
  bufsize = RECORDSIZE,
**  kwargs 
)
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

◆ taropen()

def taropen (   cls,
  name,
  mode = "r",
  fileobj = None,
**  kwargs 
)
Open uncompressed tar archive name for reading or writing.

◆ utime()

def utime (   self,
  tarinfo,
  targetpath 
)
Set modification time of targetpath according to tarinfo.

Field Documentation

◆ closed

closed

◆ debug

debug
static

◆ dereference

dereference
static

◆ encoding

encoding
static

◆ errorlevel

errorlevel
static

◆ errors

errors
static

◆ fileobj

fileobj

◆ fileobject

fileobject
static

◆ firstmember

firstmember

◆ format

format
static

◆ ignore_zeros

ignore_zeros
static

◆ inodes

inodes

◆ members

members

◆ mode

mode

◆ name

name

◆ offset

offset

◆ OPEN_METH

OPEN_METH
static

◆ pax_headers

pax_headers

◆ tarinfo

tarinfo
static

The documentation for this class was generated from the following file: