Back to index

moin  1.9.0~rc2
paste_factory.py
Go to the documentation of this file.
00001 # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
00002 # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
00003 
00004 from flup.server import NoDefault
00005 
00006 def asbool(obj):
00007     if isinstance(obj, (str, unicode)):
00008         obj = obj.strip().lower()
00009         if obj in ['true', 'yes', 'on', 'y', 't', '1']:
00010             return True
00011         elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
00012             return False
00013         else:
00014             raise ValueError(
00015                 "String is not true/false: %r" % obj)
00016     return bool(obj)
00017 
00018 def aslist(obj, sep=None, strip=True):
00019     if isinstance(obj, (str, unicode)):
00020         lst = obj.split(sep)
00021         if strip:
00022             lst = [v.strip() for v in lst]
00023         return lst
00024     elif isinstance(obj, (list, tuple)):
00025         return obj
00026     elif obj is None:
00027         return []
00028     else:
00029         return [obj]
00030 
00031 def run_ajp_thread(wsgi_app, global_conf,
00032                    scriptName='', host='localhost', port='8009',
00033                    allowedServers='127.0.0.1', debug=NoDefault):
00034     import flup.server.ajp
00035     addr = (host, int(port))
00036     if debug is NoDefault:
00037         debug = global_conf.get('debug', False)
00038     debug = asbool(debug)
00039     s = flup.server.ajp.WSGIServer(
00040         wsgi_app,
00041         scriptName=scriptName,
00042         bindAddress=addr,
00043         allowedServers=aslist(allowedServers),
00044         debug=debug,
00045         )
00046     s.run()
00047 
00048 def run_ajp_fork(wsgi_app, global_conf,
00049                  scriptName='', host='localhost', port='8009',
00050                  allowedServers='127.0.0.1', debug=NoDefault):
00051     import flup.server.ajp_fork
00052     addr = (host, int(port))
00053     if debug is NoDefault:
00054         debug = global_conf.get('debug', False)
00055     debug = asbool(debug)
00056     s = flup.server.ajp_fork.WSGIServer(
00057         wsgi_app,
00058         scriptName=scriptName,
00059         bindAddress=addr,
00060         allowedServers=aslist(allowedServers),
00061         debug=debug,
00062         )
00063     s.run()
00064 
00065 def run_fcgi_thread(wsgi_app, global_conf,
00066                     host=None, port=None,
00067                     socket=None, umask=None,
00068                     multiplexed=False, debug=NoDefault):
00069     import flup.server.fcgi
00070     if socket:
00071         assert host is None and port is None
00072         sock = socket
00073     elif host:
00074         assert host is not None and port is not None
00075         sock = (host, int(port))
00076     else:
00077         sock = None
00078     if umask is not None:
00079         umask = int(umask)
00080     if debug is NoDefault:
00081         debug = global_conf.get('debug', False)
00082     debug = asbool(debug)
00083     s = flup.server.fcgi.WSGIServer(
00084         wsgi_app,
00085         bindAddress=sock, umask=umask,
00086         multiplexed=asbool(multiplexed),
00087         debug=debug)
00088     s.run()
00089 
00090 def run_fcgi_fork(wsgi_app, global_conf,
00091                   host=None, port=None,
00092                   socket=None, umask=None,
00093                   multiplexed=False,
00094                   debug=NoDefault):
00095     import flup.server.fcgi_fork
00096     if socket:
00097         assert host is None and port is None
00098         sock = socket
00099     elif host:
00100         assert host is not None and port is not None
00101         sock = (host, int(port))
00102     else:
00103         sock = None
00104     if umask is not None:
00105         umask = int(umask)
00106     if debug is NoDefault:
00107         debug = global_conf.get('debug', False)
00108     debug = asbool(debug)
00109     s = flup.server.fcgi_fork.WSGIServer(
00110         wsgi_app,
00111         bindAddress=sock, umask=umask,
00112         multiplexed=asbool(multiplexed),
00113         debug=debug)
00114     s.run()
00115 
00116 def run_scgi_thread(wsgi_app, global_conf,
00117                     scriptName=NoDefault, host='localhost', port='4000',
00118                     allowedServers='127.0.0.1',
00119                     debug=NoDefault):
00120     import flup.server.scgi
00121     addr = (host, int(port))
00122     if debug is NoDefault:
00123         debug = global_conf.get('debug', False)
00124     debug = asbool(debug)
00125     s = flup.server.scgi.WSGIServer(
00126         wsgi_app,
00127         scriptName=scriptName,
00128         bindAddress=addr,
00129         allowedServers=aslist(allowedServers),
00130         debug=debug,
00131         )
00132     s.run()
00133 
00134 def run_scgi_fork(wsgi_app, global_conf,
00135                   scriptName=NoDefault, host='localhost', port='4000',
00136                   allowedServers='127.0.0.1',
00137                   debug=NoDefault):
00138     import flup.server.scgi_fork
00139     addr = (host, int(port))
00140     if debug is NoDefault:
00141         debug = global_conf.get('debug', False)
00142     debug = asbool(debug)
00143     s = flup.server.scgi_fork.WSGIServer(
00144         wsgi_app,
00145         scriptName=scriptName,
00146         bindAddress=addr,
00147         allowedServers=aslist(allowedServers),
00148         debug=debug,
00149         )
00150     s.run()
00151