From e4b852292ff53a147b7a6e86e87b3ced6d0d4da4 Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Wed, 24 Oct 2012 21:17:59 +0200 Subject: [PATCH] Cornice extension: Fix function args preparation, and choose the renderer based on the 'Accept' header --- wsme/cornice.py | 6 +++++- wsme/protocols/commons.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/wsme/cornice.py b/wsme/cornice.py index cac557f..36d653c 100644 --- a/wsme/cornice.py +++ b/wsme/cornice.py @@ -68,10 +68,14 @@ def wsexpose(*args, **kwargs): @functools.wraps(f) def callfunction(request): args, kwargs = combine_args( + funcdef, args_from_params(funcdef, request.params), args_from_body(funcdef, request.body, request.content_type) ) - request.override_renderer = 'wsmexml' + if 'application/json' in request.headers['Accept']: + request.override_renderer = 'wsmejson' + elif 'text/xml' in request.headers['Accept']: + request.override_renderer = 'wsmexml' return { 'datatype': funcdef.return_type, 'result': f(*args, **kwargs) diff --git a/wsme/protocols/commons.py b/wsme/protocols/commons.py index d377110..8f7e68c 100644 --- a/wsme/protocols/commons.py +++ b/wsme/protocols/commons.py @@ -137,7 +137,7 @@ def args_from_params(funcdef, params): unknown_paths = paths - hit_paths if unknown_paths: raise UnknownArgument(', '.join(unknown_paths)) - return kw + return [], kw def args_from_body(funcdef, body, mimetype):