Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.File.UndoHandle Class Reference

List of all members.

Public Member Functions

def __init__
def __iter__
def next
def readlines
def readline
def read
def saveline
def peekline
def tell
def seek
def __getattr__
def __enter__
def __exit__

Private Attributes

 _handle
 _saved

Detailed Description

A Python handle that adds functionality for saving lines.

Saves lines in a LIFO fashion.

Added methods:
saveline    Save a line to be returned next time.
peekline    Peek at the next line without consuming it.

Definition at line 62 of file File.py.


Constructor & Destructor Documentation

def Bio.File.UndoHandle.__init__ (   self,
  handle 
)

Definition at line 72 of file File.py.

00072 
00073     def __init__(self, handle):
00074         self._handle = handle
00075         self._saved = []

Here is the caller graph for this function:


Member Function Documentation

Definition at line 137 of file File.py.

00137 
00138     def __enter__(self):
00139         return self

def Bio.File.UndoHandle.__exit__ (   self,
  type,
  value,
  traceback 
)

Definition at line 140 of file File.py.

00140 
00141     def __exit__(self, type, value, traceback):
00142         self._handle.close()
00143 
00144 
00145 # I could make this faster by using cStringIO.
00146 # However, cStringIO (in v1.52) does not implement the
# readlines method.
def Bio.File.UndoHandle.__getattr__ (   self,
  attr 
)

Definition at line 134 of file File.py.

00134 
00135     def __getattr__(self, attr):
00136         return getattr(self._handle, attr)

Definition at line 76 of file File.py.

00076 
00077     def __iter__(self):
00078         return self

Here is the caller graph for this function:

def Bio.File.UndoHandle.next (   self)

Definition at line 79 of file File.py.

00079 
00080     def next(self):
00081         next = self.readline()
00082         if not next:
00083             raise StopIteration
00084         return next

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 117 of file File.py.

00117 
00118     def peekline(self):
00119         if self._saved:
00120             line = self._saved[0]
00121         else:
00122             line = self._handle.readline()
00123             self.saveline(line)
00124         return line

Here is the call graph for this function:

def Bio.File.UndoHandle.read (   self,
  size = -1 
)

Definition at line 97 of file File.py.

00097 
00098     def read(self, size=-1):
00099         if size == -1:
00100             saved = "".join(self._saved)
00101             self._saved[:] = []
00102         else:
00103             saved = ''
00104             while size > 0 and self._saved:
00105                 if len(self._saved[0]) <= size:
00106                     size = size - len(self._saved[0])
00107                     saved = saved + self._saved.pop(0)
00108                 else:
00109                     saved = saved + self._saved[0][:size]
00110                     self._saved[0] = self._saved[0][size:]
00111                     size = 0
00112         return saved + self._handle.read(size)

def Bio.File.UndoHandle.readline (   self,
  args,
  keywds 
)

Definition at line 90 of file File.py.

00090 
00091     def readline(self, *args, **keywds):
00092         if self._saved:
00093             line = self._saved.pop(0)
00094         else:
00095             line = self._handle.readline(*args,**keywds)
00096         return line

Here is the caller graph for this function:

def Bio.File.UndoHandle.readlines (   self,
  args,
  keywds 
)

Definition at line 85 of file File.py.

00085 
00086     def readlines(self, *args, **keywds):
00087         lines = self._saved + self._handle.readlines(*args,**keywds)
00088         self._saved = []
00089         return lines

def Bio.File.UndoHandle.saveline (   self,
  line 
)

Definition at line 113 of file File.py.

00113 
00114     def saveline(self, line):
00115         if line:
00116             self._saved = [line] + self._saved

Here is the caller graph for this function:

def Bio.File.UndoHandle.seek (   self,
  args 
)

Definition at line 130 of file File.py.

00130 
00131     def seek(self, *args):
00132         self._saved = []
00133         self._handle.seek(*args)

def Bio.File.UndoHandle.tell (   self)

Definition at line 125 of file File.py.

00125 
00126     def tell(self):
00127         lengths = map(len, self._saved)
00128         sum = reduce(lambda x, y: x+y, lengths, 0)
00129         return self._handle.tell() - sum


Member Data Documentation

Definition at line 73 of file File.py.

Definition at line 74 of file File.py.


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