Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.tarfile Namespace Reference

Classes

class  TarError
class  ExtractError
class  ReadError
class  CompressionError
class  StreamError
class  _LowLevelFile
class  _Stream
class  _StreamProxy
class  _BZ2Proxy
class  _FileInFile
class  ExFileObject
class  TarInfo
class  TarFile
class  TarIter
class  _section
class  _data
class  _hole
class  _ringbuffer
class  TarFileCompat

Functions

def stn
def nts
def nti
def itn
def calc_chksums
def copyfileobj
def filemode
def is_tarfile

Variables

string __version__ = "$Revision: 53162 $"
string version = "0.8.0"
string __author__ = "Lars Gustäbel (lars@gustaebel.de)"
string __date__ = "$Date: 2006-12-27 21:36:58 +1100 (Wed, 27 Dec 2006) $"
string __cvsid__ = "$Id: tarfile.py 53162 2006-12-27 10:36:58Z lars.gustaebel $"
string __credits__ = "Gustavo Niemeyer, Niels Gustäbel, Richard Townsend."
 grp = pwdNone
list __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
string NUL = "\0"
int BLOCKSIZE = 512
int RECORDSIZE = 20
string MAGIC = "ustar"
string VERSION = "00"
int LENGTH_NAME = 100
int LENGTH_LINK = 100
int LENGTH_PREFIX = 155
int MAXSIZE_MEMBER = 077777777777L
string REGTYPE = "0"
string AREGTYPE = "\0"
string LNKTYPE = "1"
string SYMTYPE = "2"
string CHRTYPE = "3"
string BLKTYPE = "4"
string DIRTYPE = "5"
string FIFOTYPE = "6"
string CONTTYPE = "7"
string GNUTYPE_LONGNAME = "L"
string GNUTYPE_LONGLINK = "K"
string GNUTYPE_SPARSE = "S"
tuple SUPPORTED_TYPES
tuple REGULAR_TYPES
int S_IFLNK = 0120000
int S_IFREG = 0100000
int S_IFBLK = 0060000
int S_IFDIR = 0040000
int S_IFCHR = 0020000
int S_IFIFO = 0010000
int TSUID = 04000
int TSGID = 02000
int TSVTX = 01000
int TUREAD = 0400
int TUWRITE = 0200
int TUEXEC = 0100
int TGREAD = 0040
int TGWRITE = 0020
int TGEXEC = 0010
int TOREAD = 0004
int TOWRITE = 0002
int TOEXEC = 0001
tuple filemode_table
tuple normpath = lambdapath:os.path.normpath(path)
int TAR_PLAIN = 0
int TAR_GZIPPED = 8
 open = TarFile.open

Function Documentation

Calculate 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.

Definition at line 202 of file tarfile.py.

00202 
00203 def calc_chksums(buf):
00204     """Calculate the checksum for a member's header by summing up all
00205        characters except for the chksum field which is treated as if
00206        it was filled with spaces. According to the GNU tar sources,
00207        some tars (Sun and NeXT) calculate chksum with signed char,
00208        which will be different if there are chars in the buffer with
00209        the high bit set. So we calculate two checksums, unsigned and
00210        signed.
00211     """
00212     unsigned_chksum = 256 + sum(struct.unpack("148B", buf[:148]) + struct.unpack("356B", buf[156:512]))
00213     signed_chksum = 256 + sum(struct.unpack("148b", buf[:148]) + struct.unpack("356b", buf[156:512]))
00214     return unsigned_chksum, signed_chksum

Here is the caller graph for this function:

def MoinMoin.support.tarfile.copyfileobj (   src,
  dst,
  length = None 
)
Copy length bytes from fileobj src to fileobj dst.
   If length is None, copy the entire content.

Definition at line 215 of file tarfile.py.

00215 
00216 def copyfileobj(src, dst, length=None):
00217     """Copy length bytes from fileobj src to fileobj dst.
00218        If length is None, copy the entire content.
00219     """
00220     if length == 0:
00221         return
00222     if length is None:
00223         shutil.copyfileobj(src, dst)
00224         return
00225 
00226     BUFSIZE = 16 * 1024
00227     blocks, remainder = divmod(length, BUFSIZE)
00228     for b in xrange(blocks):
00229         buf = src.read(BUFSIZE)
00230         if len(buf) < BUFSIZE:
00231             raise IOError("end of file reached")
00232         dst.write(buf)
00233 
00234     if remainder != 0:
00235         buf = src.read(remainder)
00236         if len(buf) < remainder:
00237             raise IOError("end of file reached")
00238         dst.write(buf)
00239     return

