10
from utils import listget
11
from net import validaddr, validip
14
def runfcgi(func, addr=('localhost', 8000)):
15
"""Runs a WSGI function as a FastCGI server."""
16
import flup.server.fcgi as flups
17
return flups.WSGIServer(func, multiplexed=True, bindAddress=addr).run()
19
def runscgi(func, addr=('localhost', 4000)):
20
"""Runs a WSGI function as an SCGI server."""
21
import flup.server.scgi as flups
22
return flups.WSGIServer(func, bindAddress=addr).run()
26
Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
27
as appropriate based on context and `sys.argv`.
30
if os.environ.has_key('SERVER_SOFTWARE'): # cgi
31
os.environ['FCGI_FORCE_CGI'] = 'Y'
33
if (os.environ.has_key('PHP_FCGI_CHILDREN') #lighttpd fastcgi
34
or os.environ.has_key('SERVER_SOFTWARE')):
35
return runfcgi(func, None)
37
if 'fcgi' in sys.argv or 'fastcgi' in sys.argv:
39
if 'fastcgi' in args: args.remove('fastcgi')
40
elif 'fcgi' in args: args.remove('fcgi')
42
return runfcgi(func, validaddr(args[0]))
44
return runfcgi(func, None)
46
if 'scgi' in sys.argv:
50
return runscgi(func, validaddr(args[0]))
54
return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))