Ejemplo n.º 1
0
def args_from_params(funcdef, params):
    kw = {}
    hit_paths = set()
    for argdef in funcdef.arguments:
        value = from_params(argdef.datatype, params, argdef.name, hit_paths)
        if value is not Unset:
            kw[argdef.name] = value
    paths = set(params.keys())
    unknown_paths = paths - hit_paths
    if '__body__' in unknown_paths:
        unknown_paths.remove('__body__')
    if not funcdef.ignore_extra_args and unknown_paths:
        raise UnknownArgument(', '.join(unknown_paths))
    return [], kw
Ejemplo n.º 2
0
def parse(s, datatypes, bodyarg):
    if hasattr(s, 'read'):
        tree = et.parse(s)
    else:
        tree = et.fromstring(s)
    if bodyarg:
        name = list(datatypes.keys())[0]
        return {name: fromxml(datatypes[name], tree)}
    else:
        kw = {}
        extra_args = []
        for sub in tree:
            if sub.tag not in datatypes:
                extra_args.append(sub.tag)
            kw[sub.tag] = fromxml(datatypes[sub.tag], sub)
        if extra_args:
            raise UnknownArgument(', '.join(extra_args))
        return kw
Ejemplo n.º 3
0
def parse(s, datatypes, bodyarg, encoding='utf8'):
    if hasattr(s, 'read'):
        jdata = json.load(s)
    else:
        if six.PY3 and isinstance(s, six.binary_type):
            s = s.decode(encoding)
        jdata = json.loads(s)
    if bodyarg:
        argname = list(datatypes.keys())[0]
        kw = {argname: fromjson(datatypes[argname], jdata)}
    else:
        kw = {}
        extra_args = []
        for key in jdata:
            if key not in datatypes:
                extra_args.append(key)
            else:
                kw[key] = fromjson(datatypes[key], jdata[key])
        if extra_args:
            raise UnknownArgument(', '.join(extra_args))
    return kw
Ejemplo n.º 4
0
def test_unknownargument():
    e = UnknownArgument('argname', "error message")

    assert e.faultstring == \
        u('Unknown argument: "argname": error message'), e.faultstring