Here is the caller graph for this function:

Convert a file's mode to a string of the form
   -rwxrwxrwx.
   Used by TarFile.list()

Definition at line 267 of file tarfile.py.

00267 
00268 def filemode(mode):
00269     """Convert a file's mode to a string of the form
00270        -rwxrwxrwx.
00271        Used by TarFile.list()
00272     """
00273     perm = []
00274     for table in filemode_table:
00275         for bit, char in table:
00276             if mode & bit == bit:
00277                 perm.append(char)
00278                 break
00279         else:
00280             perm.append("-")
00281     return "".join(perm)

Here is the caller graph for this function:

Return True if name points to a tar archive that we
   are able to handle, else return False.

Definition at line 2177 of file tarfile.py.

02177 
02178 def is_tarfile(name):
02179     """Return True if name points to a tar archive that we
02180        are able to handle, else return False.
02181     """
02182     try:
02183         t = open(name)
02184         t.close()
02185         return True
02186     except TarError:
02187         return False

def MoinMoin.support.tarfile.itn (   n,
  digits = 8,
  posix = False 
)
Convert a python number to a number field.

Definition at line 175 of file tarfile.py.

00175 
00176 def itn(n, digits=8, posix=False):
00177     """Convert a python number to a number field.
00178     """
00179     # POSIX 1003.1-1988 requires numbers to be encoded as a string of
00180     # octal digits followed by a null-byte, this allows values up to
00181     # (8**(digits-1))-1. GNU tar allows storing numbers greater than
00182     # that if necessary. A leading 0200 byte indicates this particular
00183     # encoding, the following digits-1 bytes are a big-endian
00184     # representation. This allows values up to (256**(digits-1))-1.
00185     if 0 <= n < 8 ** (digits - 1):
00186         s = "%0*o" % (digits - 1, n) + NUL
00187     else:
00188         if posix:
00189             raise ValueError("overflow in number field")
00190 
00191         if n < 0:
00192             # XXX We mimic GNU tar's behaviour with negative numbers,
00193             # this could raise OverflowError.
00194             n = struct.unpack("L", struct.pack("l", n))[0]
00195 
00196         s = ""
00197         for i in xrange(digits - 1):
00198             s = chr(n & 0377) + s
00199             n >>= 8
00200         s = chr(0200) + s
00201     return s

Here is the caller graph for this function:

Convert a number field to a python number.

Definition at line 161 of file tarfile.py.

00161 
00162 def nti(s):
00163     """Convert a number field to a python number.
00164     """
00165     # There are two possible encodings for a number field, see
00166     # itn() below.
00167     if s[0] != chr(0200):
00168         n = int(nts(s) or "0", 8)
00169     else:
00170         n = 0L
00171         for i in xrange(len(s) - 1):
00172             n <<= 8
00173             n += ord(s[i + 1])
00174     return n

Here is the call graph for this function:

Here is the caller graph for this function:

Convert a null-terminated string field to a python string.

Definition at line 152 of file tarfile.py.

00152 
00153 def nts(s):
00154     """Convert a null-terminated string field to a python string.
00155     """
00156     # Use the string up to the first null char.
00157     p = s.find("\0")
00158     if p == -1:
00159         return s
00160     return s[:p]

Here is the caller graph for this function:

def MoinMoin.support.tarfile.stn (   s,
  length 
)
Convert a python string to a null-terminated string buffer.

Definition at line 147 of file tarfile.py.

00147 
00148 def stn(s, length):
00149     """Convert a python string to a null-terminated string buffer.
00150     """
00151     return s[:length] + (length - len(s)) * NUL

Here is the caller graph for this function:


Variable Documentation

Definition at line 77 of file tarfile.py.

string MoinMoin.support.tarfile.__author__ = "Lars Gustäbel (lars@gustaebel.de)"

Definition at line 40 of file tarfile.py.

string MoinMoin.support.tarfile.__credits__ = "Gustavo Niemeyer, Niels Gustäbel, Richard Townsend."

Definition at line 43 of file tarfile.py.

