-# Copyright (c) 2010 Nicira Networks
+# Copyright (c) 2010, 2011 Nicira Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
if missing:
name = missing.pop()
if len(missing) > 1:
- self.__raise_error("Member '%s' and %d other members "
- "are present but not allowed here"
- % (name, len(missing)))
+ present = "and %d other members are" % len(missing)
elif missing:
- self.__raise_error("Member '%s' and 1 other member "
- "are present but not allowed here" % name)
+ present = "and 1 other member are"
else:
- self.__raise_error("Member '%s' is present but not "
- "allowed here" % name)
+ present = "is"
+ self.__raise_error("Member '%s' %s present but not allowed here" %
+ (name, present))
def float_to_int(x):
# XXX still needed?
if type(x) == float:
integer = int(x)
- if integer == x and integer >= -2**53 and integer < 2**53:
+ if integer == x and -2**53 <= integer < 2**53:
return integer
return x
def is_identifier(s):
return type(s) in [str, unicode] and id_re.match(s)
-def json_type_to_string(type):
- if type == None:
+def json_type_to_string(type_):
+ if type_ == None:
return "null"
- elif type == bool:
+ elif type_ == bool:
return "boolean"
- elif type == dict:
+ elif type_ == dict:
return "object"
- elif type == list:
+ elif type_ == list:
return "array"
- elif type in [int, long, float]:
+ elif type_ in [int, long, float]:
return "number"
- elif type in [str, unicode]:
+ elif type_ in [str, unicode]:
return "string"
else:
return "<invalid>"