Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes
MoinMoin.support.werkzeug.contrib.reporterstream.BaseReporterStream Class Reference

List of all members.

Public Member Functions

def __init__
def processed
def read
def readline
def readlines

Public Attributes

 threshold
 length
 pos
 environ

Private Attributes

 _stream

Detailed Description

This class can be used to wrap `wsgi.input` in order to be informed about
changes of the stream.

Usage::

    from random import randrange

    class ReporterStream(BaseReporterStream):

        def __init__(self, environ):
            super(ReporterStream, self).__init__(environ, 1024 * 16)
            self.transport_id = randrange(0, 100000)

        def processed(self):
            s = self.environ['my.session.service']
            s.store['upload/%s' % self.transport_id] = (self.pos, self.length)
            s.flush()


And before accessing `request.form` or similar attributes add the stream:

    stream = ReporterStream(environ)
    environ['wsgi.input'] = stream

Definition at line 20 of file reporterstream.py.


Constructor & Destructor Documentation

Definition at line 47 of file reporterstream.py.

00047 
00048     def __init__(self, environ, threshold):
00049         self.threshold = threshold
00050         self.length = int(environ.get('CONTENT_LENGTH') or 0)
00051         self.pos = 0
00052         self.environ = environ
00053         self._stream = environ['wsgi.input']


Member Function Documentation

Called after pos has changed for threshold or a line was read.

Definition at line 54 of file reporterstream.py.

00054 
00055     def processed(self):
00056         """Called after pos has changed for threshold or a line was read."""

Here is the caller graph for this function:

Definition at line 57 of file reporterstream.py.

00057 
00058     def read(self, size=None):
00059         length = self.length
00060         threshold = self.threshold
00061         buffer = []
00062 
00063         if size is None:
00064             while self.pos < length:
00065                 step = min(threshold, length - self.pos)
00066                 data = self._stream.read(step)
00067                 self.pos += step
00068                 self.processed()
00069                 buffer.append(data)
00070         else:
00071             read = 0
00072             while read < size:
00073                 step = min(threshold, length - self.pos)
00074                 step = min(step, size)
00075                 data = self._stream.read(step)
00076                 self.pos += step
00077                 read += step
00078                 self.processed()
00079                 buffer.append(data)
00080 
00081         return ''.join(buffer)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 82 of file reporterstream.py.

00082 
00083     def readline(self, *args):
00084         line = self._stream.readline(*args)
00085         self.pos += len(line)
00086         self.processed()
00087         return line

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 88 of file reporterstream.py.

00088 
00089     def readlines(self, hint=None):
00090         result = []
00091         while self.pos < self.length:
00092             result.append(self.readline())
00093         return result

Here is the call graph for this function:


Member Data Documentation

Definition at line 52 of file reporterstream.py.

Definition at line 51 of file reporterstream.py.

Definition at line 49 of file reporterstream.py.

Definition at line 50 of file reporterstream.py.

Definition at line 48 of file reporterstream.py.


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