string MoinMoin.support.tarfile.__cvsid__ = "$Id: tarfile.py 53162 2006-12-27 10:36:58Z lars.gustaebel $"

Definition at line 42 of file tarfile.py.

string MoinMoin.support.tarfile.__date__ = "$Date: 2006-12-27 21:36:58 +1100 (Wed, 27 Dec 2006) $"

Definition at line 41 of file tarfile.py.

string MoinMoin.support.tarfile.__version__ = "$Revision: 53162 $"

Definition at line 36 of file tarfile.py.

Definition at line 94 of file tarfile.py.

Definition at line 98 of file tarfile.py.

Definition at line 83 of file tarfile.py.

Definition at line 97 of file tarfile.py.

Definition at line 101 of file tarfile.py.

Definition at line 99 of file tarfile.py.

Definition at line 100 of file tarfile.py.

Initial value:
00001 (
00002     ((S_IFLNK,      "l"),
00003      (S_IFREG,      "-"),
00004      (S_IFBLK,      "b"),
00005      (S_IFDIR,      "d"),
00006      (S_IFCHR,      "c"),
00007      (S_IFIFO,      "p")),
00008 
00009     ((TUREAD,       "r"),),
00010     ((TUWRITE,      "w"),),
00011     ((TUEXEC|TSUID, "s"),
00012      (TSUID,        "S"),
00013      (TUEXEC,       "x")),
00014 
00015     ((TGREAD,       "r"),),
00016     ((TGWRITE,      "w"),),
00017     ((TGEXEC|TSGID, "s"),
00018      (TSGID,        "S"),
00019      (TGEXEC,       "x")),
00020 
00021     ((TOREAD,       "r"),),
00022     ((TOWRITE,      "w"),),
00023     ((TOEXEC|TSVTX, "t"),
00024      (TSVTX,        "T"),
00025      (TOEXEC,       "x"))
00026 )

Definition at line 240 of file tarfile.py.

Definition at line 104 of file tarfile.py.

Definition at line 103 of file tarfile.py.

Definition at line 105 of file tarfile.py.

Definition at line 74 of file tarfile.py.

Definition at line 89 of file tarfile.py.

Definition at line 88 of file tarfile.py.

Definition at line 90 of file tarfile.py.

Definition at line 95 of file tarfile.py.

Definition at line 85 of file tarfile.py.

Definition at line 91 of file tarfile.py.

MoinMoin.support.tarfile.normpath = lambdapath:os.path.normpath(path)

Definition at line 283 of file tarfile.py.

Definition at line 82 of file tarfile.py.

Definition at line 2188 of file tarfile.py.

Definition at line 84 of file tarfile.py.

Definition at line 93 of file tarfile.py.

Initial value:
00001 (REGTYPE, AREGTYPE,             # file types that somehow
00002                  CONTTYPE, GNUTYPE_SPARSE)

Definition at line 116 of file tarfile.py.

Definition at line 124 of file tarfile.py.

Definition at line 126 of file tarfile.py.

Definition at line 125 of file tarfile.py.

Definition at line 127 of file tarfile.py.

Definition at line 122 of file tarfile.py.

Definition at line 123 of file tarfile.py.

Initial value:
00001 (REGTYPE, AREGTYPE, LNKTYPE,  # file types that tarfile
00002                    SYMTYPE, DIRTYPE, FIFOTYPE,  # can cope with.
00003                    CONTTYPE, CHRTYPE, BLKTYPE,
00004                    GNUTYPE_LONGNAME, GNUTYPE_LONGLINK,
00005                    GNUTYPE_SPARSE)

Definition at line 110 of file tarfile.py.

Definition at line 96 of file tarfile.py.

Definition at line 2127 of file tarfile.py.

Definition at line 2126 of file tarfile.py.

Definition at line 138 of file tarfile.py.

Definition at line 136 of file tarfile.py.

Definition at line 137 of file tarfile.py.

Definition at line 141 of file tarfile.py.

Definition at line 139 of file tarfile.py.

Definition at line 140 of file tarfile.py.

Definition at line 130 of file tarfile.py.

Definition at line 129 of file tarfile.py.

Definition at line 131 of file tarfile.py.

Definition at line 135 of file tarfile.py.

Definition at line 133 of file tarfile.py.

Definition at line 134 of file tarfile.py.

Definition at line 39 of file tarfile.py.

Definition at line 86 of file tarfile.py.