From patchwork Mon Dec 21 20:47:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Russell Bryant X-Patchwork-Id: 559723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id BA95C140BB2 for ; Tue, 22 Dec 2015 07:52:48 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 25E6A1077B; Mon, 21 Dec 2015 12:48:34 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 9F10F1076D for ; Mon, 21 Dec 2015 12:48:32 -0800 (PST) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 2D7FC1E0104 for ; Mon, 21 Dec 2015 13:48:32 -0700 (MST) X-ASG-Debug-ID: 1450730911-09eadd632cc6770001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id Ow9yCTp2so4RZTfL (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 21 Dec 2015 13:48:31 -0700 (MST) X-Barracuda-Envelope-From: russell@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 21 Dec 2015 20:48:31 -0000 Received-SPF: neutral (mx1-pf2.cudamail.com: 209.132.183.28 is neither permitted nor denied by SPF record at ovn.org) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 7789E68E15; Mon, 21 Dec 2015 20:48:30 +0000 (UTC) Received: from x1c.redhat.com ([10.3.112.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBLKm0dn002018; Mon, 21 Dec 2015 15:48:29 -0500 X-CudaMail-Envelope-Sender: russell@ovn.org From: Russell Bryant To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E2-1220082818 X-CudaMail-DTE: 122115 X-CudaMail-Originating-IP: 209.132.183.28 Date: Mon, 21 Dec 2015 15:47:26 -0500 X-ASG-Orig-Subj: [##CM-E2-1220082818##][PATCH 26/55] python: Drop use of sys.maxint. Message-Id: <1450730875-18083-27-git-send-email-russell@ovn.org> In-Reply-To: <1450730875-18083-1-git-send-email-russell@ovn.org> References: <1450730875-18083-1-git-send-email-russell@ovn.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1450730911 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 26/55] python: Drop use of sys.maxint. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" 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. This is also the final change needed to make the Python 3.4 test environment pass successfully (tox -e py34). Signed-off-by: Russell Bryant --- 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 1c492f8..28b14d3 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 @@ class TableSchema(object): 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 @@ class TableSchema(object): 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 f4d1f90..944372e 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 @@ class BaseType(object): 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 @@ class BaseType(object): 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 @@ class BaseType(object): 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 @@ class BaseType(object): 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 @@ class BaseType(object): 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 @@ class BaseType(object): 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 @@ class BaseType(object): 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 @@ class Type(object): 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 @@ class Type(object): 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 @@ class Type(object): 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 @@ class Type(object): 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 @@ class Type(object): 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 fc8e80e..a59a0c2 100644 --- a/python/ovs/json.py +++ b/python/ovs/json.py @@ -254,7 +254,7 @@ class Parser(object): 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 d164900..b41f2f0 100644 --- a/python/ovs/vlog.py +++ b/python/ovs/vlog.py @@ -241,7 +241,7 @@ class Vlog(object): 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)