1 #-------------------------------------------------------------------------------
2 # elftools: common/py3compat.py
4 # Python 2/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
12 Python 2 is no longer supported by pyelftools; if you need to use Python 2,
13 please download an older pyelftools version (such as version 0.29).
18 # Functions for acting on bytestrings and strings. In Python 2 and 3,
19 # strings and bytes are the same and chr/ord can be used to convert between
20 # numeric byte values and their string representations. In Python 3, bytes
21 # and strings are different types and bytes hold numeric values when
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
31 def bytes2str(b
): return b
32 def str2bytes(s
): return s