Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes
MoinMoin.support.werkzeug.contrib.iterio.IterO Class Reference
Inheritance diagram for MoinMoin.support.werkzeug.contrib.iterio.IterO:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.werkzeug.contrib.iterio.IterO:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __new__
def __init__
def __iter__
def close
def seek
def read
def readline
def readlines
def tell
def isatty
def truncate
def write
def writelines
def flush
def next

Public Attributes

 closed
 pos

Private Attributes

 _gen
 _buf

Detailed Description

Iter output.  Wrap an iterator and give it a stream like interface.

Definition at line 170 of file iterio.py.


Constructor & Destructor Documentation

Definition at line 176 of file iterio.py.

00176 
00177     def __init__(self, gen):
00178         self._gen = gen
00179         self._buf = ''
00180         self.closed = False
00181         self.pos = 0


Member Function Documentation

Reimplemented from MoinMoin.support.werkzeug.contrib.iterio.IterIO.

Definition at line 182 of file iterio.py.

00182 
00183     def __iter__(self):
00184         return self

Reimplemented from MoinMoin.support.werkzeug.contrib.iterio.IterIO.

Definition at line 173 of file iterio.py.

00173 
00174     def __new__(cls, gen):
00175         return object.__new__(cls)

Definition at line 185 of file iterio.py.

00185 
00186     def close(self):
00187         if not self.closed:
00188             self.closed = True
00189             if hasattr(self._gen, 'close'):
00190                 self._gen.close()

Here is the caller graph for this function:

Reimplemented in MoinMoin.support.werkzeug.contrib.iterio.IterI.

Definition at line 109 of file iterio.py.

00109 
00110     def flush(self):
00111         if self.closed:
00112             raise ValueError('I/O operation on closed file')
00113         raise IOError(9, 'Bad file descriptor')

Here is the caller graph for this function:

Definition at line 69 of file iterio.py.

00069 
00070     def isatty(self):
00071         if self.closed:
00072             raise ValueError('I/O operation on closed file')
00073         return False

Definition at line 114 of file iterio.py.

00114 
00115     def next(self):
00116         if self.closed:
00117             raise StopIteration()
00118         line = self.readline()
00119         if not line:
00120             raise StopIteration()
00121         return line
00122 

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from MoinMoin.support.werkzeug.contrib.iterio.IterIO.

Definition at line 215 of file iterio.py.

00215 
00216     def read(self, n=-1):
00217         if self.closed:
00218             raise ValueError('I/O operation on closed file')
00219         if n < 0:
00220             self._buf += ''.join(self._gen)
00221             result = self._buf[self.pos:]
00222             self.pos += len(result)
00223             return result
00224         new_pos = self.pos + n
00225         buf = []
00226         try:
00227             tmp_end_pos = len(self._buf)
00228             while new_pos > tmp_end_pos:
00229                 item = self._gen.next()
00230                 tmp_end_pos += len(item)
00231                 buf.append(item)
00232         except StopIteration:
00233             pass
00234         if buf:
00235             self._buf += ''.join(buf)
00236         new_pos = max(0, new_pos)
00237         try:
00238             return self._buf[self.pos:new_pos]
00239         finally:
00240             self.pos = min(new_pos, len(self._buf))

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.contrib.iterio.IterO.readline (   self,
  length = None 
)

Reimplemented from MoinMoin.support.werkzeug.contrib.iterio.IterIO.

Definition at line 241 of file iterio.py.

00241 
00242     def readline(self, length=None):
00243         if self.closed:
00244             raise ValueError('I/O operation on closed file')
00245         nl_pos = self._buf.find('\n', self.pos)
00246         buf = []
00247         try:
00248             pos = self.pos
00249             while nl_pos < 0:
00250                 item = self._gen.next()
00251                 local_pos = item.find('\n')
00252                 buf.append(item)
00253                 if local_pos >= 0:
00254                     nl_pos = pos + local_pos
00255                     break
00256                 pos += len(item)
00257         except StopIteration:
00258             pass
00259         if buf:
00260             self._buf += ''.join(buf)
00261         if nl_pos < 0:
00262             new_pos = len(self._buf)
00263         else:
00264             new_pos = nl_pos + 1
00265         if length is not None and self.pos + length < new_pos:
00266             new_pos = self.pos + length
00267         try:
00268             return self._buf[self.pos:new_pos]
00269         finally:
00270             self.pos = min(new_pos, len(self._buf))

Here is the caller graph for this function:

Reimplemented from MoinMoin.support.werkzeug.contrib.iterio.IterIO.

Definition at line 271 of file iterio.py.

00271 
00272     def readlines(self, sizehint=0):
00273         total = 0
00274         lines = []
00275         line = self.readline()
00276         while line:
00277             lines.append(line)
00278             total += len(line)
00279             if 0 < sizehint <= total:
00280                 break
00281             line = self.readline()
00282         return lines

Here is the call graph for this function:

def MoinMoin.support.werkzeug.contrib.iterio.IterO.seek (   self,
  pos,
  mode = 0 
)

Reimplemented from MoinMoin.support.werkzeug.contrib.iterio.IterIO.

Definition at line 191 of file iterio.py.

00191 
00192     def seek(self, pos, mode=0):
00193         if self.closed:
00194             raise ValueError('I/O operation on closed file')
00195         if mode == 1:
00196             pos += self.pos
00197         elif mode == 2:
00198             self.read()
00199             self.pos = min(self.pos, self.pos + pos)
00200             return
00201         elif mode != 0:
00202             raise IOError('Invalid argument')
00203         buf = []
00204         try:
00205             tmp_end_pos = len(self._buf)
00206             while pos > tmp_end_pos:
00207                 item = self._gen.next()
00208                 tmp_end_pos += len(item)
00209                 buf.append(item)
00210         except StopIteration:
00211             pass
00212         if buf:
00213             self._buf += ''.join(buf)
00214         self.pos = max(0, pos)

Definition at line 64 of file iterio.py.

00064 
00065     def tell(self):
00066         if self.closed:
00067             raise ValueError('I/O operation on closed file')
00068         return self.pos

def MoinMoin.support.werkzeug.contrib.iterio.IterIO.truncate (   self,
  size = None 
) [inherited]

Definition at line 79 of file iterio.py.

00079 
00080     def truncate(self, size=None):
00081         if self.closed:
00082             raise ValueError('I/O operation on closed file')
00083         raise IOError(9, 'Bad file descriptor')

def MoinMoin.support.werkzeug.contrib.iterio.IterIO.write (   self,
  s 
) [inherited]

Reimplemented in MoinMoin.support.werkzeug.contrib.iterio.IterI.

Definition at line 84 of file iterio.py.

00084 
00085     def write(self, s):
00086         if self.closed:
00087             raise ValueError('I/O operation on closed file')
00088         raise IOError(9, 'Bad file descriptor')

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.contrib.iterio.IterIO.writelines (   self,
  list 
) [inherited]

Reimplemented in MoinMoin.support.werkzeug.contrib.iterio.IterI.

Definition at line 89 of file iterio.py.

00089 
00090     def writelines(self, list):
00091         if self.closed:
00092             raise ValueError('I/O operation on closed file')
00093         raise IOError(9, 'Bad file descriptor')


Member Data Documentation

Definition at line 178 of file iterio.py.

Definition at line 177 of file iterio.py.

Definition at line 179 of file iterio.py.

Definition at line 180 of file iterio.py.


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