Added a mod_python-style form-data application decorator.
[wrw.git] / wrw / util.py
index 86a7eab..7a29ea8 100644 (file)
@@ -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):