diff options
| author | Timothy Redaelli <tredaelli@redhat.com> | 2019-12-20 18:35:08 +0100 |
|---|---|---|
| committer | Ben Pfaff <blp@ovn.org> | 2019-12-20 12:23:06 -0800 |
| commit | 0c4d144a989a444d038d58272d8571e97e00e86f (patch) | |
| tree | e78d3a01c469f5f1842d3344f86801dcff30e761 /python/ovs/db | |
| parent | 24e6970809483d256c38cfd029ae9469b0d3e961 (diff) | |
| download | openvswitch-0c4d144a989a444d038d58272d8571e97e00e86f.tar.gz | |
Remove dependency on python3-six
Since Python 2 support was removed in 1ca0323e7c29 ("Require Python 3 and
remove support for Python 2."), python3-six is not needed anymore.
Moreover python3-six is not available on RHEL/CentOS7 without using EPEL
and so this patch is needed in order to release OVS 2.13 on RHEL7.
Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'python/ovs/db')
| -rw-r--r-- | python/ovs/db/data.py | 30 | ||||
| -rw-r--r-- | python/ovs/db/idl.py | 60 | ||||
| -rw-r--r-- | python/ovs/db/parser.py | 8 | ||||
| -rw-r--r-- | python/ovs/db/schema.py | 34 | ||||
| -rw-r--r-- | python/ovs/db/types.py | 29 |
5 files changed, 75 insertions, 86 deletions
diff --git a/python/ovs/db/data.py b/python/ovs/db/data.py index 9e57595f7..2a2102d6b 100644 --- a/python/ovs/db/data.py +++ b/python/ovs/db/data.py @@ -25,8 +25,6 @@ import ovs.poller import ovs.socket_util from ovs.db import error -import six - class ConstraintViolation(error.Error): def __init__(self, msg, json=None): @@ -119,16 +117,16 @@ class Atom(object): def from_json(base, json, symtab=None): type_ = base.type json = ovs.db.parser.float_to_int(json) - real_types = list(six.integer_types) + real_types = [int] real_types.extend([float]) real_types = tuple(real_types) if ((type_ == ovs.db.types.IntegerType - and isinstance(json, six.integer_types)) + and isinstance(json, int)) or (type_ == ovs.db.types.RealType and isinstance(json, real_types)) or (type_ == ovs.db.types.BooleanType and isinstance(json, bool)) or (type_ == ovs.db.types.StringType - and isinstance(json, six.string_types))): + and isinstance(json, str))): atom = Atom(type_, json) elif type_ == ovs.db.types.UuidType: atom = Atom(type_, ovs.ovsuuid.from_json(json, symtab)) @@ -251,13 +249,13 @@ class Atom(object): @staticmethod def new(x): - if isinstance(x, six.integer_types): + if isinstance(x, int): t = ovs.db.types.IntegerType elif isinstance(x, float): t = ovs.db.types.RealType elif isinstance(x, bool): t = ovs.db.types.BooleanType - elif isinstance(x, six.string_types): + elif isinstance(x, str): t = ovs.db.types.StringType elif isinstance(x, uuid): t = ovs.db.types.UuidType @@ -320,7 +318,7 @@ class Datum(object): This function is not commonly useful because the most ordinary way to obtain a datum is ultimately via Datum.from_json() or Atom.from_json(), which check constraints themselves.""" - for keyAtom, valueAtom in six.iteritems(self.values): + for keyAtom, valueAtom in self.values.items(): keyAtom.check_constraints(self.type.key) if valueAtom is not None: valueAtom.check_constraints(self.type.value) @@ -381,7 +379,7 @@ class Datum(object): return ["map", [[k.to_json(), v.to_json()] for k, v in sorted(self.values.items())]] elif len(self.values) == 1: - key = next(six.iterkeys(self.values)) + key = next(iter(self.values.keys())) return key.to_json() else: return ["set", [k.to_json() for k in sorted(self.values.keys())]] @@ -415,7 +413,7 @@ class Datum(object): def diff(self, datum): if self.type.n_max > 1 or len(self.values) == 0: - for k, v in six.iteritems(datum.values): + for k, v in datum.values.items(): if k in self.values and v == self.values[k]: del self.values[k] else: @@ -427,9 +425,9 @@ class Datum(object): def as_list(self): if self.type.is_map(): - return [[k.value, v.value] for k, v in six.iteritems(self.values)] + return [[k.value, v.value] for k, v in self.values.items()] else: - return [k.value for k in six.iterkeys(self.values)] + return [k.value for k in self.values.keys()] def as_dict(self): return dict(self.values) @@ -437,10 +435,10 @@ class Datum(object): def as_scalar(self): if len(self.values) == 1: if self.type.is_map(): - k, v = next(six.iteritems(self.values)) + k, v = next(iter(self.values.items())) return [k.value, v.value] else: - return next(six.iterkeys(self.values)).value + return next(iter(self.values.keys())).value else: return None @@ -487,7 +485,7 @@ class Datum(object): return value elif self.type.is_map(): value = {} - for k, v in six.iteritems(self.values): + for k, v in self.values.items(): dk = uuid_to_row(k.value, self.type.key) dv = uuid_to_row(v.value, self.type.value) if dk is not None and dv is not None: @@ -515,7 +513,7 @@ class Datum(object): 'type_'.""" d = {} if isinstance(value, dict): - for k, v in six.iteritems(value): + for k, v in value.items(): ka = Atom.from_python(type_.key, row_to_uuid(k)) va = Atom.from_python(type_.value, row_to_uuid(v)) d[ka] = va diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index d1d91552b..020291d48 100644 --- a/python/ovs/db/idl.py +++ b/python/ovs/db/idl.py @@ -25,8 +25,6 @@ import ovs.vlog from ovs.db import custom_index from ovs.db import error -import six - vlog = ovs.vlog.Vlog("idl") __pychecker__ = 'no-classattr no-objattrs' @@ -171,8 +169,8 @@ class Idl(object): self.txn = None self._outstanding_txns = {} - for table in six.itervalues(schema.tables): - for column in six.itervalues(table.columns): + for table in schema.tables.values(): + for column in table.columns.values(): if not hasattr(column, 'alert'): column.alert = True table.need_table = False @@ -394,7 +392,7 @@ class Idl(object): if not self._session.is_connected(): return - for table in six.itervalues(self.tables): + for table in self.tables.values(): if table.cond_changed: self.__send_cond_change(table, table.condition) table.cond_changed = False @@ -487,7 +485,7 @@ class Idl(object): def __clear(self): changed = False - for table in six.itervalues(self.tables): + for table in self.tables.values(): if table.rows: changed = True table.rows = custom_index.IndexedRows(table) @@ -556,9 +554,9 @@ class Idl(object): method = "monitor" monitor_requests = {} - for table in six.itervalues(self.tables): + for table in self.tables.values(): columns = [] - for column in six.iterkeys(table.columns): + for column in table.columns.keys(): if ((table.name not in self.readonly) or (table.name in self.readonly) and (column not in self.readonly[table.name])): @@ -585,8 +583,8 @@ class Idl(object): self.state = self.IDL_S_SERVER_MONITOR_REQUESTED monitor_requests = {} table = self.server_tables[self._server_db_table] - columns = [column for column in six.iterkeys(table.columns)] - for column in six.itervalues(table.columns): + columns = [column for column in table.columns.keys()] + for column in table.columns.values(): if not hasattr(column, 'alert'): column.alert = True table.rows = custom_index.IndexedRows(table) @@ -616,7 +614,7 @@ class Idl(object): raise error.Error("<table-updates> is not an object", table_updates) - for table_name, table_update in six.iteritems(table_updates): + for table_name, table_update in table_updates.items(): table = tables.get(table_name) if not table: raise error.Error('<table-updates> includes unknown ' @@ -626,7 +624,7 @@ class Idl(object): raise error.Error('<table-update> for table "%s" is not ' 'an object' % table_name, table_update) - for uuid_string, row_update in six.iteritems(table_update): + for uuid_string, row_update in table_update.items(): if not ovs.ovsuuid.is_valid_string(uuid_string): raise error.Error('<table-update> for table "%s" ' 'contains bad UUID "%s" as member ' @@ -755,7 +753,7 @@ class Idl(object): rows = self.server_tables[self._server_db_table].rows database = None - for row in six.itervalues(rows): + for row in rows.values(): if self.cluster_id: if self.cluster_id in \ map(lambda x: str(x)[:4], row.cid): @@ -801,7 +799,7 @@ class Idl(object): return column.type.key.type.default def __add_default(self, table, row_update): - for column in six.itervalues(table.columns): + for column in table.columns.values(): if column.name not in row_update: if ((table.name not in self.readonly) or (table.name in self.readonly) and @@ -811,7 +809,7 @@ class Idl(object): def __apply_diff(self, table, row, row_diff): old_row = {} - for column_name, datum_diff_json in six.iteritems(row_diff): + for column_name, datum_diff_json in row_diff.items(): column = table.columns.get(column_name) if not column: # XXX rate-limit @@ -836,7 +834,7 @@ class Idl(object): def __row_update(self, table, row, row_json): changed = False - for column_name, datum_json in six.iteritems(row_json): + for column_name, datum_json in row_json.items(): column = table.columns.get(column_name) if not column: # XXX rate-limit @@ -864,7 +862,7 @@ class Idl(object): def __create_row(self, table, uuid): data = {} - for column in six.itervalues(table.columns): + for column in table.columns.values(): data[column.name] = ovs.db.data.Datum.default(column.type) return Row(self, table, uuid, data) @@ -1160,7 +1158,7 @@ class Row(object): @classmethod def from_json(cls, idl, table, uuid, row_json): data = {} - for column_name, datum_json in six.iteritems(row_json): + for column_name, datum_json in row_json.items(): column = table.columns.get(column_name) if not column: # XXX rate-limit @@ -1390,7 +1388,7 @@ class Transaction(object): def __disassemble(self): self.idl.txn = None - for row in six.itervalues(self._txn_rows): + for row in self._txn_rows.values(): if row._changes is None: # If we add the deleted row back to rows with _changes == None # then __getattr__ will not work for the indexes @@ -1474,7 +1472,7 @@ class Transaction(object): "lock": self.idl.lock_name}) # Add prerequisites and declarations of new rows. - for row in six.itervalues(self._txn_rows): + for row in self._txn_rows.values(): if row._prereqs: rows = {} columns = [] @@ -1491,7 +1489,7 @@ class Transaction(object): # Add updates. any_updates = False - for row in six.itervalues(self._txn_rows): + for row in self._txn_rows.values(): if row._changes is None: if row._table.is_root: operations.append({"op": "delete", @@ -1517,7 +1515,7 @@ class Transaction(object): row_json = {} op["row"] = row_json - for column_name, datum in six.iteritems(row._changes): + for column_name, datum in row._changes.items(): if row._data is not None or not datum.is_default(): row_json[column_name] = ( self._substitute_uuids(datum.to_json())) @@ -1545,7 +1543,7 @@ class Transaction(object): op["where"] = _where_uuid_equals(row.uuid) op["mutations"] = [] if '_removes' in row._mutations.keys(): - for col, dat in six.iteritems(row._mutations['_removes']): + for col, dat in row._mutations['_removes'].items(): column = row._table.columns[col] if column.type.is_map(): opdat = ["set"] @@ -1566,7 +1564,7 @@ class Transaction(object): op["mutations"].append(mutation) addop = True if '_inserts' in row._mutations.keys(): - for col, val in six.iteritems(row._mutations['_inserts']): + for col, val in row._mutations['_inserts'].items(): column = row._table.columns[col] if column.type.is_map(): opdat = ["map"] @@ -1809,7 +1807,7 @@ class Transaction(object): else: hard_errors = True - for insert in six.itervalues(self._inserted_rows): + for insert in self._inserted_rows.values(): if not self.__process_insert_reply(insert, ops): hard_errors = True @@ -1878,7 +1876,7 @@ class Transaction(object): # __process_reply() already checked. mutate = ops[self._inc_index] count = mutate.get("count") - if not Transaction.__check_json_type(count, six.integer_types, + if not Transaction.__check_json_type(count, (int,), '"mutate" reply "count"'): return False if count != 1: @@ -1901,7 +1899,7 @@ class Transaction(object): '"select" reply row'): return False column = row.get(self._inc_column) - if not Transaction.__check_json_type(column, six.integer_types, + if not Transaction.__check_json_type(column, (int,), '"select" reply inc column'): return False self._inc_new_value = column @@ -1979,7 +1977,7 @@ class SchemaHelper(object): 'readonly' must be a list of strings. """ - assert isinstance(table, six.string_types) + assert isinstance(table, str) assert isinstance(columns, list) columns = set(columns) | self._tables.get(table, set()) @@ -1992,7 +1990,7 @@ class SchemaHelper(object): 'table' must be a string """ - assert isinstance(table, six.string_types) + assert isinstance(table, str) self._tables[table] = set() # empty set means all columns in the table def register_all(self): @@ -2009,7 +2007,7 @@ class SchemaHelper(object): if not self._all: schema_tables = {} - for table, columns in six.iteritems(self._tables): + for table, columns in self._tables.items(): schema_tables[table] = ( self._keep_table_columns(schema, table, columns)) @@ -2027,7 +2025,7 @@ class SchemaHelper(object): new_columns = {} for column_name in columns: - assert isinstance(column_name, six.string_types) + assert isinstance(column_name, str) assert column_name in table.columns new_columns[column_name] = table.columns[column_name] diff --git a/python/ovs/db/parser.py b/python/ovs/db/parser.py index b39de39ff..c1c5f33d8 100644 --- a/python/ovs/db/parser.py +++ b/python/ovs/db/parser.py @@ -16,8 +16,6 @@ import re from ovs.db import error -import six - class Parser(object): def __init__(self, json, name): @@ -81,11 +79,11 @@ id_re = re.compile("[_a-zA-Z][_a-zA-Z0-9]*$") def is_identifier(s): - return isinstance(s, six.string_types) and id_re.match(s) + return isinstance(s, str) and id_re.match(s) def json_type_to_string(type_): - number_types = list(six.integer_types) + number_types = [int] number_types.extend([float]) number_types = tuple(number_types) if type_ is None: @@ -98,7 +96,7 @@ def json_type_to_string(type_): return "array" elif issubclass(type_, number_types): return "number" - elif issubclass(type_, six.string_types): + elif issubclass(type_, str): return "string" else: return "<invalid>" diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py index 44b030757..3ba844ae5 100644 --- a/python/ovs/db/schema.py +++ b/python/ovs/db/schema.py @@ -19,8 +19,6 @@ import ovs.db.parser import ovs.db.types from ovs.db import error -import six - def _check_id(name, json): if name.startswith('_'): @@ -42,7 +40,7 @@ class DbSchema(object): # backward compatibility, if the root set is empty then assume that # every table is in the root set. if self.__root_set_size() == 0: - for table in six.itervalues(self.tables): + for table in self.tables.values(): table.is_root = True # Find the "ref_table"s referenced by "ref_table_name"s. @@ -50,15 +48,15 @@ class DbSchema(object): # Also force certain columns to be persistent, as explained in # __check_ref_table(). This requires 'is_root' to be known, so this # must follow the loop updating 'is_root' above. - for table in six.itervalues(self.tables): - for column in six.itervalues(table.columns): + for table in self.tables.values(): + for column in table.columns.values(): self.__follow_ref_table(column, column.type.key, "key") self.__follow_ref_table(column, column.type.value, "value") def __root_set_size(self): """Returns the number of tables in the schema's root set.""" n_root = 0 - for table in six.itervalues(self.tables): + for table in self.tables.values(): if table.is_root: n_root += 1 return n_root @@ -67,8 +65,8 @@ class DbSchema(object): def from_json(json, allow_extensions=False): parser = ovs.db.parser.Parser(json, "database schema") name = parser.get("name", ['id']) - version = parser.get_optional("version", six.string_types) - parser.get_optional("cksum", six.string_types) + version = parser.get_optional("version", (str,)) + parser.get_optional("cksum", (str,)) tablesJson = parser.get("tables", [dict]) parser.finish() @@ -78,7 +76,7 @@ class DbSchema(object): % version) tables = {} - for tableName, tableJson in six.iteritems(tablesJson): + for tableName, tableJson in tablesJson.items(): _check_id(tableName, json) tables[tableName] = TableSchema.from_json(tableJson, tableName, allow_extensions) @@ -93,7 +91,7 @@ class DbSchema(object): default_is_root = self.__root_set_size() == len(self.tables) tables = {} - for table in six.itervalues(self.tables): + for table in self.tables.values(): tables[table.name] = table.to_json(default_is_root) json = {"name": self.name, "tables": tables} if self.version: @@ -137,10 +135,10 @@ class IdlSchema(DbSchema): @staticmethod def from_json(json): parser = ovs.db.parser.Parser(json, "IDL schema") - idlPrefix = parser.get("idlPrefix", six.string_types) - idlHeader = parser.get("idlHeader", six.string_types) - cDecls = parser.get_optional("cDecls", six.string_types, "") - hDecls = parser.get_optional("hDecls", six.string_types, "") + idlPrefix = parser.get("idlPrefix", (str,)) + idlHeader = parser.get("idlHeader", (str,)) + cDecls = parser.get_optional("cDecls", (str,), "") + hDecls = parser.get_optional("hDecls", (str,), "") subjson = dict(json) del subjson["idlPrefix"] @@ -160,7 +158,7 @@ def column_set_from_json(json, columns): raise error.Error("array of distinct column names expected", json) else: for column_name in json: - if not isinstance(column_name, six.string_types): + if not isinstance(column_name, str): raise error.Error("array of distinct column names expected", json) elif column_name not in columns: @@ -206,7 +204,7 @@ class TableSchema(object): raise error.Error("table must have at least one column", json) columns = {} - for column_name, column_json in six.iteritems(columns_json): + for column_name, column_json in columns_json.items(): _check_id(column_name, json) columns[column_name] = ColumnSchema.from_json(column_json, column_name, @@ -247,7 +245,7 @@ class TableSchema(object): json["isRoot"] = self.is_root json["columns"] = columns = {} - for column in six.itervalues(self.columns): + for column in self.columns.values(): if not column.name.startswith("_"): columns[column.name] = column.to_json() @@ -276,7 +274,7 @@ class ColumnSchema(object): parser = ovs.db.parser.Parser(json, "schema for column %s" % name) mutable = parser.get_optional("mutable", [bool], True) ephemeral = parser.get_optional("ephemeral", [bool], False) - _types = list(six.string_types) + _types = [str] _types.extend([dict]) type_ = ovs.db.types.Type.from_json(parser.get("type", _types)) if allow_extensions: diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py index 54f577405..3b47b9b30 100644 --- a/python/ovs/db/types.py +++ b/python/ovs/db/types.py @@ -20,8 +20,6 @@ import ovs.db.parser import ovs.ovsuuid from ovs.db import error -import six - class AtomicType(object): def __init__(self, name, default, python_types): @@ -39,7 +37,7 @@ class AtomicType(object): @staticmethod def from_json(json): - if not isinstance(json, six.string_types): + if not isinstance(json, str): raise error.Error("atomic-type expected", json) else: return AtomicType.from_string(json) @@ -57,15 +55,15 @@ class AtomicType(object): return ovs.db.data.Atom(self, self.default) -REAL_PYTHON_TYPES = list(six.integer_types) +REAL_PYTHON_TYPES = [int] REAL_PYTHON_TYPES.extend([float]) REAL_PYTHON_TYPES = tuple(REAL_PYTHON_TYPES) VoidType = AtomicType("void", None, ()) -IntegerType = AtomicType("integer", 0, six.integer_types) +IntegerType = AtomicType("integer", 0, (int,)) RealType = AtomicType("real", 0.0, REAL_PYTHON_TYPES) BooleanType = AtomicType("boolean", False, (bool,)) -StringType = AtomicType("string", "", six.string_types) +StringType = AtomicType("string", "", (str,)) UuidType = AtomicType("uuid", ovs.ovsuuid.zero(), (uuid.UUID,)) ATOMIC_TYPES = [VoidType, IntegerType, RealType, BooleanType, StringType, @@ -155,7 +153,7 @@ class BaseType(object): @staticmethod def __parse_uint(parser, name, default): - value = parser.get_optional(name, six.integer_types) + value = parser.get_optional(name, (int,)) if value is None: value = default else: @@ -167,12 +165,11 @@ class BaseType(object): @staticmethod def from_json(json): - if isinstance(json, six.string_types): + if isinstance(json, str): return BaseType(AtomicType.from_json(json)) parser = ovs.db.parser.Parser(json, "ovsdb type") - atomic_type = AtomicType.from_json(parser.get("type", - six.string_types)) + atomic_type = AtomicType.from_json(parser.get("type", (str,))) base = BaseType(atomic_type) @@ -181,8 +178,8 @@ class BaseType(object): base.enum = ovs.db.data.Datum.from_json( BaseType.get_enum_type(base.type), enum) elif base.type == IntegerType: - base.min = parser.get_optional("minInteger", six.integer_types) - base.max = parser.get_optional("maxInteger", six.integer_types) + base.min = parser.get_optional("minInteger", (int,)) + base.max = parser.get_optional("maxInteger", (int,)) if (base.min is not None and base.max is not None and base.min > base.max): raise error.Error("minInteger exceeds maxInteger", json) @@ -202,7 +199,7 @@ class BaseType(object): base.ref_table_name = parser.get_optional("refTable", ['id']) if base.ref_table_name: base.ref_type = parser.get_optional("refType", - six.string_types, + (str,), "strong") if base.ref_type not in ['strong', 'weak']: raise error.Error('refType must be "strong" or "weak" ' @@ -520,16 +517,16 @@ class Type(object): @staticmethod def from_json(json): - if isinstance(json, six.string_types): + if isinstance(json, str): return Type(BaseType.from_json(json)) parser = ovs.db.parser.Parser(json, "ovsdb type") - _types = list(six.string_types) + _types = [str] _types.extend([dict]) key_json = parser.get("key", _types) value_json = parser.get_optional("value", _types) min_json = parser.get_optional("min", [int]) - _types = list(six.string_types) + _types = [str] _types.extend([int]) max_json = parser.get_optional("max", _types) parser.finish() |
