Flask simple call now works
This commit is contained in:
parent
5f99ad0edd
commit
4ba5ce042a
@ -1,14 +1,21 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
import wsme
|
import wsme
|
||||||
import wsme.api
|
import wsme.api
|
||||||
|
import wsme.rest.json
|
||||||
|
import wsme.rest.xml
|
||||||
from wsme.rest.args import (
|
from wsme.rest.args import (
|
||||||
args_from_params, args_from_body, combine_args
|
args_from_params, args_from_body, combine_args
|
||||||
)
|
)
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def signature(*args, **kw):
|
def signature(*args, **kw):
|
||||||
sig = wsme.signature(*args, **kw)
|
sig = wsme.signature(*args, **kw)
|
||||||
@ -18,14 +25,39 @@ def signature(*args, **kw):
|
|||||||
funcdef = wsme.api.FunctionDefinition.get(f)
|
funcdef = wsme.api.FunctionDefinition.get(f)
|
||||||
|
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
def wrapper(*args, **kw):
|
def wrapper(*args, **kwargs):
|
||||||
args, kwargs = combine_args(
|
args, kwargs = wsme.rest.args.get_args(
|
||||||
funcdef,
|
funcdef, args, kwargs, flask.request.args, flask.request.data,
|
||||||
args_from_params(funcdef, flask.request.args),
|
flask.request.content_type
|
||||||
args_from_body(funcdef, flask.request.data, flask.request.content_type)
|
|
||||||
)
|
)
|
||||||
resp = make_response(f(*args, **kw))
|
print args, kwargs
|
||||||
return resp
|
|
||||||
|
dataformat = None
|
||||||
|
if 'Accept' in flask.request.headers:
|
||||||
|
if 'application/json' in flask.request.headers['Accept']:
|
||||||
|
dataformat = wsme.rest.json
|
||||||
|
elif 'text/xml' in flask.request.headers['Accept']:
|
||||||
|
dataformat = wsme.rest.xml
|
||||||
|
if dataformat is None:
|
||||||
|
log.info('''Could not determine what format is wanted by the
|
||||||
|
caller, falling back to json''')
|
||||||
|
dataformat = wsme.rest.json
|
||||||
|
try:
|
||||||
|
res = flask.make_response(
|
||||||
|
dataformat.encode_result(
|
||||||
|
f(*args, **kwargs),
|
||||||
|
funcdef.return_type
|
||||||
|
)
|
||||||
|
)
|
||||||
|
res.mimetype = dataformat.content_type
|
||||||
|
except:
|
||||||
|
data = wsme.api.format_exception(sys.exc_info())
|
||||||
|
res = flask.make_response(dataformat.encode_error(data))
|
||||||
|
if data['faultcode']:
|
||||||
|
res.status = 400
|
||||||
|
else:
|
||||||
|
res.status = 500
|
||||||
|
return res
|
||||||
|
|
||||||
wrapper.wsme_func = f
|
wrapper.wsme_func = f
|
||||||
return wrapper
|
return wrapper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user