mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-23 05:57:33 +00:00
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 <junjie.mao@intel.com>
This commit is contained in:
parent
e6e61a4979
commit
05c738a480
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user