From 05c738a4802c1060ede8cef8a17525cd7210b60e Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Fri, 30 Apr 2021 08:29:53 +0800 Subject: [PATCH] board_inspector/lib: fix compatibility issues in unpack.py Starting from Python 3.0 the following changes to the language are effective: 1. The integer types `int` and `long` have been unified as `int`. See `https://www.python.org/dev/peps/pep-0237/` for details. 2. The `.iterkeys` method is removed from the `dict` class. See `https://www.python.org/dev/peps/pep-3106/` for details. This patch updates `unpack.py`, originally from BITS, so that it can be used in Python 3. Tracked-On: #5922 Signed-off-by: Junjie Mao --- misc/config_tools/board_inspector/lib/unpack.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/misc/config_tools/board_inspector/lib/unpack.py b/misc/config_tools/board_inspector/lib/unpack.py index dedbc9d8d..20ff9e446 100644 --- a/misc/config_tools/board_inspector/lib/unpack.py +++ b/misc/config_tools/board_inspector/lib/unpack.py @@ -127,7 +127,7 @@ class Struct(object): if hasattr(self, name): raise StructError("Internal error: Duplicate Struct field name {}".format(name)) if fmt is None: - if isinstance(value, (int, long)) and not isinstance(value, bool): + if isinstance(value, int) and not isinstance(value, bool): fmt = "{:#x}".format else: fmt = "{!r}".format @@ -142,21 +142,21 @@ class Struct(object): return self.fields[name](getattr(self, name)) def __repr__(self): - return "{}({})".format(self.__class__.__name__, ", ".join("{}={}".format(k, self.format_field(k)) for k in self.fields.iterkeys())) + return "{}({})".format(self.__class__.__name__, ", ".join("{}={}".format(k, self.format_field(k)) for k in self.fields.keys())) def __iter__(self): - return (getattr(self, k) for k in self.fields.iterkeys()) + return (getattr(self, k) for k in self.fields.keys()) def __eq__(self, other): if type(self) is not type(other): return NotImplemented - return self.fields.keys() == other.fields.keys() and all(getattr(self, name) == getattr(other, name) for name in self.fields.iterkeys()) + return self.fields.keys() == other.fields.keys() and all(getattr(self, name) == getattr(other, name) for name in self.fields.keys()) def __ne__(self, other): return not self == other def __hash__(self): - return hash(tuple((name, getattr(self, name)) for name in self.fields.iterkeys())) + return hash(tuple((name, getattr(self, name)) for name in self.fields.keys())) def format_each(fmt_one): def f(it):