Back to index

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

List of all members.

Public Member Functions

def __init__
def read
def readline
def readlines
def tell
def seek
def close
def __iter__

Public Attributes

 fileobj
 name
 mode
 closed
 size
 position
 buffer

Static Public Attributes

int blocksize = 1024

Detailed Description

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

Definition at line 720 of file tarfile.py.


Constructor & Destructor Documentation

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

Definition at line 726 of file tarfile.py.

00726 
00727     def __init__(self, tarfile, tarinfo):
00728         self.fileobj = _FileInFile(tarfile.fileobj,
00729                                    tarinfo.offset_data,
00730                                    tarinfo.size,
00731                                    getattr(tarinfo, "sparse", None))
00732         self.name = tarinfo.name
00733         self.mode = "r"
00734         self.closed = False
00735         self.size = tarinfo.size
00736 
00737         self.position = 0
00738         self.buffer = ""


Member Function Documentation

Get an iterator over the file's lines.

Definition at line 838 of file tarfile.py.

00838 
00839     def __iter__(self):
00840         """Get an iterator over the file's lines.
00841         """
00842         while True:
00843             line = self.readline()
00844             if not line:
00845                 break
00846             yield line
00847 #class ExFileObject
00848 
00849 #------------------
00850 # Exported Classes
#------------------

Here is the call graph for this function:

Close the file object.

Definition at line 833 of file tarfile.py.

00833 
00834     def close(self):
00835         """Close the file object.
00836         """
00837         self.closed = True

Here is the caller graph for this function:

def MoinMoin.support.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 739 of file tarfile.py.

00739 
00740     def read(self, size=None):
00741         """Read at most size bytes from the file. If size is not
00742            present or None, read all data until EOF is reached.
00743         """
00744         if self.closed:
00745             raise ValueError("I/O operation on closed file")
00746 
00747         buf = ""
00748         if self.buffer:
00749             if size is None:
00750                 buf = self.buffer
00751                 self.buffer = ""
00752             else:
00753                 buf = self.buffer[:size]
00754                 self.buffer = self.buffer[size:]
00755 
00756         if size is None:
00757             buf += self.fileobj.read()
00758         else:
00759             buf += self.fileobj.read(size - len(buf))
00760 
00761         self.position += len(buf)
00762         return buf

Here is the caller graph for this function:

def MoinMoin.support.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 763 of file tarfile.py.

00763 
00764     def readline(self, size=-1):
00765         """Read one entire line from the file. If size is present
00766            and non-negative, return a string with at most that
00767            size, which may be an incomplete line.
00768         """
00769         if self.closed:
00770             raise ValueError("I/O operation on closed file")
00771 
00772         if "\n" in self.buffer:
00773             pos = self.buffer.find("\n") + 1
00774         else:
00775             buffers = [self.buffer]
00776             while True:
00777                 buf = self.fileobj.read(self.blocksize)
00778                 buffers.append(buf)
00779                 if not buf or "\n" in buf:
00780                     self.buffer = "".join(buffers)
00781                     pos = self.buffer.find("\n") + 1
00782                     if pos == 0:
00783                         # no newline found.
00784                         pos = len(self.buffer)
00785                     break
00786 
00787         if size != -1:
00788             pos = min(size, pos)
00789 
00790         buf = self.buffer[:pos]
00791         self.buffer = self.buffer[pos:]
00792         self.position += len(buf)
00793         return buf

Here is the caller graph for this function:

Return a list with all remaining lines.

Definition at line 794 of file tarfile.py.

00794 
00795     def readlines(self):
00796         """Return a list with all remaining lines.
00797         """
00798         result = []
00799         while True:
00800             line = self.readline()
00801             if not line: break
00802             result.append(line)
00803         return result

Here is the call graph for this function:

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

Definition at line 812 of file tarfile.py.

00812 
00813     def seek(self, pos, whence=os.SEEK_SET):
00814         """Seek to a position in the file.
00815         """
00816         if self.closed:
00817             raise ValueError("I/O operation on closed file")
00818 
00819         if whence == os.SEEK_SET:
00820             self.position = min(max(pos, 0), self.size)
00821         elif whence == os.SEEK_CUR:
00822             if pos < 0:
00823                 self.position = max(self.position + pos, 0)
00824             else:
00825                 self.position = min(self.position + pos, self.size)
00826         elif whence == os.SEEK_END:
00827             self.position = max(min(self.size + pos, self.size), 0)
00828         else:
00829             raise ValueError("Invalid argument")
00830 
00831         self.buffer = ""
00832         self.fileobj.seek(self.position)

Return the current file position.

Definition at line 804 of file tarfile.py.

00804 
00805     def tell(self):
00806         """Return the current file position.
00807         """
00808         if self.closed:
00809             raise ValueError("I/O operation on closed file")
00810 
00811         return self.position


Member Data Documentation

Definition at line 724 of file tarfile.py.

Definition at line 737 of file tarfile.py.

Definition at line 733 of file tarfile.py.

Definition at line 727 of file tarfile.py.

Definition at line 732 of file tarfile.py.

Definition at line 731 of file tarfile.py.

Definition at line 736 of file tarfile.py.

Definition at line 734 of file tarfile.py.


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