changeset 5804:2e7f76626b58

update flup to repo tip (no release since 1.0.2 / 2.5y)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Dec 2011 02:38:57 +0100
parents 6446873d152f
children da0c45f012fb
files MoinMoin/support/flup/client/fcgi_app.py MoinMoin/support/flup/client/scgi_app.py MoinMoin/support/flup/server/ajp_base.py MoinMoin/support/flup/server/fcgi_base.py MoinMoin/support/flup/server/fcgi_single.py MoinMoin/support/flup/server/paste_factory.py MoinMoin/support/flup/server/scgi_base.py MoinMoin/support/flup/server/threadedserver.py docs/REQUIREMENTS
diffstat 9 files changed, 68 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/support/flup/client/fcgi_app.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/client/fcgi_app.py	Thu Dec 01 02:38:57 2011 +0100
@@ -31,6 +31,7 @@
 import struct
 import socket
 import errno
+import types
 
 __all__ = ['FCGIApp']
 
@@ -386,11 +387,14 @@
         if self._connect is not None:
             # The simple case. Create a socket and connect to the
             # application.
-            if type(self._connect) is str:
+            if isinstance(self._connect, types.StringTypes):
                 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+                sock.connect(self._connect)
+            elif hasattr(socket, 'create_connection'):
+                sock = socket.create_connection(self._connect)
             else:
                 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            sock.connect(self._connect)
+                sock.connect(self._connect)
             return sock
 
         # To be done when I have more time...
--- a/MoinMoin/support/flup/client/scgi_app.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/client/scgi_app.py	Thu Dec 01 02:38:57 2011 +0100
@@ -31,6 +31,7 @@
 import struct
 import socket
 import errno
+import types
 
 __all__ = ['SCGIApp']
 
@@ -136,11 +137,14 @@
         return [result]
 
     def _getConnection(self):
-        if type(self._connect) is str:
+        if isinstance(self._connect, types.StringTypes):
             sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+            sock.connect(self._connect)
+        elif hasattr(socket, 'create_connection'):
+            sock = socket.create_connection(self._connect)
         else:
             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        sock.connect(self._connect)
