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:
|
except KeyError:
|
||||||
raise ConfigError("No such group: '%s'" % val)
|
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):
|
class ConfigFile(Setting):
|
||||||
name = "config"
|
name = "config"
|
||||||
section = "Config File"
|
section = "Config File"
|
||||||
@ -728,7 +749,7 @@ class PreRequest(Setting):
|
|||||||
class PostRequest(Setting):
|
class PostRequest(Setting):
|
||||||
name = "post_request"
|
name = "post_request"
|
||||||
section = "Server Hooks"
|
section = "Server Hooks"
|
||||||
validator = validate_callable(3)
|
validator = validate_post_request
|
||||||
type = "callable"
|
type = "callable"
|
||||||
def post_request(worker, req, environ):
|
def post_request(worker, req, environ):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class AsyncWorker(base.Worker):
|
|||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
self.cfg.post_request(self, req)
|
self.cfg.post_request(self, req, environ)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return True
|
return True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user