Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
MoinMoin.support.flup.server.ajp_base.InputStream Class Reference

List of all members.

Public Member Functions

def __init__
def bytesAvailForAdd
def read
def readline
def readlines
def __iter__
def next
def setDataLength
def addData

Public Attributes

 logger

Private Member Functions

def _shrinkBuffer
def _waitForData

Private Attributes

 _conn
 _shrinkThreshold
 _buf
 _bufList
 _pos
 _avail
 _length

Detailed Description

File-like object that represents the request body (if any). Supports
the bare mininum methods required by the WSGI spec. Thanks to
StringIO for ideas.

Definition at line 315 of file ajp_base.py.


Constructor & Destructor Documentation

Definition at line 321 of file ajp_base.py.

00321 
00322     def __init__(self, conn):
00323         self._conn = conn
00324 
00325         # See WSGIServer.
00326         self._shrinkThreshold = conn.server.inputStreamShrinkThreshold
00327 
00328         self._buf = ''
00329         self._bufList = []
00330         self._pos = 0 # Current read position.
00331         self._avail = 0 # Number of bytes currently available.
00332         self._length = 0 # Set to Content-Length in request.
00333 
00334         self.logger = logging.getLogger(LoggerName)


Member Function Documentation

Definition at line 426 of file ajp_base.py.

00426 
00427     def __iter__(self):
00428         return self

Gets rid of already read data (since we can't rewind).

Definition at line 338 of file ajp_base.py.

00338 
00339     def _shrinkBuffer(self):
00340         """Gets rid of already read data (since we can't rewind)."""
00341         if self._pos >= self._shrinkThreshold:
00342             self._buf = self._buf[self._pos:]
00343             self._avail -= self._pos
00344             self._length -= self._pos
00345             self._pos = 0
00346 
00347             assert self._avail >= 0 and self._length >= 0

Here is the caller graph for this function:

Definition at line 348 of file ajp_base.py.

00348 
00349     def _waitForData(self):
00350         toAdd = min(self.bytesAvailForAdd(), 0xffff)
00351         assert toAdd > 0
00352         pkt = Packet()
00353         pkt.data = PKTTYPE_GET_BODY + \
00354                    struct.pack('>H', toAdd)
00355         self._conn.writePacket(pkt)
00356         self._conn.processInput()

Here is the call graph for this function:

Here is the caller graph for this function:

Adds data from the server to this InputStream. Note that we never ask
the server for data beyond the Content-Length, so the server should
never send us an EOF (empty string argument).

Definition at line 441 of file ajp_base.py.

00441 
00442     def addData(self, data):
00443         """
00444         Adds data from the server to this InputStream. Note that we never ask
00445         the server for data beyond the Content-Length, so the server should
00446         never send us an EOF (empty string argument).
00447         """
00448         if not data:
00449             raise ProtocolError, 'short data'
00450         self._bufList.append(data)
00451         length = len(data)
00452         self._avail += length
00453         if self._avail > self._length:
00454             raise ProtocolError, 'too much data'

Definition at line 335 of file ajp_base.py.

00335 
00336     def bytesAvailForAdd(self):
00337         return self._length - self._avail

Here is the caller graph for this function:

Definition at line 429 of file ajp_base.py.

00429 
00430     def next(self):
00431         r = self.readline()
00432         if not r:
00433             raise StopIteration
00434         return r

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 357 of file ajp_base.py.

00357 
00358     def read(self, n=-1):
00359         if self._pos == self._length:
00360             return ''
00361         while True:
00362             if n < 0 or (self._avail - self._pos) < n:
00363                 # Not enough data available.
00364                 if not self.bytesAvailForAdd():
00365                     # And there's no more coming.
00366                     newPos = self._avail
00367                     break
00368                 else:
00369                     # Ask for more data and wait.
00370                     self._waitForData()
00371                     continue
00372             else:
00373                 newPos = self._pos + n
00374                 break
00375         # Merge buffer list, if necessary.
00376         if self._bufList:
00377             self._buf += ''.join(self._bufList)
00378             self._bufList = []
00379         r = self._buf[self._pos:newPos]
00380         self._pos = newPos
00381         self._shrinkBuffer()
00382         return r

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 383 of file ajp_base.py.

00383 
00384     def readline(self, length=None):
00385         if self._pos == self._length:
00386             return ''
00387         while True:
00388             # Unfortunately, we need to merge the buffer list early.
00389             if self._bufList:
00390                 self._buf += ''.join(self._bufList)
00391                 self._bufList = []
00392             # Find newline.
00393             i = self._buf.find('\n', self._pos)
00394             if i < 0:
00395                 # Not found?
00396                 if not self.bytesAvailForAdd():
00397                     # No more data coming.
00398                     newPos = self._avail
00399                     break
00400                 else:
00401                     if length is not None and len(self._buf) >= length + self._pos:
00402                         newPos = self._pos + length
00403                         break
00404                     # Wait for more to come.
00405                     self._waitForData()
00406                     continue
00407             else:
00408                 newPos = i + 1
00409                 break
00410         r = self._buf[self._pos:newPos]
00411         self._pos = newPos
00412         self._shrinkBuffer()
00413         return r

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 414 of file ajp_base.py.

00414 
00415     def readlines(self, sizehint=0):
00416         total = 0
00417         lines = []
00418         line = self.readline()
00419         while line:
00420             lines.append(line)
00421             total += len(line)
00422             if 0 < sizehint <= total:
00423                 break
00424             line = self.readline()
00425         return lines

Here is the call graph for this function:

Once Content-Length is known, Request calls this method to set it.

Definition at line 435 of file ajp_base.py.

00435 
00436     def setDataLength(self, length):
00437         """
00438         Once Content-Length is known, Request calls this method to set it.
00439         """
00440         self._length = length


Member Data Documentation

Definition at line 330 of file ajp_base.py.

Definition at line 327 of file ajp_base.py.

Definition at line 328 of file ajp_base.py.

Definition at line 322 of file ajp_base.py.

Definition at line 331 of file ajp_base.py.

Definition at line 329 of file ajp_base.py.

Definition at line 325 of file ajp_base.py.

Definition at line 333 of file ajp_base.py.


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