mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
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.
This commit is contained in:
parent
4009c942df
commit
2375ca87fe
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user