Cornice extension: Fix function args preparation, and choose the renderer based on the 'Accept' header

This commit is contained in:
Christophe de Vienne 2012-10-24 21:17:59 +02:00
parent 0b2cf8df04
commit e4b852292f
2 changed files with 6 additions and 2 deletions

View File

@ -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)

View File

@ -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):