From d46dfad91fdeb4cfe34b05f68f3fef53191a280e Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Mon, 17 May 2010 06:46:12 +0200 Subject: [PATCH] fix paster application --- gunicorn/app/base.py | 2 +- gunicorn/app/pasterapp.py | 34 ++++++++++++++++++++-------------- gunicorn/main.py | 4 ++-- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index 47d84af6..c5c88990 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -28,7 +28,7 @@ class Application(object): # Load up the any app specific configuration if cfg: - for k, v in cfg: + for k, v in cfg.items(): self.cfg.set(k.lower(), v) # Load up the config file if its found. diff --git a/gunicorn/app/pasterapp.py b/gunicorn/app/pasterapp.py index dd62504d..8fce6845 100644 --- a/gunicorn/app/pasterapp.py +++ b/gunicorn/app/pasterapp.py @@ -10,6 +10,9 @@ import sys from paste.deploy import loadapp, loadwsgi SERVER = loadwsgi.SERVER +from gunicorn.app.base import Application +from gunicorn.config import Config + class PasterApplication(Application): def init(self, parser, opts, args): @@ -31,11 +34,11 @@ class PasterApplication(Application): def app_config(self): cx = loadwsgi.loadcontext(SERVER, self.cfgurl, relative_to=self.relpath) - gc, lc = cx.global_conf, cx.local_conf + gc, lc = cx.global_conf.copy(), cx.local_conf.copy() cfg = {} - host, port = lc.get('host'), lc.get('port') + host, port = lc.pop('host', ''), lc.pop('port', '') if host and port: cfg['bind'] = '%s:%s' % (host, port) elif host: @@ -52,25 +55,28 @@ class PasterApplication(Application): class PasterServerApplication(Application): - def __init__(self, app, *args, **kwargs): - self.log = logging.getLogger(__name__) + def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs): self.cfg = Config() self.app = app - cfg = {} - host, port = kwargs.get('host'), kwargs.get('port') - if host and port: - cfg['bind'] = '%s:%s' % (host, port) - elif host: - cfg['bind'] = host + cfg = kwargs.copy() + + if port and not host.startswith("unix:"): + bind = "%s:%s" % (host, port) + else: + bind = host + cfg["bind"] = bind if gcfg: for k, v in list(gcfg.items()): - if k.lower() in self.cfg.settings: - self.cfg.set(k.lower(), v) - self.cfg.default_proc_name = kwargs.__file__ + cfg[k] = v + cfg["default_proc_name"] = cfg['__file__'] - self.configure_logging(cfg) + for k, v in list(cfg.items()): + if k.lower() in self.cfg.settings and v is not None: + self.cfg.set(k.lower(), v) + + self.configure_logging() def load(self): return self.app diff --git a/gunicorn/main.py b/gunicorn/main.py index ba9c66b2..533750e6 100644 --- a/gunicorn/main.py +++ b/gunicorn/main.py @@ -27,7 +27,7 @@ def run_paster(): from gunicorn.app.pasterapp import PasterApplication PasterApplication("%prog [OPTIONS] pasteconfig.ini").run() -def paste_server(*args, **kwargs): +def paste_server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs): """\ A paster server. @@ -40,7 +40,7 @@ def paste_server(*args, **kwargs): """ from gunicorn.app.pasterapp import PasterServerApplication - PasterServerApplication(app, *args, **kwargs).run() + PasterServerApplication(app, gcfg=gcfg, host=host, port=port, *args, **kwargs).run()