From: Ben Pfaff Date: Mon, 22 Aug 2011 23:49:53 +0000 (-0700) Subject: python: Take advantage of Python "x < y < z" syntax. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d272c10ecdba8a5dc7adba30c98d8d4273dfd1ae;p=openvswitch python: Take advantage of Python "x < y < z" syntax. Suggested-by: Reid Price --- diff --git a/lib/ovsdb-types.c b/lib/ovsdb-types.c index b3452dd8..959f0875 100644 --- a/lib/ovsdb-types.c +++ b/lib/ovsdb-types.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010 Nicira Networks +/* Copyright (c) 2009, 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. @@ -556,7 +556,6 @@ ovsdb_type_is_valid(const struct ovsdb_type *type) && ovsdb_base_type_is_valid(&type->key) && ovsdb_base_type_is_valid(&type->value) && type->n_min <= 1 - && type->n_min <= type->n_max && type->n_max >= 1); } diff --git a/python/ovs/db/data.py b/python/ovs/db/data.py index 531d5338..551eef17 100644 --- a/python/ovs/db/data.py +++ b/python/ovs/db/data.py @@ -402,7 +402,7 @@ class Datum(object): def conforms_to_type(self): n = len(self.values) - return n >= self.type.n_min and n <= self.type.n_max + return self.type.n_min <= n <= self.type.n_max def cInitDatum(self, var): if len(self.values) == 0: diff --git a/python/ovs/db/parser.py b/python/ovs/db/parser.py index 8858f00f..073f7606 100644 --- a/python/ovs/db/parser.py +++ b/python/ovs/db/parser.py @@ -1,4 +1,4 @@ -# 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. @@ -67,7 +67,7 @@ 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 diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py index ded9f5f7..635922f5 100644 --- a/python/ovs/db/types.py +++ b/python/ovs/db/types.py @@ -141,7 +141,7 @@ class BaseType(object): value = default else: max_value = 2**32 - 1 - if value < 0 or value > max_value: + if not (0 <= value <= max_value): raise error.Error("%s out of valid range 0 to %d" % (name, max_value), value) return value @@ -396,9 +396,7 @@ class Type(object): return (self.key.type != VoidType and self.key.is_valid() and (self.value is None or (self.value.type != VoidType and self.value.is_valid())) and - self.n_min <= 1 and - self.n_min <= self.n_max and - self.n_max >= 1) + self.n_min <= 1 <= self.n_max) def is_scalar(self): return self.n_min == 1 and self.n_max == 1 and not self.value @@ -423,7 +421,7 @@ class Type(object): def __n_from_json(json, default): if json is None: return default - elif type(json) == int and json >= 0 and json <= sys.maxint: + elif type(json) == int and 0 <= json <= sys.maxint: return json else: raise error.Error("bad min or max value", json)