def gettarinfo(self, name=None, arcname=None, fileobj=None):
self._check("<STR_LIT>")<EOL>if fileobj is not None:<EOL><INDENT>name = fileobj.name<EOL><DEDENT>if arcname is None:<EOL><INDENT>arcname = name<EOL><DEDENT>drv, arcname = os.path.splitdrive(arcname)<EOL>arcname = arcname.replace(os.sep, "<STR_LIT:/>")<EOL>arcname = arcname.lstrip("<STR_LIT:/>")<EOL>tarinfo = self.tarinfo()<EOL>tarinfo.tarfile = self<EOL>if fileobj is None:<EOL><INDENT>if hasattr(os, "<STR_LIT>") and not self.dereference:<EOL><INDENT>statres = os.lstat(name)<EOL><DEDENT>else:<EOL><INDENT>statres = os.stat(name)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>statres = os.fstat(fileobj.fileno())<EOL><DEDENT>linkname = "<STR_LIT>"<EOL>stmd = statres.st_mode<EOL>if stat.S_ISREG(stmd):<EOL><INDENT>inode = (statres.st_ino, statres.st_dev)<EOL>if not self.dereference and statres.st_nlink > <NUM_LIT:1> andinode in self.inodes and arcname != self.inodes[inode]:<EOL><INDENT>type = LNKTYPE<EOL>linkname = self.inodes[inode]<EOL><DEDENT>else:<EOL><INDENT>type = REGTYPE<EOL>if inode[<NUM_LIT:0>]:<EOL><INDENT>self.inodes[inode] = arcname<EOL><DEDENT><DEDENT><DEDENT>elif stat.S_ISDIR(stmd):<EOL><INDENT>type = DIRTYPE<EOL><DEDENT>elif stat.S_ISFIFO(stmd):<EOL><INDENT>type = FIFOTYPE<EOL><DEDENT>elif stat.S_ISLNK(stmd):<EOL><INDENT>type = SYMTYPE<EOL>linkname = os.readlink(name)<EOL><DEDENT>elif stat.S_ISCHR(stmd):<EOL><INDENT>type = CHRTYPE<EOL><DEDENT>elif stat.S_ISBLK(stmd):<EOL><INDENT>type = BLKTYPE<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>tarinfo.name = arcname<EOL>tarinfo.mode = stmd<EOL>tarinfo.uid = statres.st_uid<EOL>tarinfo.gid = statres.st_gid<EOL>if type == REGTYPE:<EOL><INDENT>tarinfo.size = statres.st_size<EOL><DEDENT>else:<EOL><INDENT>tarinfo.size = <NUM_LIT:0><EOL><DEDENT>tarinfo.mtime = statres.st_mtime<EOL>tarinfo.type = type<EOL>tarinfo.linkname = linkname<EOL>if pwd:<EOL><INDENT>try:<EOL><INDENT>tarinfo.uname = pwd.getpwuid(tarinfo.uid)[<NUM_LIT:0>]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if grp:<EOL><INDENT>try:<EOL><INDENT>tarinfo.gname = grp.getgrgid(tarinfo.gid)[<NUM_LIT:0>]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if type in (CHRTYPE, BLKTYPE):<EOL><INDENT>if hasattr(os, "<STR_LIT>") and hasattr(os, "<STR_LIT>"):<EOL><INDENT>tarinfo.devmajor = os.major(statres.st_rdev)<EOL>tarinfo.devminor = os.minor(statres.st_rdev)<EOL><DEDENT><DEDENT>return tarinfo<EOL>
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.