From d36bbd37f6da56f7999f4978d9c471a49b6a2b02 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Tue, 15 Dec 2015 16:37:11 -0500 Subject: [PATCH] python: Drop use of sys.maxint. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sys.maxint does not exist in Python 3, as an int does not have a max value anymore (except as limited by implementation details and system resources). sys.maxsize works as a reasonable substitute as it's the same as sys.maxint. The Python 3.0 release notes have this to say: The sys.maxint constant was removed, since there is no longer a limit to the value of integers. However, sys.maxsize can be used as an integer larger than any practical list or string index. It conforms to the implementation’s “natural” integer size and is typically the same as sys.maxint in previous releases on the same platform (assuming the same build options). sys.maxsize is documented as: An integer giving the maximum value a variable of type Py_ssize_t can take. It’s usually 2**31 - 1 on a 32-bit platform and 2**63 - 1 on a 64-bit platform. Signed-off-by: Russell Bryant Acked-by: Ben Pfaff --- python/ovs/db/schema.py | 6 +++--- python/ovs/db/types.py | 26 +++++++++++++------------- python/ovs/json.py | 2 +- python/ovs/vlog.py | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py index 1c492f8e670..28b14d340df 100644 --- a/python/ovs/db/schema.py +++ b/python/ovs/db/schema.py @@ -165,7 +165,7 @@ def column_set_from_json(json, columns): class TableSchema(object): - def __init__(self, name, columns, mutable=True, max_rows=sys.maxint, + def __init__(self, name, columns, mutable=True, max_rows=sys.maxsize, is_root=True, indexes=[]): self.name = name self.columns = columns @@ -185,7 +185,7 @@ def from_json(json, name): parser.finish() if max_rows is None: - max_rows = sys.maxint + max_rows = sys.maxsize elif max_rows <= 0: raise error.Error("maxRows must be at least 1", json) @@ -236,7 +236,7 @@ def to_json(self, default_is_root=False): if not column.name.startswith("_"): columns[column.name] = column.to_json() - if self.max_rows != sys.maxint: + if self.max_rows != sys.maxsize: json["maxRows"] = self.max_rows if self.indexes: diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py index f4d1f90e29e..944372ee2a1 100644 --- a/python/ovs/db/types.py +++ b/python/ovs/db/types.py @@ -119,7 +119,7 @@ def returnUnchanged(x): class BaseType(object): def __init__(self, type_, enum=None, min=None, max=None, - min_length=0, max_length=sys.maxint, ref_table_name=None): + min_length=0, max_length=sys.maxsize, ref_table_name=None): assert isinstance(type_, AtomicType) self.type = type_ self.enum = enum @@ -194,7 +194,7 @@ def from_json(json): elif base.type == StringType: base.min_length = BaseType.__parse_uint(parser, "minLength", 0) base.max_length = BaseType.__parse_uint(parser, "maxLength", - sys.maxint) + sys.maxsize) if base.min_length > base.max_length: raise error.Error("minLength exceeds maxLength", json) elif base.type == UuidType: @@ -232,7 +232,7 @@ def to_json(self): elif self.type == StringType: if self.min_length != 0: json['minLength'] = self.min_length - if self.max_length != sys.maxint: + if self.max_length != sys.maxsize: json['maxLength'] = self.max_length elif self.type == UuidType: if self.ref_table_name: @@ -260,7 +260,7 @@ def is_valid(self): def has_constraints(self): return (self.enum is not None or self.min is not None or self.max is not None or - self.min_length != 0 or self.max_length != sys.maxint or + self.min_length != 0 or self.max_length != sys.maxsize or self.ref_table_name is not None) def without_constraints(self): @@ -270,7 +270,7 @@ def without_constraints(self): def get_enum_type(atomic_type): """Returns the type of the 'enum' member for a BaseType whose 'type' is 'atomic_type'.""" - return Type(BaseType(atomic_type), None, 1, sys.maxint) + return Type(BaseType(atomic_type), None, 1, sys.maxsize) def is_ref(self): return self.type == UuidType and self.ref_table_name is not None @@ -322,7 +322,7 @@ def constraintsToEnglish(self, escapeLiteral=returnUnchanged, english = 'at most %s' % escapeNumber(commafy(self.max)) else: english = 'at most %s' % escapeNumber("%g" % self.max) - elif self.min_length != 0 and self.max_length != sys.maxint: + elif self.min_length != 0 and self.max_length != sys.maxsize: if self.min_length == self.max_length: english = ('exactly %s characters long' % commafy(self.min_length)) @@ -332,7 +332,7 @@ def constraintsToEnglish(self, escapeLiteral=returnUnchanged, commafy(self.max_length))) elif self.min_length != 0: return 'at least %s characters long' % commafy(self.min_length) - elif self.max_length != sys.maxint: + elif self.max_length != sys.maxsize: english = 'at most %s characters long' % commafy(self.max_length) else: english = '' @@ -407,7 +407,7 @@ def cInitBaseType(self, indent, var): if self.min_length is not None: stmts.append('%s.u.string.minLen = %d;' % (var, self.min_length)) - if self.max_length != sys.maxint: + if self.max_length != sys.maxsize: stmts.append('%s.u.string.maxLen = %d;' % (var, self.max_length)) elif self.type == UuidType: @@ -482,7 +482,7 @@ def is_optional_pointer(self): def __n_from_json(json, default): if json is None: return default - elif type(json) == int and 0 <= json <= sys.maxint: + elif isinstance(json, int) and 0 <= json <= sys.maxsize: return json else: raise error.Error("bad min or max value", json) @@ -512,7 +512,7 @@ def from_json(json): n_min = Type.__n_from_json(min_json, Type.DEFAULT_MIN) if max_json == 'unlimited': - n_max = sys.maxint + n_max = sys.maxsize else: n_max = Type.__n_from_json(max_json, Type.DEFAULT_MAX) @@ -530,7 +530,7 @@ def to_json(self): json["value"] = self.value.to_json() if self.n_min != Type.DEFAULT_MIN: json["min"] = self.n_min - if self.n_max == sys.maxint: + if self.n_max == sys.maxsize: json["max"] = "unlimited" elif self.n_max != Type.DEFAULT_MAX: json["max"] = self.n_max @@ -549,7 +549,7 @@ def toEnglish(self, escapeLiteral=returnUnchanged): else: return "optional %s" % keyName else: - if self.n_max == sys.maxint: + if self.n_max == sys.maxsize: if self.n_min: quantity = "%s or more " % commafy(self.n_min) else: @@ -602,7 +602,7 @@ def cInitType(self, indent, var): initValue = ('%sovsdb_base_type_init(&%s.value, ' 'OVSDB_TYPE_VOID);' % (indent, var)) initMin = "%s%s.n_min = %s;" % (indent, var, self.n_min) - if self.n_max == sys.maxint: + if self.n_max == sys.maxsize: n_max = "UINT_MAX" else: n_max = self.n_max diff --git a/python/ovs/json.py b/python/ovs/json.py index fc8e80e2e7a..a59a0c2f9b4 100644 --- a/python/ovs/json.py +++ b/python/ovs/json.py @@ -254,7 +254,7 @@ def __lex_finish_number(self): if m: sign, integer, fraction, exp = m.groups() if (exp is not None and - (int(exp) > sys.maxint or int(exp) < -sys.maxint - 1)): + (int(exp) > sys.maxsize or int(exp) < -sys.maxsize - 1)): self.__error("exponent outside valid range") return diff --git a/python/ovs/vlog.py b/python/ovs/vlog.py index d164900b4d5..b41f2f07870 100644 --- a/python/ovs/vlog.py +++ b/python/ovs/vlog.py @@ -241,7 +241,7 @@ def init(log_file=None): ovs.unixctl.command_register("vlog/reopen", "", 0, 0, Vlog._unixctl_vlog_reopen, None) - ovs.unixctl.command_register("vlog/set", "spec", 1, sys.maxint, + ovs.unixctl.command_register("vlog/set", "spec", 1, sys.maxsize, Vlog._unixctl_vlog_set, None) ovs.unixctl.command_register("vlog/list", "", 0, 0, Vlog._unixctl_vlog_list, None)