def path_to_posix(s):
return posixpath.join(*os.path.split(s))
-
-
-def iterkeys(d):
- """Return an iterator over the keys of a dictionary."""
- return getattr(d, 'keys' if PY3 else 'iterkeys')()
-
-def itervalues(d):
- """Return an iterator over the values of a dictionary."""
- return getattr(d, 'values' if PY3 else 'itervalues')()
-
-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
import copy
from collections import namedtuple
from ..common.utils import (struct_parse, dwarf_assert, preserve_stream_pos)
-from ..common.py3compat import iterbytes, iterkeys
+from ..common.py3compat import iterbytes
from ..construct import Struct, Switch
from .enums import DW_EH_encoding_flags
from .structs import DWARFStructs
# for DW_CFA_* instructions, and mapping their values to names. Since all
# names were imported from constants with `import *`, we look in globals()
_OPCODE_NAME_MAP = {}
-for name in list(iterkeys(globals())):
+for name in list(globals().keys()):
if name.startswith('DW_CFA'):
_OPCODE_NAME_MAP[globals()[name]] = name
import os
from ..common.exceptions import DWARFError
-from ..common.py3compat import bytes2str, iteritems
+from ..common.py3compat import bytes2str
from ..common.utils import struct_parse, preserve_stream_pos
from .enums import DW_FORM_raw2name
from .dwarf_util import _resolve_via_offset_table, _get_base_offset
def __repr__(self):
s = 'DIE %s, size=%s, has_children=%s\n' % (
self.tag, self.size, self.has_children)
- for attrname, attrval in iteritems(self.attributes):
+ for attrname, attrval in self.attributes.items():
s += ' |%-18s: %s\n' % (attrname, attrval)
return s
#-------------------------------------------------------------------------------
from collections import namedtuple
-from ..common.py3compat import BytesIO, iteritems
+from ..common.py3compat import BytesIO
from ..common.utils import struct_parse, bytelist2string, read_blob
_generate_dynamic_values(DW_OP_name2opcode, 'DW_OP_breg', 0, 31, 0x70)
# opcode -> name mapping
-DW_OP_opcode2name = dict((v, k) for k, v in iteritems(DW_OP_name2opcode))
+DW_OP_opcode2name = dict((v, k) for k, v in DW_OP_name2opcode.items())
# Each parsed DWARF expression is returned as this type with its numeric opcode,
# This code is in the public domain
#-------------------------------------------------------------------------------
from ..construct import Pass
-from ..common.py3compat import iteritems
ENUM_DW_TAG = dict(
)
# Inverse mapping for ENUM_DW_FORM
-DW_FORM_raw2name = dict((v, k) for k, v in iteritems(ENUM_DW_FORM))
+DW_FORM_raw2name = dict((v, k) for k, v in ENUM_DW_FORM.items())
# See http://www.airs.com/blog/archives/460
DW_EH_encoding_flags = dict(
import os
import collections
from collections import OrderedDict
+from collections.abc import Mapping
from ..common.utils import struct_parse
-from ..common.py3compat import Mapping
from bisect import bisect_right
import math
from ..construct import CString, Struct, If
ENUM_RELOC_TYPE_MIPS, ENUM_ATTR_TAG_ARM, ENUM_DT_FLAGS, ENUM_DT_FLAGS_1)
from .constants import (
P_FLAGS, RH_FLAGS, SH_FLAGS, SUNW_SYMINFO_FLAGS, VER_FLAGS)
-from ..common.py3compat import bytes2hex, iteritems
+from ..common.py3compat import bytes2hex
def describe_ei_class(x):
not override any other entries of the same value.
"""
out = {}
- for k, v in iteritems(d):
+ for k, v in d.items():
if v in out and k in low_priority:
continue
out[v] = k
# examples/ dir of the source distribution.
sys.path[0:0] = ['.', '..']
-from elftools.common.py3compat import itervalues
from elftools.elf.elffile import ELFFile
from elftools.dwarf.descriptions import (
describe_DWARF_expr, set_global_machine_arch)
# Go over all attributes of the DIE. Each attribute is an
# AttributeValue object (from elftools.dwarf.die), which we
# can examine.
- for attr in itervalues(DIE.attributes):
+ for attr in DIE.attributes.values():
# Check if this attribute contains location information
if loc_parser.attribute_has_location(attr, CU['version']):
print(' DIE %s. attr %s.' % (DIE.tag, attr.name))
# examples/ dir of the source distribution.
sys.path[0:0] = ['.', '..']
-from elftools.common.py3compat import itervalues
from elftools.elf.elffile import ELFFile
from elftools.dwarf.descriptions import (
describe_DWARF_expr, set_global_machine_arch)
# Go over all attributes of the DIE. Each attribute is an
# AttributeValue object (from elftools.dwarf.die), which we
# can examine.
- for attr in itervalues(DIE.attributes):
+ for attr in DIE.attributes.values():
if attribute_has_range_list(attr):
# This is a range list. Its value is an offset into
# the .debug_ranges section, so we can use the range
from elftools import __version__
from elftools.common.exceptions import ELFError
from elftools.common.py3compat import (
- ifilter, byte2int, bytes2str, itervalues, str2bytes, iterbytes)
+ ifilter, byte2int, bytes2str, str2bytes, iterbytes)
from elftools.elf.elffile import ELFFile
from elftools.elf.dynamic import DynamicSection, DynamicSegment
from elftools.elf.enums import ENUM_D_TAG
die_depth -= 1
continue
- for attr in itervalues(die.attributes):
+ for attr in die.attributes.values():
name = attr.name
# Unknown attribute values are passed-through as integers
if isinstance(name, int):
#-------------------------------------------------------------------------------
import unittest
-from elftools.common.py3compat import BytesIO, iteritems
+from elftools.common.py3compat import BytesIO
from elftools.dwarf.lineprogram import LineProgram, LineState, LineProgramEntry
from elftools.dwarf.structs import DWARFStructs
from elftools.dwarf.constants import *
""" Assert that the state attributes specified in kwargs have the given
values (the rest are default).
"""
- for k, v in iteritems(kwargs):
+ for k, v in kwargs.items():
self.assertEqual(getattr(state, k), v)
def test_spec_sample_59(self):
#-------------------------------------------------------------------------------
import unittest
-from elftools.common.py3compat import (iterbytes, iterkeys, itervalues,
- iteritems)
-
-
-class TestPy3Compat(unittest.TestCase):
- def test_iterbytes(self):
- bi = iterbytes(b'fo1')
- self.assertEqual(next(bi), b'f')
- self.assertEqual(next(bi), b'o')
- self.assertEqual(next(bi), b'1')
- with self.assertRaises(StopIteration):
- next(bi)
-
- def test_iterdict(self):
- d = {1: 'foo', 2: 'bar'}
- self.assertEqual(list(sorted(iterkeys(d))), [1, 2])
- self.assertEqual(list(sorted(itervalues(d))), ['bar', 'foo'])
- self.assertEqual(list(sorted(iteritems(d))), [(1, 'foo'), (2, 'bar')])
-
-
if __name__ == '__main__':
unittest.main()