1 #-------------------------------------------------------------------------------
2 # elftools: common/py3compat.py
4 # Python 3 compatibility code
6 # Eli Bendersky (eliben@gmail.com)
7 # This code is in the public domain
8 #-------------------------------------------------------------------------------
10 PY3 = sys.version_info[0] == 3
15 StringIO = io.StringIO
19 OrderedDict = collections.OrderedDict
23 _itervalues = "values"
25 def bytes2str(b): return b.decode('latin-1')
26 def str2bytes(s): return s.encode('latin-1')
27 def int2byte(i):return bytes((i,))
28 def byte2int(b): return b
35 StringIO = BytesIO = cStringIO.StringIO
37 from .ordereddict import OrderedDict
39 _iterkeys = "iterkeys"
40 _iteritems = "iteritems"
41 _itervalues = "itervalues"
43 def bytes2str(b): return b
44 def str2bytes(s): return s
48 from itertools import ifilter
54 """Return an iterator over the keys of a dictionary."""
55 return getattr(d, _iterkeys)()
58 """Return an iterator over the values of a dictionary."""
59 return getattr(d, _itervalues)()
62 """Return an iterator over the items of a dictionary."""
63 return getattr(d, _iteritems)()