From 4bb96b28dee16e78d68f16f5bf158f1e879a0523 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sun, 11 Sep 2011 22:11:36 +0200 Subject: API first draft: utils. (related to #27) Introduces the "rest" module, with reusable utils for flask applications (will be packaged as a flask extension later on). --- budget/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'budget/utils.py') diff --git a/budget/utils.py b/budget/utils.py index 262ebfe..8d67410 100644 --- a/budget/utils.py +++ b/budget/utils.py @@ -1,4 +1,6 @@ from functools import wraps +import inspect + from flask import redirect, url_for, session, request from werkzeug.routing import HTTPException, RoutingException @@ -34,3 +36,12 @@ class Redirect303(HTTPException, RoutingException): def get_response(self, environ): return redirect(self.new_url, 303) + +def for_all_methods(decorator): + """Apply a decorator to all the methods of a class""" + def decorate(cls): + for name, method in inspect.getmembers(cls, inspect.ismethod): + setattr(cls, name, decorator(method)) + return cls + return decorate + -- cgit v1.1