Back to index

moin  1.9.0~rc2
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
MoinMoin.support.flup.client.scgi_app.SCGIApp Class Reference

List of all members.

Public Member Functions

def __init__
def __call__

Private Member Functions

def _getConnection
def _defaultFilterEnviron
def _lightFilterEnviron

Private Attributes

 _connect
 _filterEnviron

Static Private Attributes

list _environPrefixes
list _environCopies = ['SCRIPT_NAME', 'QUERY_STRING', 'AUTH_TYPE']
dictionary _environRenames = {}

Detailed Description

Definition at line 40 of file scgi_app.py.


Constructor & Destructor Documentation

def MoinMoin.support.flup.client.scgi_app.SCGIApp.__init__ (   self,
  connect = None,
  host = None,
  port = None,
  filterEnviron = True 
)

Definition at line 42 of file scgi_app.py.

00042 
00043                  filterEnviron=True):
00044         if host is not None:
00045             assert port is not None
00046             connect=(host, port)
00047 
00048         assert connect is not None
00049         self._connect = connect
00050 
00051         self._filterEnviron = filterEnviron
        

Member Function Documentation

def MoinMoin.support.flup.client.scgi_app.SCGIApp.__call__ (   self,
  environ,
  start_response 
)

Definition at line 52 of file scgi_app.py.

00052 
00053     def __call__(self, environ, start_response):
00054         sock = self._getConnection()
00055 
00056         outfile = sock.makefile('w')
00057         infile = sock.makefile('r')
00058 
00059         sock.close()
00060 
00061         # Filter WSGI environ and send as request headers
00062         if self._filterEnviron:
00063             headers = self._defaultFilterEnviron(environ)
00064         else:
00065             headers = self._lightFilterEnviron(environ)
00066         # TODO: Anything not from environ that needs to be sent also?
00067 
00068         content_length = int(environ.get('CONTENT_LENGTH') or 0)
00069         if headers.has_key('CONTENT_LENGTH'):
00070             del headers['CONTENT_LENGTH']
00071             
00072         headers_out = ['CONTENT_LENGTH', str(content_length), 'SCGI', '1']
00073         for k,v in headers.items():
00074             headers_out.append(k)
00075             headers_out.append(v)
00076         headers_out.append('') # For trailing NUL
00077         outfile.write(encodeNetstring('\x00'.join(headers_out)))
00078 
00079         # Transfer wsgi.input to outfile
00080         while True:
00081             chunk_size = min(content_length, 4096)
00082             s = environ['wsgi.input'].read(chunk_size)
00083             content_length -= len(s)
00084             outfile.write(s)
00085 
00086             if not s: break
00087 
00088         outfile.close()
00089         
00090         # Read result from SCGI server
00091         result = []
00092         while True:
00093             buf = infile.read(4096)
00094             if not buf: break
00095 
00096             result.append(buf)
00097 
00098         infile.close()
00099         
00100         result = ''.join(result)
00101 
00102         # Parse response headers
00103         status = '200 OK'
00104         headers = []
00105         pos = 0
00106         while True:
00107             eolpos = result.find('\n', pos)
00108             if eolpos < 0: break
00109             line = result[pos:eolpos-1]
00110             pos = eolpos + 1
00111 
00112             # strip in case of CR. NB: This will also strip other
00113             # whitespace...
00114             line = line.strip()
00115             
00116             # Empty line signifies end of headers
00117             if not line: break
00118 
00119             # TODO: Better error handling
00120             header, value = line.split(':', 1)
00121             header = header.strip().lower()
00122             value = value.strip()
00123 
00124             if header == 'status':
00125                 # Special handling of Status header
00126                 status = value
00127                 if status.find(' ') < 0:
00128                     # Append a dummy reason phrase if one was not provided
00129                     status += ' SCGIApp'
00130             else:
00131                 headers.append((header, value))
00132 
00133         result = result[pos:]
00134 
00135         # Set WSGI status, headers, and return result.
00136         start_response(status, headers)
00137         return [result]

Here is the call graph for this function:

Definition at line 151 of file scgi_app.py.

00151 
00152     def _defaultFilterEnviron(self, environ):
00153         result = {}
00154         for n in environ.keys():
00155             for p in self._environPrefixes:
00156                 if n.startswith(p):
00157                     result[n] = environ[n]
00158             if n in self._environCopies:
00159                 result[n] = environ[n]
00160             if n in self._environRenames:
00161                 result[self._environRenames[n]] = environ[n]
00162                 
00163         return result

Here is the caller graph for this function:

Definition at line 138 of file scgi_app.py.

00138 
00139     def _getConnection(self):
00140         if type(self._connect) is str:
00141             sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
00142         else:
00143             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00144         sock.connect(self._connect)
00145         return sock
    

Here is the caller graph for this function:

Definition at line 164 of file scgi_app.py.

00164 
00165     def _lightFilterEnviron(self, environ):
00166         result = {}
00167         for n in environ.keys():
00168             if n.upper() == n:
00169                 result[n] = environ[n]
00170         return result

Here is the caller graph for this function:


Member Data Documentation

Definition at line 48 of file scgi_app.py.

list MoinMoin.support.flup.client.scgi_app.SCGIApp._environCopies = ['SCRIPT_NAME', 'QUERY_STRING', 'AUTH_TYPE'] [static, private]

Definition at line 148 of file scgi_app.py.

Initial value:
['SERVER_', 'HTTP_', 'REQUEST_', 'REMOTE_', 'PATH_',
                        'CONTENT_']

Definition at line 146 of file scgi_app.py.

Definition at line 149 of file scgi_app.py.

Definition at line 50 of file scgi_app.py.


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