

def basic_type_check(self, msg, types_info):
    ' Performs basic typechecking on fields in msg.\n\n        Keyword arguments:\n        msg        -- a message, deserialized into a dictoinary\n        types_info -- a list of tuples (mandatory, fieldname, fieldtype) where\n                mandatory - boolean, is the field mandatory\n                fieldname - the name of the field in the message\n                fieldtypes - the expected python type of the field or list of types\n\n        Throws:\n        MissingArgumentException -- if a field is mandatory but not present in\n        the message\n        InvalidArgumentException -- if a field is present but not of the type\n        specified by fieldtype\n\n        '
    for (mandatory, fieldname, fieldtypes) in types_info:
        if (mandatory and (fieldname not in msg)):
            raise MissingArgumentException(('Expected a %s field but none was found.' % fieldname))
        elif (fieldname in msg):
            if (not isinstance(fieldtypes, tuple)):
                fieldtypes = (fieldtypes,)
            valid = False
            for typ in fieldtypes:
                if isinstance(msg[fieldname], typ):
                    valid = True
            if (not typ):
                raise InvalidArgumentException(('Expected field %s to be one of %s. Invalid value: %s' % (fieldname, fieldtypes, msg[fieldname])))

dataset/ETHPy150Open RobotWebTools/rosbridge_suite/rosbridge_library/src/rosbridge_library/capability.py Capability.basic_type_check/VarMisuse@117/385 `valid`->`typ`