Upstream version 8.36.161.0
[platform/framework/web/crosswalk.git] / src / third_party / pyelftools / elftools / common / py3compat.py
1 #-------------------------------------------------------------------------------
2 # elftools: common/py3compat.py
3 #
4 # Python 3 compatibility code
5 #
6 # Eli Bendersky (eliben@gmail.com)
7 # This code is in the public domain
8 #-------------------------------------------------------------------------------
9 import sys
10 PY3 = sys.version_info[0] == 3
11
12
13 if PY3:
14     import io
15     StringIO = io.StringIO
16     BytesIO = io.BytesIO
17
18     import collections
19     OrderedDict = collections.OrderedDict
20
21     _iterkeys = "keys"
22     _iteritems = "items"
23     _itervalues = "values"
24
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
29
30     ifilter = filter
31
32     maxint = sys.maxsize
33 else:
34     import cStringIO
35     StringIO = BytesIO = cStringIO.StringIO
36
37     from .ordereddict import OrderedDict
38
39     _iterkeys = "iterkeys"
40     _iteritems = "iteritems"
41     _itervalues = "itervalues"
42
43     def bytes2str(b): return b
44     def str2bytes(s): return s
45     int2byte = chr
46     byte2int = ord
47
48     from itertools import ifilter
49
50     maxint = sys.maxint
51
52
53 def iterkeys(d):
54     """Return an iterator over the keys of a dictionary."""
55     return getattr(d, _iterkeys)()
56
57 def itervalues(d):
58     """Return an iterator over the values of a dictionary."""
59     return getattr(d, _itervalues)()
60
61 def iteritems(d):
62     """Return an iterator over the items of a dictionary."""
63     return getattr(d, _iteritems)()
64