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, debug=False).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, debug=False).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, '')))
57 # Some embedded python interpreters won't have sys.arv
58 # For details, see https://github.com/webpy/webpy/issues/87
59 argv = getattr(sys, "argv", [])
61 # quick hack to check if the program is running in dev mode.
62 if os.environ.has_key('SERVER_SOFTWARE') \
63 or os.environ.has_key('PHP_FCGI_CHILDREN') \
64 or 'fcgi' in argv or 'fastcgi' in argv \
65 or 'mod_wsgi' in argv:
69 # When running the builtin-server, enable debug mode if not already set.
70 web.config.setdefault('debug', _is_dev_mode())