def from_json(base, json, symtab=None):
type_ = base.type
json = ovs.db.parser.float_to_int(json)
- if ((type_ == ovs.db.types.IntegerType and type(json) in [int, long])
+ real_types = list(six.integer_types)
+ real_types.extend([float])
+ real_types = tuple(real_types)
+ if ((type_ == ovs.db.types.IntegerType
+ and isinstance(json, six.integer_types))
or (type_ == ovs.db.types.RealType
- and type(json) in [int, long, float])
- or (type_ == ovs.db.types.BooleanType and type(json) == bool)
+ and isinstance(json, real_types))
+ or (type_ == ovs.db.types.BooleanType and isinstance(json, bool))
or (type_ == ovs.db.types.StringType
- and type(json) in [str, unicode])):
+ and isinstance(json, (str, unicode)))):
atom = Atom(type_, json)
elif type_ == ovs.db.types.UuidType:
atom = Atom(type_, ovs.ovsuuid.from_json(json, symtab))
@staticmethod
def new(x):
- if type(x) in [int, long]:
+ if isinstance(x, six.integer_types):
t = ovs.db.types.IntegerType
- elif type(x) == float:
+ elif isinstance(x, float):
t = ovs.db.types.RealType
- elif x in [False, True]:
+ elif isinstance(x, bool):
t = ovs.db.types.BooleanType
- elif type(x) in [str, unicode]:
+ elif isinstance(x, (str, unicode)):
t = ovs.db.types.StringType
elif isinstance(x, uuid):
t = ovs.db.types.UuidType
# __process_reply() already checked.
mutate = ops[self._inc_index]
count = mutate.get("count")
- if not Transaction.__check_json_type(count, (int, long),
+ if not Transaction.__check_json_type(count, six.integer_types,
'"mutate" reply "count"'):
return False
if count != 1:
'"select" reply row'):
return False
column = row.get(self._inc_column)
- if not Transaction.__check_json_type(column, (int, long),
+ if not Transaction.__check_json_type(column, six.integer_types,
'"select" reply inc column'):
return False
self._inc_new_value = column
import re
+import six
+
from ovs.db import error
def json_type_to_string(type_):
+ number_types = list(six.integer_types)
+ number_types.extend([float])
+ number_types = tuple(number_types)
if type_ is None:
return "null"
- elif type_ == bool:
+ elif issubclass(type_, bool):
return "boolean"
- elif type_ == dict:
+ elif issubclass(type_, dict):
return "object"
- elif type_ == list:
+ elif issubclass(type_, list):
return "array"
- elif type_ in [int, long, float]:
+ elif issubclass(type_, number_types):
return "number"
- elif type_ in [str, unicode]:
+ elif issubclass(type_, (str, unicode)):
return "string"
else:
return "<invalid>"
import sys
import uuid
+import six
+
from ovs.db import error
import ovs.db.parser
import ovs.db.data
def default_atom(self):
return ovs.db.data.Atom(self, self.default)
+REAL_PYTHON_TYPES = list(six.integer_types)
+REAL_PYTHON_TYPES.extend([float])
+REAL_PYTHON_TYPES = tuple(REAL_PYTHON_TYPES)
+
VoidType = AtomicType("void", None, ())
-IntegerType = AtomicType("integer", 0, (int, long))
-RealType = AtomicType("real", 0.0, (int, long, float))
+IntegerType = AtomicType("integer", 0, six.integer_types)
+RealType = AtomicType("real", 0.0, REAL_PYTHON_TYPES)
BooleanType = AtomicType("boolean", False, (bool,))
StringType = AtomicType("string", "", (str, unicode))
UuidType = AtomicType("uuid", ovs.ovsuuid.zero(), (uuid.UUID,))
@staticmethod
def __parse_uint(parser, name, default):
- value = parser.get_optional(name, [int, long])
+ value = parser.get_optional(name, six.integer_types)
if value is None:
value = default
else:
base.enum = ovs.db.data.Datum.from_json(
BaseType.get_enum_type(base.type), enum)
elif base.type == IntegerType:
- base.min = parser.get_optional("minInteger", [int, long])
- base.max = parser.get_optional("maxInteger", [int, long])
+ base.min = parser.get_optional("minInteger", six.integer_types)
+ base.max = parser.get_optional("maxInteger", six.integer_types)
if (base.min is not None and base.max is not None
and base.min > base.max):
raise error.Error("minInteger exceeds maxInteger", json)
elif base.type == RealType:
- base.min = parser.get_optional("minReal", [int, long, float])
- base.max = parser.get_optional("maxReal", [int, long, float])
+ base.min = parser.get_optional("minReal", REAL_PYTHON_TYPES)
+ base.max = parser.get_optional("maxReal", REAL_PYTHON_TYPES)
if (base.min is not None and base.max is not None
and base.min > base.max):
raise error.Error("minReal exceeds maxReal", json)
self.stream.write(u"false")
elif obj is True:
self.stream.write(u"true")
- elif type(obj) in (int, long):
+ elif isinstance(obj, six.integer_types):
self.stream.write(u"%d" % obj)
- elif type(obj) == float:
+ elif isinstance(obj, float):
self.stream.write("%.15g" % obj)
- elif type(obj) == unicode:
+ elif isinstance(obj, unicode):
self.__serialize_string(obj)
- elif type(obj) == str:
+ elif isinstance(obj, str):
self.__serialize_string(unicode(obj))
- elif type(obj) == dict:
+ elif isinstance(obj, dict):
self.stream.write(u"{")
self.depth += 1
self.stream.write(u"}")
self.depth -= 1
- elif type(obj) in (list, tuple):
+ elif isinstance(obj, (list, tuple)):
self.stream.write(u"[")
self.depth += 1
if m:
sign, integer, fraction, exp = m.groups()
if (exp is not None and
- (long(exp) > sys.maxint or long(exp) < -sys.maxint - 1)):
+ (int(exp) > sys.maxint or int(exp) < -sys.maxint - 1)):
self.__error("exponent outside valid range")
return
if fraction is not None:
pow10 -= len(fraction)
if exp is not None:
- pow10 += long(exp)
+ pow10 += int(exp)
if significand == 0:
self.__parser_input(0)
self.parse_state = Parser.__parse_object_next
def __parse_value(self, token, string, next_state):
- if token in [False, None, True] or type(token) in [int, long, float]:
+ number_types = list(six.integer_types)
+ number_types.extend([float])
+ number_types = tuple(number_types)
+ if token in [False, None, True] or isinstance(token, number_types):
self.__put_value(token)
elif token == 'string':
self.__put_value(string)
raise argparse.ArgumentTypeError("Not a valid target bandwidth")
bwidth = string.replace("M", "000000")
bwidth = bwidth.replace("K", "000")
- return long(bwidth) / 8 # Convert from bits to bytes
+ return int(bwidth) / 8 # Convert from bits to bytes
def tunnel_types(string):
time.sleep(duration + 1)
- rcv_bytes = long(server1.get_tcp_listener_results(listen_handle))
- snt_bytes = long(server2.get_tcp_sender_results(send_handle))
+ rcv_bytes = int(server1.get_tcp_listener_results(listen_handle))
+ snt_bytes = int(server2.get_tcp_sender_results(send_handle))
bwidth = rcv_bytes / duration