Move the missing argument verification in a wsme.runtime module so that it can be used in all adapters
This commit is contained in:
@@ -9,6 +9,7 @@ from wsme.exc import ClientSideError, UnknownArgument
|
||||
from wsme.types import iscomplex, list_attributes, Unset
|
||||
from wsme.types import UserType, ArrayType, DictType, File
|
||||
from wsme.utils import parse_isodate, parse_isotime, parse_isodatetime
|
||||
import wsme.runtime
|
||||
|
||||
ARRAY_MAX_SIZE = 1000
|
||||
|
||||
@@ -273,8 +274,10 @@ def get_args(funcdef, args, kwargs, params, form, body, mimetype):
|
||||
(from_params, from_form_params, from_body)
|
||||
)
|
||||
|
||||
return combine_args(
|
||||
args, kwargs = combine_args(
|
||||
funcdef,
|
||||
(from_args, from_params_and_body),
|
||||
allow_override=True
|
||||
)
|
||||
wsme.runtime.check_arguments(funcdef, args, kwargs)
|
||||
return args, kwargs
|
||||
|
||||
@@ -6,6 +6,7 @@ from wsme.protocol import CallContext, Protocol
|
||||
|
||||
import wsme.rest
|
||||
import wsme.rest.args
|
||||
import wsme.runtime
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -120,7 +121,7 @@ class RestProtocol(Protocol):
|
||||
(wsme.rest.args.args_from_params(funcdef, request.params),
|
||||
wsme.rest.args.args_from_body(funcdef, body, context.inmime))
|
||||
)
|
||||
assert len(args) == 0
|
||||
wsme.runtime.check_arguments(funcdef, args, kwargs)
|
||||
return kwargs
|
||||
|
||||
def encode_result(self, context, result):
|
||||
|
||||
@@ -7,7 +7,7 @@ import six
|
||||
|
||||
import webob
|
||||
|
||||
from wsme.exc import ClientSideError, MissingArgument, UnknownFunction
|
||||
from wsme.exc import ClientSideError, UnknownFunction
|
||||
from wsme.protocol import getprotocol
|
||||
from wsme.rest import scan_api
|
||||
from wsme import spore
|
||||
@@ -180,10 +180,6 @@ class WSRoot(object):
|
||||
kw = protocol.read_arguments(context)
|
||||
args = list(args)
|
||||
|
||||
for arg in context.funcdef.arguments:
|
||||
if arg.mandatory and arg.name not in kw:
|
||||
raise MissingArgument(arg.name)
|
||||
|
||||
txn = self.begin()
|
||||
try:
|
||||
result = context.func(*args, **kw)
|
||||
|
||||
9
wsme/runtime.py
Normal file
9
wsme/runtime.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from wsme.exc import MissingArgument
|
||||
|
||||
|
||||
def check_arguments(funcdef, args, kw):
|
||||
"""Check if some arguments are missing"""
|
||||
assert len(args) == 0
|
||||
for arg in funcdef.arguments:
|
||||
if arg.mandatory and arg.name not in kw:
|
||||
raise MissingArgument(arg.name)
|
||||
Reference in New Issue
Block a user