Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
MoinMoin.support.tarfile.TarInfo Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def frombuf
def tobuf
def isreg
def isfile
def isdir
def issym
def islnk
def ischr
def isblk
def isfifo
def issparse
def isdev

Public Attributes

 name
 mode
 uid
 gid
 size
 mtime
 chksum
 type
 linkname
 uname
 gname
 devmajor
 devminor
 offset
 offset_data
 buf

Static Public Attributes

tuple frombuf = classmethod(frombuf)

Private Member Functions

def _create_gnulong

Detailed Description

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

Definition at line 851 of file tarfile.py.


Constructor & Destructor Documentation

def MoinMoin.support.tarfile.TarInfo.__init__ (   self,
  name = "" 
)
Construct a TarInfo object. name is the optional name
   of the member.

Definition at line 859 of file tarfile.py.

00859 
00860     def __init__(self, name=""):
00861         """Construct a TarInfo object. name is the optional name
00862            of the member.
00863         """
00864         self.name = name        # member name (dirnames must end with '/')
00865         self.mode = 0666        # file permissions
00866         self.uid = 0            # user id
00867         self.gid = 0            # group id
00868         self.size = 0           # file size
00869         self.mtime = 0          # modification time
00870         self.chksum = 0         # header checksum
00871         self.type = REGTYPE     # member type
00872         self.linkname = ""      # link name
00873         self.uname = "user"     # user name
00874         self.gname = "group"    # group name
00875         self.devmajor = 0       # device major number
00876         self.devminor = 0       # device minor number
00877 
00878         self.offset = 0         # the tar header starts here
00879         self.offset_data = 0    # the file's data starts here


Member Function Documentation

Definition at line 880 of file tarfile.py.

00880 
00881     def __repr__(self):
00882         return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(self))

def MoinMoin.support.tarfile.TarInfo._create_gnulong (   self,
  name,
  type 
) [private]
Create a GNU longname/longlink header from name.
   It consists of an extended tar header, with the length
   of the longname as size, followed by data blocks,
   which contain the longname as a null terminated string.

Definition at line 991 of file tarfile.py.

00991 
00992     def _create_gnulong(self, name, type):
00993         """Create a GNU longname/longlink header from name.
00994            It consists of an extended tar header, with the length
00995            of the longname as size, followed by data blocks,
00996            which contain the longname as a null terminated string.
00997         """
00998         name += NUL
00999 
01000         tarinfo = self.__class__()
01001         tarinfo.name = "././@LongLink"
01002         tarinfo.type = type
01003         tarinfo.mode = 0
01004         tarinfo.size = len(name)
01005 
01006         # create extended header
01007         buf = tarinfo.tobuf()
01008         # create name blocks
01009         buf += name
01010         blocks, remainder = divmod(len(name), BLOCKSIZE)
01011         if remainder > 0:
01012             buf += (BLOCKSIZE - remainder) * NUL
01013         return buf

Here is the caller graph for this function:

def MoinMoin.support.tarfile.TarInfo.frombuf (   cls,
  buf 
)
Construct a TarInfo object from a 512 byte string buffer.

Definition at line 883 of file tarfile.py.

00883 
00884     def frombuf(cls, buf):
00885         """Construct a TarInfo object from a 512 byte string buffer.
00886         """
00887         if len(buf) != BLOCKSIZE:
00888             raise ValueError("truncated header")
00889         if buf.count(NUL) == BLOCKSIZE:
00890             raise ValueError("empty header")
00891 
00892         tarinfo = cls()
00893         tarinfo.buf = buf
00894         tarinfo.name = nts(buf[0:100])
00895         tarinfo.mode = nti(buf[100:108])
00896         tarinfo.uid = nti(buf[108:116])
00897         tarinfo.gid = nti(buf[116:124])
00898         tarinfo.size = nti(buf[124:136])
00899         tarinfo.mtime = nti(buf[136:148])
00900         tarinfo.chksum = nti(buf[148:156])
00901         tarinfo.type = buf[156:157]
00902         tarinfo.linkname = nts(buf[157:257])
00903         tarinfo.uname = nts(buf[265:297])
00904         tarinfo.gname = nts(buf[297:329])
00905         tarinfo.devmajor = nti(buf[329:337])
00906         tarinfo.devminor = nti(buf[337:345])
00907         prefix = nts(buf[345:500])
00908 
00909         if prefix and not tarinfo.issparse():
00910             tarinfo.name = prefix + "/" + tarinfo.name
00911 
00912         if tarinfo.chksum not in calc_chksums(buf):
00913             raise ValueError("invalid header")
        return tarinfo

Here is the call graph for this function:

Definition at line 1026 of file tarfile.py.

01026 
01027     def isblk(self):
        return self.type == BLKTYPE

Definition at line 1024 of file tarfile.py.

01024 
01025     def ischr(self):
        return self.type == CHRTYPE

Definition at line 1032 of file tarfile.py.

