Skip to content
Browse files

Added an env config key. This allows one to define environment variab…

…les to be

set before running the WSGI server.
  • Loading branch information...
1 parent cb38ae9 commit 1ea8fa6c8ad2e91e60a765daa34d7d373d42c5d9 @brosner committed Jun 30, 2008
Showing with 9 additions and 2 deletions.
  1. +9 −2 bosnowsgi.py
View
11 bosnowsgi.py
@@ -17,17 +17,22 @@ class WSGIServerProcess(object):
"""
A simple wrapper around starting and stopping a CherryPy WSGI process.
"""
- def __init__(self, dispatcher, host, port, daemonize=False, pidfile=None):
+ def __init__(self, dispatcher, host, port, daemonize=False, pidfile=None,
+ env={}):
self.dispatcher = dispatcher
self.host = host
self.port = port
self.daemonize = daemonize
self.pidfile = pidfile
+ self.env = env
def start(self):
"""
Starts the WSGI server.
"""
+ # setup the environment
+ for var, value in self.env.items():
+ os.environ[var] = value
server = CherryPyWSGIServer((self.host, self.port), self.dispatcher)
if self.daemonize:
daemonize()
@@ -100,7 +105,9 @@ def load_wsgi_server(name, **kwargs):
raise ImproperlyConfigured, "no port specified for '%s'" % name
except ValueError:
raise ImproperlyConfigured, "'%s' has a malformed port" % name
- return WSGIServerProcess(dispatcher, host, port, **kwargs)
+ defaults = {"env": config.get("env", {})}
+ defaults.update(kwargs)
+ return WSGIServerProcess(dispatcher, host, port, **defaults)
def parse_parameters():
"""

0 comments on commit 1ea8fa6

Please sign in to comment.
Something went wrong with that request. Please try again.