1 """
2 WSGI Utilities
3 (from web.py)
4 """
5
6 import os, sys
7
8 import http
9 import webapi as web
10 from utils import listget
11 from net import validaddr, validip
12 import httpserver
13
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()
18
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()
23
25 """
26 Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
27 as appropriate based on context and `sys.argv`.
28 """
29
30 if os.environ.has_key('SERVER_SOFTWARE'):
31 os.environ['FCGI_FORCE_CGI'] = 'Y'
32
33 if (os.environ.has_key('PHP_FCGI_CHILDREN')
34 or os.environ.has_key('SERVER_SOFTWARE')):
35 return runfcgi(func, None)
36
37 if 'fcgi' in sys.argv or 'fastcgi' in sys.argv:
38 args = sys.argv[1:]
39 if 'fastcgi' in args: args.remove('fastcgi')
40 elif 'fcgi' in args: args.remove('fcgi')
41 if args:
42 return runfcgi(func, validaddr(args[0]))
43 else:
44 return runfcgi(func, None)
45
46 if 'scgi' in sys.argv:
47 args = sys.argv[1:]
48 args.remove('scgi')
49 if args:
50 return runscgi(func, validaddr(args[0]))
51 else:
52 return runscgi(func)
53
54 return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))
55
57
58 if os.environ.has_key('SERVER_SOFTWARE') \
59 or os.environ.has_key('PHP_FCGI_CHILDREN') \
60 or 'fcgi' in sys.argv or 'fastcgi' in sys.argv \
61 or 'mod_wsgi' in sys.argv:
62 return False
63 return True
64
65
66 web.config.setdefault('debug', _is_dev_mode())
67