changeset 1166:b6dee77f7e67

thfcgi: whitespace only cleanup
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Aug 2006 19:10:43 +0200
parents b9c91deadca4
children 038d975120bd
files MoinMoin/support/thfcgi.py
diffstat 1 files changed, 28 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/support/thfcgi.py	Sat Aug 12 23:56:08 2006 +0200
+++ b/MoinMoin/support/thfcgi.py	Sun Aug 13 19:10:43 2006 +0200
@@ -1,6 +1,5 @@
 # -*- coding: iso-8859-1 -*-
 """
-    
     thfcgi.py - FastCGI communication with thread support
 
     Copyright Peter Åstrand <astrand@lysator.liu.se> 2001
@@ -33,7 +32,6 @@
 # CONTENT_LENGTH and abort the update if the two numbers are not equal.
 #
 
-# Imports
 import os
 import sys
 import select
@@ -48,6 +46,7 @@
 FCGI_MAX_REQS = 50
 FCGI_MAX_CONNS = 50
 FCGI_VERSION_1 = 1
+
 # Can this application multiplex connections?
 FCGI_MPXS_CONNS = 0
 
@@ -91,7 +90,7 @@
 FCGI_EndRequestBody = "!IB3x"
 
 class SocketErrorOnWrite:
-    """ Is raised if a write fails in the socket code."""
+    """Is raised if a write fails in the socket code."""
     pass
 
 class Record:
@@ -158,25 +157,25 @@
             data += struct.pack("!I", value | 0x80000000L)
 
         return data + name + value
-        
+
     def readRecord(self, sock):
         """Read a FastCGI record from the server."""
         data = sock.recv(8)
         if not data:
             # No data recieved. This means EOF. 
             return None
-        
+
         fields = struct.unpack(FCGI_Record_header, data)
         (self.version, self.rec_type, self.req_id,
          contentLength, paddingLength) = fields
-        
+
         self.content = ""
         while len(self.content) < contentLength:
             data = sock.recv(contentLength - len(self.content))
             self.content = self.content + data
         if paddingLength != 0:
             sock.recv(paddingLength)
-        
+
         # Parse the content information
         if self.rec_type == FCGI_BEGIN_REQUEST:
             (self.role, self.flags) = struct.unpack(FCGI_BeginRequestBody,
@@ -220,10 +219,10 @@
         # Align to 8-byte boundary
         clen = len(content)
         padlen = ((clen + 7) & 0xfff8) - clen
-        
+
         hdr = struct.pack(FCGI_Record_header, self.version, self.rec_type,
                           self.req_id, clen, padlen)
-        
+
         try:
             sock.sendall(hdr + content + padlen*"\x00")
         except socket.error:
@@ -234,13 +233,13 @@
 class Request:
     """A request, corresponding to an accept():ed connection and
     a FCGI request."""
-    
+
     def __init__(self, conn, req_handler, multi=1):
         """Initialize Request container."""
         self.conn = conn
         self.req_handler = req_handler
         self.multi = multi
-        
+
         self.keep_conn = 0
         self.req_id = None
 
@@ -276,7 +275,7 @@
             else:
                 # EOF, connection closed. Break loop, end thread. 
                 return
-                
+
     def getFieldStorage(self):
         """Return a cgi FieldStorage constructed from the stdin and
         environ read from the server for this request."""
@@ -301,7 +300,7 @@
         if not data:
             # Writing zero bytes would mean stream termination
             return
-        
+
         while data:
             chunk, data = self.getNextChunk(data)
             rec.content = chunk
@@ -365,7 +364,7 @@
             if self.multi:
                 import thread
                 thread.exit()
-    
+
     #
     # Record handlers
     #
@@ -397,9 +396,9 @@
             reply_rec = Record()
             reply_rec.rec_type = FCGI_GET_VALUES_RESULT
 
-            params = {'FCGI_MAX_CONNS' : FCGI_MAX_CONNS,
-                      'FCGI_MAX_REQS' : FCGI_MAX_REQS,
-                      'FCGI_MPXS_CONNS' : FCGI_MPXS_CONNS}
+            params = {'FCGI_MAX_CONNS': FCGI_MAX_CONNS,
+                      'FCGI_MAX_REQS': FCGI_MAX_REQS,
+                      'FCGI_MPXS_CONNS': FCGI_MPXS_CONNS}
 
             for name in rec.values.keys():
                 if params.has_key(name):
@@ -461,14 +460,14 @@
 
         self.req_id = rec.req_id
         self.keep_conn = rec.keep_conn
-        
+
     def _handle_params(self, rec):
         """Handle environment."""
         if self.env_complete:
             # Should not happen
             #print >> sys.stderr, "Recieved FCGI_PARAMS more than once"
             return
-        
+
         if not rec.content:
             self.env_complete = 1
 
@@ -481,7 +480,7 @@
             # Should not happen
             #print >> sys.stderr, "Recieved FCGI_STDIN more than once"
             return
-        
+
         if not rec.content:
             self.stdin_complete = 1
             self.stdin.reset()
@@ -498,7 +497,7 @@
 
         if not rec.content:
             self.data_complete = 1
-        
+
         self.data.write(rec.content)
 
     def getNextChunk(self, data):
@@ -509,7 +508,7 @@
 
 class FCGIbase:
     """Base class for FCGI requests."""
-    
+
     def __init__(self, req_handler, fd, port):
         """Initialize main loop and set request_handler."""
         self.req_handler = req_handler
@@ -553,7 +552,7 @@
                 raise RuntimeError("No FastCGI environment: %s - %s" % (`err`, errmsg))
 
         self.sock = s
-        
+
     def _check_good_addrs(self, addr):
         """Check if request is done from the right server."""
         # Apaches mod_fastcgi seems not to use FCGI_WEB_SERVER_ADDRS. 
@@ -562,14 +561,14 @@
             good_addrs = map(string.strip, good_addrs) # Remove whitespace
         else:
             good_addrs = None
-        
+
         # Check if the connection is from a legal address
         if good_addrs != None and addr not in good_addrs:
             raise RuntimeError("Connection from invalid server!")
 
 class THFCGI(FCGIbase):
     """Multi-threaded main loop to handle FastCGI Requests."""
-    
+
     def __init__(self, req_handler, fd=sys.stdin, port=None):
         """Initialize main loop and set request_handler."""
         self.multi = 1
@@ -580,7 +579,7 @@
         thread on every request."""
         import thread
         self.sock.listen(50)
-        
+
         while 1:
             (conn, addr) = self.sock.accept()
             thread.start_new_thread(self.accept_handler, (conn, addr))
@@ -592,12 +591,12 @@
         """Initialize main loop and set request_handler."""
         self.multi = 0
         FCGIbase.__init__(self, req_handler, fd, port)
-    
+
     def run(self):
         """Wait & serve. Calls request handler for every request (blocking)."""
         self.sock.listen(50)
-        
+
         while 1:
             (conn, addr) = self.sock.accept()
             self.accept_handler(conn, addr)
-   
+