From 02100343590b8fd636eea569ce29824844aa5ca6 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 11 Sep 2019 06:02:15 -0700 Subject: [PATCH] Portable import of collections.Mapping Tested with Python 3.8 Based on #237 by @Plailect. Closes #237 --- elftools/common/py3compat.py | 5 +++++ elftools/dwarf/namelut.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/elftools/common/py3compat.py b/elftools/common/py3compat.py index b901e07..2296771 100644 --- a/elftools/common/py3compat.py +++ b/elftools/common/py3compat.py @@ -64,3 +64,8 @@ def itervalues(d): def iteritems(d): """Return an iterator over the items of a dictionary.""" return getattr(d, 'items' if PY3 else 'iteritems')() + +try: + from collections.abc import Mapping # python >= 3.3 +except ImportError: + from collections import Mapping # python < 3.3 diff --git a/elftools/dwarf/namelut.py b/elftools/dwarf/namelut.py index 2cc32d4..fd12aad 100755 --- a/elftools/dwarf/namelut.py +++ b/elftools/dwarf/namelut.py @@ -10,13 +10,14 @@ import os import collections from collections import OrderedDict from ..common.utils import struct_parse +from ..common.py3compat import Mapping from bisect import bisect_right import math from ..construct import CString, Struct, If NameLUTEntry = collections.namedtuple('NameLUTEntry', 'cu_ofs die_ofs') -class NameLUT(collections.Mapping): +class NameLUT(Mapping): """ A "Name LUT" holds any of the tables specified by .debug_pubtypes or .debug_pubnames sections. This is basically a dictionary where the key is -- 2.30.2