From 2375ca87fe4ec4990a6afd62c57e6d3d755464b8 Mon Sep 17 00:00:00 2001 From: benoitc Date: Fri, 9 Sep 2011 00:09:16 +0200 Subject: [PATCH] fix issue #244. lats change in post_request arity was breaking some apps and also wasn't working everywhere. This patch wrap the function if arity != 3 so we don't have to test its arity each time we use it. --- gunicorn/config.py | 23 ++++++++++++++++++++++- gunicorn/workers/async.py | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gunicorn/config.py b/gunicorn/config.py index afb5d684..75e46ce7 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -238,6 +238,27 @@ def validate_group(val): except KeyError: raise ConfigError("No such group: '%s'" % val) +def validate_post_request(val): + + # decorator + def wrap_post_request(fun): + def _wrapped(instance, req, environ): + return fun(instance, req) + return _wrapped + + if not callable(val): + raise TypeError("Value isn't a callable: %s" % val) + + largs = len(inspect.getargspec(val)[0]) + if largs == 3: + return val + elif largs == 2: + return wrap_post_request(val) + else: + raise TypeError("Value must have an arity of: 3") + + + class ConfigFile(Setting): name = "config" section = "Config File" @@ -728,7 +749,7 @@ class PreRequest(Setting): class PostRequest(Setting): name = "post_request" section = "Server Hooks" - validator = validate_callable(3) + validator = validate_post_request type = "callable" def post_request(worker, req, environ): pass diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index 445adee2..2c39322f 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -75,7 +75,7 @@ class AsyncWorker(base.Worker): raise StopIteration() finally: try: - self.cfg.post_request(self, req) + self.cfg.post_request(self, req, environ) except: pass return True