summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-08-22 16:49:53 -0700
committerBen Pfaff <blp@nicira.com>2011-08-24 11:57:42 -0700
commitd272c10ecdba8a5dc7adba30c98d8d4273dfd1ae (patch)
treefd5973a79ab4a649e886fd570c50b8893c8f3ffe
parentf2d8ad13e1819a6553b30ba33a28abf7603f5b9b (diff)
downloadopenvswitch-d272c10ecdba8a5dc7adba30c98d8d4273dfd1ae.tar.gz
python: Take advantage of Python "x < y < z" syntax.
Suggested-by: Reid Price <reid@nicira.com>
-rw-r--r--lib/ovsdb-types.c3
-rw-r--r--python/ovs/db/data.py2
-rw-r--r--python/ovs/db/parser.py4
-rw-r--r--python/ovs/db/types.py8
4 files changed, 7 insertions, 10 deletions
diff --git a/lib/ovsdb-types.c b/lib/ovsdb-types.c
index b3452dd83..959f08754 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 531d5338e..551eef17c 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 8858f00ff..073f76062 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 ded9f5f71..635922f50 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)