From: Fredrik Tolf Date: Fri, 30 Dec 2011 01:33:09 +0000 (+0100) Subject: Added a mod_python-style form-data application decorator. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=bbdebbab6c98d8611bc8faa197df226d29e4cb2b;p=wrw.git Added a mod_python-style form-data application decorator. --- diff --git a/wrw/__init__.py b/wrw/__init__.py index 30936b6..c0b8273 100644 --- a/wrw/__init__.py +++ b/wrw/__init__.py @@ -1,6 +1,6 @@ __all__ = ["wsgiwrap", "restart", "cookie", "formdata"] -from util import wsgiwrap, persession, sessiondata +from util import wsgiwrap, formparams, persession, sessiondata, autodirty, manudirty from dispatch import restart import cookie from form import formdata diff --git a/wrw/util.py b/wrw/util.py index 86a7eab..7a29ea8 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -1,10 +1,24 @@ -import req, dispatch, session +import inspect +import req, dispatch, session, form def wsgiwrap(callable): def wrapper(env, startreq): return dispatch.handle(req.origrequest(env), startreq, callable) return wrapper +def formparams(callable): + def wrapper(req): + data = form.formdata(req) + spec = inspect.getargspec(callable) + args = dict(data.items()) + args["req"] = req + if not spec.keywords: + for arg in list(args): + if arg not in spec.args: + del args[arg] + return callable(**args) + return wrapper + def persession(data = None): def dec(callable): def wrapper(req):