Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
tarfile.ExFileObject Class Reference
Inheritance diagram for tarfile.ExFileObject:
Inheritance graph
[legend]
Collaboration diagram for tarfile.ExFileObject:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def readable
def writable
def seekable
def read
def readline
def readlines
def tell
def seek
def close
def __iter__

Public Attributes

 fileobj
 name
 mode
 closed
 size
 position
 buffer
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

int blocksize = 1024
 read1 = read

Detailed Description

File-like object for reading an archive member.
   Is returned by TarFile.extractfile().

Definition at line 773 of file tarfile.py.


Constructor & Destructor Documentation

def tarfile.ExFileObject.__init__ (   self,
  tarfile,
  tarinfo 
)

Definition at line 779 of file tarfile.py.

00779 
00780     def __init__(self, tarfile, tarinfo):
00781         self.fileobj = _FileInFile(tarfile.fileobj,
00782                                    tarinfo.offset_data,
00783                                    tarinfo.size,
00784                                    tarinfo.sparse)
00785         self.name = tarinfo.name
00786         self.mode = "r"
00787         self.closed = False
00788         self.size = tarinfo.size
00789 
00790         self.position = 0
00791         self.buffer = b""

Here is the caller graph for this function:


Member Function Documentation

Get an iterator over the file's lines.

Definition at line 901 of file tarfile.py.

00901 
00902     def __iter__(self):
00903         """Get an iterator over the file's lines.
00904         """
00905         while True:
00906             line = self.readline()
00907             if not line:
00908                 break
00909             yield line
00910 #class ExFileObject
00911 
00912 #------------------
00913 # Exported Classes
#------------------

Here is the call graph for this function:

Close the file object.

Definition at line 896 of file tarfile.py.

00896 
00897     def close(self):
00898         """Close the file object.
00899         """
00900         self.closed = True

Here is the caller graph for this function:

def tarfile.ExFileObject.read (   self,
  size = None 
)
Read at most size bytes from the file. If size is not
   present or None, read all data until EOF is reached.

Definition at line 801 of file tarfile.py.

00801 
00802     def read(self, size=None):
00803         """Read at most size bytes from the file. If size is not
00804            present or None, read all data until EOF is reached.
00805         """
00806         if self.closed:
00807             raise ValueError("I/O operation on closed file")
00808 
00809         buf = b""
00810         if self.buffer:
00811             if size is None:
00812                 buf = self.buffer
00813                 self.buffer = b""
00814             else:
00815                 buf = self.buffer[:size]
00816                 self.buffer = self.buffer[size:]
00817 
00818         if size is None:
00819             buf += self.fileobj.read()
00820         else:
00821             buf += self.fileobj.read(size - len(buf))
00822 
00823         self.position += len(buf)
00824         return buf

Here is the caller graph for this function:

Definition at line 792 of file tarfile.py.

00792 
00793     def readable(self):
00794         return True

def tarfile.ExFileObject.readline (   self,
  size = -1 
)
Read one entire line from the file. If size is present
   and non-negative, return a string with at most that
   size, which may be an incomplete line.

Definition at line 828 of file tarfile.py.

00828 
00829     def readline(self, size=-1):
00830         """Read one entire line from the file. If size is present
00831            and non-negative, return a string with at most that
00832            size, which may be an incomplete line.
00833         """
00834         if self.closed:
00835             raise ValueError("I/O operation on closed file")
00836 
00837         pos = self.buffer.find(b"\n") + 1
00838         if pos == 0:
00839             # no newline found.
00840             while True:
00841                 buf = self.fileobj.read(self.blocksize)
00842                 self.buffer += buf
00843                 if not buf or b"\n" in buf:
00844                     pos = self.buffer.find(b"\n") + 1
00845                     if pos == 0:
00846                         # no newline found.
00847                         pos = len(self.buffer)
00848                     break
00849 
00850         if size != -1:
00851             pos = min(size, pos)
00852 
00853         buf = self.buffer[:pos]
00854         self.buffer = self.buffer[pos:]
00855         self.position += len(buf)
00856         return buf

Here is the caller graph for this function:

Return a list with all remaining lines.

Definition at line 857 of file tarfile.py.

00857 
00858     def readlines(self):
00859         """Return a list with all remaining lines.
00860         """
00861         result = []
00862         while True:
00863             line = self.readline()
00864             if not line: break
00865             result.append(line)
00866         return result

Here is the call graph for this function:

def tarfile.ExFileObject.seek (   self,
  pos,
  whence = os.SEEK_SET 
)
Seek to a position in the file.

Definition at line 875 of file tarfile.py.

00875 
00876     def seek(self, pos, whence=os.SEEK_SET):
00877         """Seek to a position in the file.
00878         """
00879         if self.closed:
00880             raise ValueError("I/O operation on closed file")
00881 
00882         if whence == os.SEEK_SET:
00883             self.position = min(max(pos, 0), self.size)
00884         elif whence == os.SEEK_CUR:
00885             if pos < 0:
00886                 self.position = max(self.position + pos, 0)
00887             else:
00888                 self.position = min(self.position + pos, self.size)
00889         elif whence == os.SEEK_END:
00890             self.position = max(min(self.size + pos, self.size), 0)
00891         else:
00892             raise ValueError("Invalid argument")
00893 
00894         self.buffer = b""
00895         self.fileobj.seek(self.position)

Here is the caller graph for this function:

Definition at line 798 of file tarfile.py.

00798 
00799     def seekable(self):
00800         return self.fileobj.seekable()

def tarfile.ExFileObject.tell (   self)
Return the current file position.

Definition at line 867 of file tarfile.py.

00867 
00868     def tell(self):
00869         """Return the current file position.
00870         """
00871         if self.closed:
00872             raise ValueError("I/O operation on closed file")
00873 
00874         return self.position

Definition at line 795 of file tarfile.py.

00795 
00796     def writable(self):
00797         return False


Member Data Documentation

Definition at line 777 of file tarfile.py.

Definition at line 790 of file tarfile.py.

Definition at line 786 of file tarfile.py.

Definition at line 780 of file tarfile.py.

Definition at line 785 of file tarfile.py.

Definition at line 784 of file tarfile.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 789 of file tarfile.py.

Definition at line 826 of file tarfile.py.

Definition at line 787 of file tarfile.py.


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