From: Fredrik Tolf Date: Tue, 25 Jun 2024 01:35:09 +0000 (+0200) Subject: Mangle parameter names in formparams. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=0a22b876bbda8fec0e584c37287528c151b81888;p=wrw.git Mangle parameter names in formparams. --- diff --git a/wrw/util.py b/wrw/util.py index 6fa4155..18e3c97 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -10,9 +10,14 @@ def wsgiwrap(callable): def formparams(callable): sig = inspect.signature(callable) haskw = inspect.Parameter.VAR_KEYWORD in (par.kind for par in sig.parameters.values()) + + def mangle(nm): + return nm.replace("-", "_") + def wrapper(req): try: - data = dict(form.formdata(req).items()) + data = dict((mangle(key), val) for (key, val) + in form.formdata(req).items()) except IOError: raise resp.httperror(400, "Invalid request", "Form data was incomplete") @@ -30,6 +35,7 @@ def formparams(callable): if par.default is inspect.Parameter.empty and par.name not in args: raise resp.httperror(400, "Missing parameter", ("The query parameter `", resp.h.code(par.name), "' is required but not supplied.")) return callable(**args) + wrapper.__wrapped__ = callable return wrapper