Code

Ticket #3047: generalize_flup.diff

File generalize_flup.diff, 2.9 KB (added by Barry Pederson <bp@…>, 7 years ago)

Suggested enhancement

Line 
1Index: django/core/servers/fastcgi.py
2===================================================================
3--- django/core/servers/fastcgi.py      (revision 4088)
4+++ django/core/servers/fastcgi.py      (working copy)
5@@ -1,5 +1,5 @@
6 """
7-FastCGI server that implements the WSGI protocol.
8+FastCGI (or SCGI, or AJP1.3 ...) server that implements the WSGI protocol.
9 
10 Uses the flup python package: http://www.saddi.com/software/flup/
11 
12@@ -18,15 +18,16 @@
13 __all__ = ["runfastcgi"]
14 
15 FASTCGI_HELP = r"""runfcgi:
16-  Run this project as a fastcgi application. To do this, the
17-  flup package from http://www.saddi.com/software/flup/ is
18-  required.
19+  Run this project as a fastcgi (or some other protocol supported
20+  by flup) application. To do this, the flup package from
21+  http://www.saddi.com/software/flup/ is required.
22 
23 Usage:
24    django-admin.py runfcgi --settings=yourproject.settings [fcgi settings]
25    manage.py runfcgi [fcgi settings]
26 
27 Optional Fcgi settings: (setting=value)
28+  protocol=PROTOCOL    fcgi, scgi, ajp, ... (default fcgi)
29   host=HOSTNAME        hostname to listen on..
30   port=PORTNUM         port to listen on.
31   socket=FILE          UNIX socket to listen on.
32@@ -45,8 +46,8 @@
33   (for webservers which spawn your processes for you)
34     $ manage.py runfcgi method=threaded
35 
36-  Run a fastcgi server on a TCP host/port
37-    $ manage.py runfcgi method=prefork host=127.0.0.1 port=8025
38+  Run a scgi server on a TCP host/port
39+    $ manage.py runfcgi protocol=scgi method=prefork host=127.0.0.1 port=8025
40 
41   Run a fastcgi server on a UNIX domain socket (posix platforms only)
42     $ manage.py runfcgi method=prefork socket=/tmp/fcgi.sock
43@@ -58,6 +59,7 @@
44 """
45 
46 FASTCGI_OPTIONS = {
47+    'protocol': 'fcgi',
48     'host': None,
49     'port': None,
50     'socket': None,
51@@ -100,16 +102,17 @@
52         print >> sys.stderr, "  installed flup, then make sure you have it in your PYTHONPATH."
53         return False
54 
55+    flup_module = 'server.' + options['protocol']
56+
57     if options['method'] in ('prefork', 'fork'):
58-        from flup.server.fcgi_fork import WSGIServer
59         wsgi_opts = {
60             'maxSpare': int(options["maxspare"]),
61             'minSpare': int(options["minspare"]),
62             'maxChildren': int(options["maxchildren"]),
63             'maxRequests': int(options["maxrequests"]),
64         }
65+        flup_module += '_fork'
66     elif options['method'] in ('thread', 'threaded'):
67-        from flup.server.fcgi import WSGIServer
68         wsgi_opts = {
69             'maxSpare': int(options["maxspare"]),
70             'minSpare': int(options["minspare"]),
71@@ -118,6 +121,12 @@
72     else:
73         return fastcgi_help("ERROR: Implementation must be one of prefork or thread.")
74 
75+    try:
76+        WSGIServer = getattr(__import__('flup.' + flup_module, '', '', flup_module), 'WSGIServer')
77+    except:
78+        print "Can't import flup." + flup_module
79+        return False
80+
81     # Prep up and go
82     from django.core.handlers.wsgi import WSGIHandler
83