Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.flup.server.scgi_base Namespace Reference

Classes

class  ProtocolError
class  StdoutWrapper
class  Request
class  Connection
class  BaseSCGIServer

Functions

def recvall
def readNetstring

Variables

string __author__ = 'Allan Saddi <allan@saddi.com>'
string __version__ = '$Revision$'
list __all__ = ['BaseSCGIServer']
string LoggerName = 'scgi-wsgi'
tuple console = logging.StreamHandler()

Class Documentation

class MoinMoin::support::flup::server::scgi_base::ProtocolError
Exception raised when the server does something unexpected or
sends garbled data. Usually leads to a Connection closing.

Definition at line 61 of file scgi_base.py.


Function Documentation

Attempt to read a netstring from a socket.

Definition at line 92 of file scgi_base.py.

00092 
00093 def readNetstring(sock):
00094     """
00095     Attempt to read a netstring from a socket.
00096     """
00097     # First attempt to read the length.
00098     size = ''
00099     while True:
00100         try:
00101             c = sock.recv(1)
00102         except socket.error, e:
00103             if e[0] == errno.EAGAIN:
00104                 select.select([sock], [], [])
00105                 continue
00106             else:
00107                 raise
00108         if c == ':':
00109             break
00110         if not c:
00111             raise EOFError
00112         size += c
00113 
00114     # Try to decode the length.
00115     try:
00116         size = int(size)
00117         if size < 0:
00118             raise ValueError
00119     except ValueError:
00120         raise ProtocolError, 'invalid netstring length'
00121 
00122     # Now read the string.
00123     s, length = recvall(sock, size)
00124 
00125     if length < size:
00126         raise EOFError
00127 
00128     # Lastly, the trailer.
00129     trailer, length = recvall(sock, 1)
00130 
00131     if length < 1:
00132         raise EOFError
00133 
00134     if trailer != ',':
00135         raise ProtocolError, 'invalid netstring trailer'
00136 
00137     return s

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.flup.server.scgi_base.recvall (   sock,
  length 
)
Attempts to receive length bytes from a socket, blocking if necessary.
(Socket may be blocking or non-blocking.)

Definition at line 68 of file scgi_base.py.

00068 
00069 def recvall(sock, length):
00070     """
00071     Attempts to receive length bytes from a socket, blocking if necessary.
00072     (Socket may be blocking or non-blocking.)
00073     """
00074     dataList = []
00075     recvLen = 0
00076     while length:
00077         try:
00078             data = sock.recv(length)
00079         except socket.error, e:
00080             if e[0] == errno.EAGAIN:
00081                 select.select([sock], [], [])
00082                 continue
00083             else:
00084                 raise
00085         if not data: # EOF
00086             break
00087         dataList.append(data)
00088         dataLen = len(data)
00089         recvLen += dataLen
00090         length -= dataLen
00091     return ''.join(dataList), recvLen

Here is the caller graph for this function:


Variable Documentation

Definition at line 46 of file scgi_base.py.

string MoinMoin.support.flup.server.scgi_base.__author__ = 'Allan Saddi <allan@saddi.com>'

Definition at line 27 of file scgi_base.py.

Definition at line 28 of file scgi_base.py.

tuple MoinMoin.support.flup.server.scgi_base.console = logging.StreamHandler()

Definition at line 54 of file scgi_base.py.

Definition at line 51 of file scgi_base.py.