This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new f0f2fed0d Add generic require_method helper, alongside require_post
f0f2fed0d is described below
commit f0f2fed0ded33ed8ac368f36490d0828b6f5fa0e
Author: Dave Brondsema <[email protected]>
AuthorDate: Fri Jul 8 16:19:54 2022 -0400
Add generic require_method helper, alongside require_post
---
Allura/allura/lib/decorators.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Allura/allura/lib/decorators.py b/Allura/allura/lib/decorators.py
index 241164afb..078eaa4f8 100644
--- a/Allura/allura/lib/decorators.py
+++ b/Allura/allura/lib/decorators.py
@@ -115,6 +115,20 @@ class require_post:
return func
+def require_method(*methods):
+ """
+ Usage:
+
+ @require_method('GET', 'HEAD')
+ def foo()
+ """
+ def check_methods(func, *args, **kwargs):
+ if request.method not in methods:
+ raise exc.HTTPMethodNotAllowed(headers={'Allow':
str(','.join(methods))})
+ return func(*args, **kwargs)
+ return decorator(check_methods)
+
+
@decorator
def reconfirm_auth(func, *args, **kwargs):
'''