01032 
01033     def isdev(self):
01034         return self.type in (CHRTYPE, BLKTYPE, FIFOTYPE)
01035 # class TarInfo

Definition at line 1018 of file tarfile.py.

01018 
01019     def isdir(self):
        return self.type == DIRTYPE

Definition at line 1028 of file tarfile.py.

01028 
01029     def isfifo(self):
        return self.type == FIFOTYPE

Definition at line 1016 of file tarfile.py.

01016 
01017     def isfile(self):
        return self.isreg()

Here is the call graph for this function:

Definition at line 1022 of file tarfile.py.

01022 
01023     def islnk(self):
        return self.type == LNKTYPE

Definition at line 1014 of file tarfile.py.

01014 
01015     def isreg(self):
        return self.type in REGULAR_TYPES

Here is the caller graph for this function:

Definition at line 1030 of file tarfile.py.

01030 
01031     def issparse(self):
        return self.type == GNUTYPE_SPARSE

Definition at line 1020 of file tarfile.py.

01020 
01021     def issym(self):
        return self.type == SYMTYPE
def MoinMoin.support.tarfile.TarInfo.tobuf (   self,
  posix = False 
)
Return a tar header as a string of 512 byte blocks.

Definition at line 916 of file tarfile.py.

00916 
00917     def tobuf(self, posix=False):
00918         """Return a tar header as a string of 512 byte blocks.
00919         """
00920         buf = ""
00921         type = self.type
00922         prefix = ""
00923 
00924         if self.name.endswith("/"):
00925             type = DIRTYPE
00926 
00927         if type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK):
00928             # Prevent "././@LongLink" from being normalized.
00929             name = self.name
00930         else:
00931             name = normpath(self.name)
00932 
00933         if type == DIRTYPE:
00934             # directories should end with '/'
00935             name += "/"
00936 
00937         linkname = self.linkname
00938         if linkname:
00939             # if linkname is empty we end up with a '.'
00940             linkname = normpath(linkname)
00941 
00942         if posix:
00943             if self.size > MAXSIZE_MEMBER:
00944                 raise ValueError("file is too large (>= 8 GB)")
00945 
00946             if len(self.linkname) > LENGTH_LINK:
00947                 raise ValueError("linkname is too long (>%d)" % (LENGTH_LINK))
00948 
00949             if len(name) > LENGTH_NAME:
00950                 prefix = name[:LENGTH_PREFIX + 1]
00951                 while prefix and prefix[-1] != "/":
00952                     prefix = prefix[:-1]
00953 
00954                 name = name[len(prefix):]
00955                 prefix = prefix[:-1]
00956 
00957                 if not prefix or len(name) > LENGTH_NAME:
00958                     raise ValueError("name is too long")
00959 
00960         else:
00961             if len(self.linkname) > LENGTH_LINK:
00962                 buf += self._create_gnulong(self.linkname, GNUTYPE_LONGLINK)
00963 
00964             if len(name) > LENGTH_NAME:
00965                 buf += self._create_gnulong(name, GNUTYPE_LONGNAME)
00966 
00967         parts = [
00968             stn(name, 100),
00969             itn(self.mode & 07777, 8, posix),
00970             itn(self.uid, 8, posix),
00971             itn(self.gid, 8, posix),
00972             itn(self.size, 12, posix),
00973             itn(self.mtime, 12, posix),
00974             "        ", # checksum field
00975             type,
00976             stn(self.linkname, 100),
00977             stn(MAGIC, 6),
00978             stn(VERSION, 2),
00979             stn(self.uname, 32),
00980             stn(self.gname, 32),
00981             itn(self.devmajor, 8, posix),
00982             itn(self.devminor, 8, posix),
00983             stn(prefix, 155)
00984         ]
00985 
00986         buf += "".join(parts).ljust(BLOCKSIZE, NUL)
00987         chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
00988         buf = buf[:-364] + "%06o\0" % chksum + buf[-357:]
00989         self.buf = buf
00990         return buf

Here is the call graph for this function:


Member Data Documentation

Definition at line 988 of file tarfile.py.

Definition at line 869 of file tarfile.py.

Definition at line 874 of file tarfile.py.

Definition at line 875 of file tarfile.py.

tuple MoinMoin.support.tarfile.TarInfo.frombuf = classmethod(frombuf) [static]

Definition at line 914 of file tarfile.py.

Definition at line 866 of file tarfile.py.

Definition at line 873 of file tarfile.py.

Definition at line 871 of file tarfile.py.

Definition at line 864 of file tarfile.py.

Definition at line 868 of file tarfile.py.

Definition at line 863 of file tarfile.py.

Definition at line 877 of file tarfile.py.

Definition at line 878 of file tarfile.py.

Definition at line 867 of file tarfile.py.

Definition at line 870 of file tarfile.py.

Definition at line 865 of file tarfile.py.

Definition at line 872 of file tarfile.py.


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