else:
class_ = "set"
- inner = ovs.db.parser.unwrap_json(json, class_, list)
+ inner = ovs.db.parser.unwrap_json(json, class_, [list, tuple],
+ "array")
n = len(inner)
if n < type_.n_min or n > type_.n_max:
raise error.Error("%s must have %d to %d members but %d are "
else:
return "<invalid>"
-def unwrap_json(json, name, need_type):
- if (type(json) != list or len(json) != 2 or json[0] != name or
- type(json[1]) != need_type):
- raise error.Error('expected ["%s", <%s>]'
- % (name, json_type_to_string(need_type)), json)
+def unwrap_json(json, name, types, desc):
+ if (type(json) not in (list, tuple) or len(json) != 2 or json[0] != name or
+ type(json[1]) not in types):
+ raise error.Error('expected ["%s", <%s>]' % (name, desc), json)
return json[1]
def parse_json_pair(json):
def from_json(json):
parser = ovs.db.parser.Parser(json, "database schema")
name = parser.get("name", ['id'])
- version = parser.get_optional("version", [unicode])
- parser.get_optional("cksum", [unicode])
+ version = parser.get_optional("version", [str, unicode])
+ parser.get_optional("cksum", [str, unicode])
tablesJson = parser.get("tables", [dict])
parser.finish()
@staticmethod
def from_json(json):
parser = ovs.db.parser.Parser(json, "IDL schema")
- idlPrefix = parser.get("idlPrefix", [unicode])
- idlHeader = parser.get("idlHeader", [unicode])
+ idlPrefix = parser.get("idlPrefix", [str, unicode])
+ idlHeader = parser.get("idlHeader", [str, unicode])
subjson = dict(json)
del subjson["idlPrefix"]
parser = ovs.db.parser.Parser(json, "schema for column %s" % name)
mutable = parser.get_optional("mutable", [bool], True)
ephemeral = parser.get_optional("ephemeral", [bool], False)
- type_ = types.Type.from_json(parser.get("type", [dict, unicode]))
+ type_ = types.Type.from_json(parser.get("type", [dict, str, unicode]))
parser.finish()
return ColumnSchema(name, mutable, not ephemeral, type_)
@staticmethod
def from_json(json):
- if type(json) == unicode:
+ if type(json) in [str, unicode]:
return BaseType(AtomicType.from_json(json))
parser = ovs.db.parser.Parser(json, "ovsdb type")
return Type(BaseType.from_json(json))
parser = ovs.db.parser.Parser(json, "ovsdb type")
- key_json = parser.get("key", [dict, unicode])
- value_json = parser.get_optional("value", [dict, unicode])
+ key_json = parser.get("key", [dict, str, unicode])
+ value_json = parser.get_optional("value", [dict, str, unicode])
min_json = parser.get_optional("min", [int])
max_json = parser.get_optional("max", [int, str, unicode])
parser.finish()
def from_json(json, symtab=None):
try:
- s = ovs.db.parser.unwrap_json(json, "uuid", unicode)
+ s = ovs.db.parser.unwrap_json(json, "uuid", [str, unicode], "string")
if not uuidRE.match(s):
raise error.Error("\"%s\" is not a valid UUID" % s, json)
return uuid.UUID(s)
if not symtab:
raise e
try:
- name = ovs.db.parser.unwrap_json(json, "named-uuid", unicode)
+ name = ovs.db.parser.unwrap_json(json, "named-uuid",
+ [str, unicode], "string")
except error.Error:
raise e