mirror of
https://github.com/openvswitch/ovs
synced 2025-10-17 14:28:02 +00:00
python: Take advantage of Python "x < y < z" syntax.
Suggested-by: Reid Price <reid@nicira.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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:
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user