From: Eli Bendersky Date: Wed, 11 Sep 2019 13:02:15 +0000 (-0700) Subject: Portable import of collections.Mapping X-Git-Tag: v0.26~12 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=02100343590b8fd636eea569ce29824844aa5ca6;p=pyelftools.git Portable import of collections.Mapping Tested with Python 3.8 Based on #237 by @Plailect. Closes #237 --- 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