+            sock.connect(self._connect)
         return sock
     
     _environPrefixes = ['SERVER_', 'HTTP_', 'REQUEST_', 'REMOTE_', 'PATH_',
--- a/MoinMoin/support/flup/server/ajp_base.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/server/ajp_base.py	Thu Dec 01 02:38:57 2011 +0100
@@ -960,7 +960,8 @@
         all errors should be caught at the application level.
         """
         if self.debug:
-            request.startResponse(200, 'OK', [('Content-Type', 'text/html')])
+            request.startResponse(500, 'Internal Server Error',
+                                  [('Content-Type', 'text/html')])
             import cgitb
             request.write(cgitb.html(sys.exc_info()))
         else:
@@ -972,5 +973,6 @@
 <p>An unhandled exception was thrown by the application.</p>
 </body></html>
 """
-            request.startResponse(200, 'OK', [('Content-Type', 'text/html')])
+            request.startResponse(500, 'Internal Server Error',
+                                  [('Content-Type', 'text/html')])
             request.write(errorpage)
--- a/MoinMoin/support/flup/server/fcgi_base.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/server/fcgi_base.py	Thu Dec 01 02:38:57 2011 +0100
@@ -821,7 +821,7 @@
         outrec = Record(FCGI_UNKNOWN_TYPE)
         outrec.contentData = struct.pack(FCGI_UnknownTypeBody, inrec.type)
         outrec.contentLength = FCGI_UnknownTypeBody_LEN
-        self.writeRecord(rec)
+        self.writeRecord(outrec)
         
 class MultiplexedConnection(Connection):
     """
@@ -1186,7 +1186,10 @@
 
         if not environ.has_key('PATH_INFO') or not environ['PATH_INFO']:
             if reqUri is not None:
-                environ['PATH_INFO'] = reqUri[0]
+                scriptName = environ['SCRIPT_NAME']
+                if not reqUri[0].startswith(scriptName):
+                    environ['wsgi.errors'].write('WARNING: SCRIPT_NAME does not match REQUEST_URI')
+                environ['PATH_INFO'] = reqUri[0][len(scriptName):]
             else:
                 environ['PATH_INFO'] = ''
         if not environ.has_key('QUERY_STRING') or not environ['QUERY_STRING']:
@@ -1214,7 +1217,8 @@
         """
         if self.debug:
             import cgitb
-            req.stdout.write('Content-Type: text/html\r\n\r\n' +
+            req.stdout.write('Status: 500 Internal Server Error\r\n' +
+                             'Content-Type: text/html\r\n\r\n' +
                              cgitb.html(sys.exc_info()))
         else:
             errorpage = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
@@ -1225,5 +1229,6 @@
 <p>An unhandled exception was thrown by the application.</p>
 </body></html>
 """
-            req.stdout.write('Content-Type: text/html\r\n\r\n' +
+            req.stdout.write('Status: 500 Internal Server Error\r\n' +
+                             'Content-Type: text/html\r\n\r\n' +
                              errorpage)
--- a/MoinMoin/support/flup/server/fcgi_single.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/server/fcgi_single.py	Thu Dec 01 02:38:57 2011 +0100
@@ -93,7 +93,7 @@
             if kw.has_key(key):
                 del kw[key]
         SingleServer.__init__(self, jobClass=self._connectionClass,
-                              jobArgs=(self,), **kw)
+                              jobArgs=(self, None), **kw)
         self.capability = {
             FCGI_MAX_CONNS: 1,
             FCGI_MAX_REQS: 1,
--- a/MoinMoin/support/flup/server/paste_factory.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/server/paste_factory.py	Thu Dec 01 02:38:57 2011 +0100
@@ -30,18 +30,26 @@
 
 def run_ajp_thread(wsgi_app, global_conf,
                    scriptName='', host='localhost', port='8009',
-                   allowedServers='127.0.0.1', debug=NoDefault):
+                   allowedServers='127.0.0.1', debug=NoDefault,
+                   minSpare=None, maxSpare=None, maxThreads=None):
     import flup.server.ajp
     addr = (host, int(port))
     if debug is NoDefault:
         debug = global_conf.get('debug', False)
     debug = asbool(debug)
+    threadpool_args = {}
+    if minSpare is not None:
+        threadpool_args['minSpare'] = int(minSpare)
+    if maxSpare is not None:
+        threadpool_args['maxSpare'] = int(maxSpare)
+    if maxThreads is not None:
+        threadpool_args['maxThreads'] = int(maxThreads)
     s = flup.server.ajp.WSGIServer(
         wsgi_app,
         scriptName=scriptName,
         bindAddress=addr,
         allowedServers=aslist(allowedServers),
-        debug=debug,
+        debug=debug, **threadpool_args
         )
     s.run()
 
@@ -76,7 +84,8 @@
 def run_fcgi_thread(wsgi_app, global_conf,
                     host=None, port=None,
                     socket=None, umask=None,
-                    multiplexed=False, debug=NoDefault):
+                    multiplexed=False, debug=NoDefault,
+                    minSpare=None, maxSpare=None, maxThreads=None):
     import flup.server.fcgi
     if socket:
         assert host is None and port is None
@@ -91,11 +100,19 @@
     if debug is NoDefault:
         debug = global_conf.get('debug', False)
     debug = asbool(debug)
+    threadpool_args = {}
+    if minSpare is not None:
+        threadpool_args['minSpare'] = int(minSpare)
+    if maxSpare is not None:
+        threadpool_args['maxSpare'] = int(maxSpare)
+    if maxThreads is not None:
+        threadpool_args['maxThreads'] = int(maxThreads)
     s = flup.server.fcgi.WSGIServer(
         wsgi_app,
         bindAddress=sock, umask=umask,
         multiplexed=asbool(multiplexed),
-        debug=debug)
+        debug=debug, **threadpool_args
+        )
     s.run()
 
 def run_fcgi_fork(wsgi_app, global_conf,
@@ -139,18 +156,26 @@
 def run_scgi_thread(wsgi_app, global_conf,
                     scriptName=NoDefault, host='localhost', port='4000',
                     allowedServers='127.0.0.1',
-                    debug=NoDefault):
+                    debug=NoDefault,
+                    minSpare=None, maxSpare=None, maxThreads=None):
     import flup.server.scgi
     addr = (host, int(port))
     if debug is NoDefault:
         debug = global_conf.get('debug', False)
     debug = asbool(debug)
+    threadpool_args = {}
+    if minSpare is not None:
+        threadpool_args['minSpare'] = int(minSpare)
+    if maxSpare is not None:
+        threadpool_args['maxSpare'] = int(maxSpare)
+    if maxThreads is not None:
+        threadpool_args['maxThreads'] = int(maxThreads)
     s = flup.server.scgi.WSGIServer(
         wsgi_app,
         scriptName=scriptName,
         bindAddress=addr,
         allowedServers=aslist(allowedServers),
-        debug=debug,
+        debug=debug, **threadpool_args
         )
     s.run()
 
--- a/MoinMoin/support/flup/server/scgi_base.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/server/scgi_base.py	Thu Dec 01 02:38:57 2011 +0100
@@ -525,7 +525,10 @@
                 environ['SCRIPT_NAME'] = ''
             if not environ.has_key('PATH_INFO') or not environ['PATH_INFO']:
                 if reqUri is not None:
-                    environ['PATH_INFO'] = reqUri[0]
+                    scriptName = environ['SCRIPT_NAME']
+                    if not reqUri[0].startswith(scriptName):
+                        self.logger.warning('SCRIPT_NAME does not match request URI')
+                    environ['PATH_INFO'] = reqUri[0][len(scriptName):]
                 else:
                     environ['PATH_INFO'] = ''
         else:
@@ -550,7 +553,8 @@
         """
         if self.debug:
             import cgitb
-            request.stdout.write('Content-Type: text/html\r\n\r\n' +
+            request.stdout.write('Status: 500 Internal Server Error\r\n' +
+                                 'Content-Type: text/html\r\n\r\n' +
                                  cgitb.html(sys.exc_info()))
         else:
             errorpage = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
@@ -561,5 +565,6 @@
 <p>An unhandled exception was thrown by the application.</p>
 </body></html>
 """
-            request.stdout.write('Content-Type: text/html\r\n\r\n' +
+            request.stdout.write('Status: 500 Internal Server Error\r\n' +
+                                 'Content-Type: text/html\r\n\r\n' +
                                  errorpage)
--- a/MoinMoin/support/flup/server/threadedserver.py	Thu Dec 01 02:26:16 2011 +0100
+++ b/MoinMoin/support/flup/server/threadedserver.py	Thu Dec 01 02:38:57 2011 +0100
@@ -105,7 +105,8 @@
             self._mainloopPeriodic()
 
         # Restore signal handlers.
-        self._restoreSignalHandlers()
+        if not sys.platform.startswith('win'):
+            self._restoreSignalHandlers()
 
         # Return bool based on whether or not SIGHUP was received.
         return self._hupReceived
--- a/docs/REQUIREMENTS	Thu Dec 01 02:26:16 2011 +0100
+++ b/docs/REQUIREMENTS	Thu Dec 01 02:38:57 2011 +0100
@@ -90,7 +90,7 @@
 
 flup (cgi/fastcgi/scgi/ajp to WSGI adapter)
 ===========================================
-shipped: 1.0.2+, from repo: hg clone -r 72496e17674f http://hg.saddi.com/flup-server
+shipped: 1.0.2+, from repo: hg clone -r 8d52f88effa3 http://hg.saddi.com/flup-server
 minimum: 1.0.2