diff --git a/gunicorn/config.py b/gunicorn/config.py index d4e1fca7..4640e5c8 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -100,7 +100,7 @@ class Config(object): def address(self): if not self.conf['bind']: raise RuntimeError("Listener address is not set") - return util.parse_address(self.conf['bind']) + return util.parse_address(util.to_bytestring(self.conf['bind'])) def _hook(self, hookname, *args): hook = self.conf.get(hookname) diff --git a/gunicorn/main.py b/gunicorn/main.py index 970fe30c..fab3e031 100644 --- a/gunicorn/main.py +++ b/gunicorn/main.py @@ -155,7 +155,7 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None, """ - bind_addr = util.parse_address(host, port) + bind_addr = util.parse_address(util.to_bytestring(host), port) # set others options debug = kwargs.get('debug') diff --git a/gunicorn/management/commands/run_gunicorn.py b/gunicorn/management/commands/run_gunicorn.py index 224c2f1d..b88f46cd 100644 --- a/gunicorn/management/commands/run_gunicorn.py +++ b/gunicorn/management/commands/run_gunicorn.py @@ -16,8 +16,9 @@ from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException from django.core.handlers.wsgi import WSGIHandler from gunicorn.arbiter import Arbiter -from gunicorn.main import daemonize, UMASK, set_owner_process -from gunicorn.util import parse_address +from gunicorn.config import Config +from gunicorn.main import daemonize, UMASK, set_owner_process, configure_logging +from gunicorn.util import parse_address, to_bytestring class Command(BaseCommand): option_list = BaseCommand.option_list + ( @@ -46,24 +47,21 @@ class Command(BaseCommand): if args: raise CommandError('Usage is runserver %s' % self.args) - bind = addrport or '127.0.0.1' - addr = parse_address(bind) + + options['bind'] = addrport or '127.0.0.1' + conf = Config(options) admin_media_path = options.get('admin_media_path', '') - workers = int(options.get('workers', '1')) - daemon = options.get('daemon') quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' - pidfile = options.get('pidfile', None) - umask = options.get('umask', UMASK) print "Validating models..." self.validate(display_num_errors=True) print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE) - if isinstance(addr, basestring): - print "Development server is running at unix:/%s" % addr + if isinstance(conf.address, basestring): + print "Development server is running at unix:/%s" % conf.address else: - print "Development server is running at http://%s:%s/" % addr + print "Development server is running at http://%s:%s/" % conf.address print "Quit the server with %s." % quit_command # django.core.management.base forces the locale to en-us. @@ -71,13 +69,14 @@ class Command(BaseCommand): try: handler = AdminMediaHandler(WSGIHandler(), admin_media_path) - arbiter = Arbiter(addr, workers, handler, - pidfile=pidfile) - if daemon: - daemonize(umask) + arbiter = Arbiter(conf.address, conf.workers, handler, + pidfile=conf['pidfile'], config=conf) + if conf['daemon']: + daemonize(conf['umask']) else: os.setpgrp() - set_owner_process(options.get("user"), options.get("group")) + set_owner_process(conf["user"], conf["group"]) + configure_logging(conf) arbiter.run() except WSGIServerException, e: # Use helpful error messages instead of ugly tracebacks. diff --git a/gunicorn/util.py b/gunicorn/util.py index d78f9a36..3fd22351 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -163,3 +163,12 @@ def http_date(timestamp=None): day, monthname[month], year, hh, mm, ss) return s + +def to_bytestring(s): + """ convert to bytestring an unicode """ + if not isinstance(s, basestring): + return s + if isinstance(s, unicode): + return s.encode('utf-8') + else: + return s