Skip to content

Commit 8ce088b

Browse files
authored
Python2 leftovers v2 (#2395)
* Remove python2 leftovers * Remove python2 references from BUILDING.txt * Remove some leftover install3 references * Update shebangs to python3 * Delete suite/test_corpus.py
1 parent 95966a1 commit 8ce088b

34 files changed

+20
-296
lines changed

.github/workflows/CITest.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ jobs:
179179
run: |
180180
cp libcapstone.* bindings/python/prebuilt
181181
cd bindings/python
182-
make install3
182+
make install
183183
cd ..
184184
BUILD_TESTS=no make tests
185185
@@ -188,7 +188,7 @@ jobs:
188188
run: |
189189
pip install cython
190190
cd bindings/python
191-
make install3_cython
191+
make install_cython
192192
cd ..
193193
python -c "import capstone;print(capstone.debug())" | grep Cython
194194
BUILD_TESTS=no make tests

bindings/python/BUILDING.txt

+3-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
$ sudo make install
88

9-
To install Capstone for Python 3, run the command below:
10-
(Note: this requires python3 installed in your machine)
11-
12-
$ sudo make install3
13-
149
To control the install destination, set the DESTDIR environment variable.
1510

1611
2. For better Python performance, install cython-based binding with:
@@ -19,7 +14,7 @@
1914

2015
Note that this requires Cython installed first. To install Cython, see
2116
below.
22-
17+
2318
3. To install Cython, you have to ensure that the header files
2419
and the static library for Python are installed beforehand.
2520

@@ -38,13 +33,13 @@
3833
install the required Cython version using your repository.
3934

4035
E.g. on Ubuntu, do:
41-
36+
4237
$ sudo apt-get install cython
4338

4439
However, our cython-based binding requires Cython version 0.19 or newer,
4540
but sometimes distributions only provide older version. Make sure to
4641
verify the current installed version before going into section 2 above.
47-
42+
4843
E.g, on Ubuntu, you can verify the current Cython version with:
4944

5045
$ apt-cache policy cython

bindings/python/Makefile

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
PYTHON2 ?= python2
21
PYTHON3 ?= python3
32

4-
.PHONY: gen_const install install3 install_cython sdist sdist3 bdist bdist3 clean check
3+
.PHONY: gen_const install install_cython sdist bdist clean check
54

65
gen_const:
76
cd .. && $(PYTHON3) const_generator.py python
87

98
install:
10-
rm -rf src/
11-
if test -n "${DESTDIR}"; then \
12-
$(PYTHON2) setup.py build install --root="${DESTDIR}"; \
13-
else \
14-
$(PYTHON2) setup.py build install; \
15-
fi
16-
17-
install3:
189
rm -rf src/
1910
if test -n "${DESTDIR}"; then \
2011
$(PYTHON3) setup.py build install --root="${DESTDIR}"; \
@@ -24,14 +15,6 @@ install3:
2415

2516
# NOTE: Newer cython can be installed by: sudo pip install --upgrade cython
2617
install_cython:
27-
rm -rf src/
28-
if test -n "${DESTDIR}"; then \
29-
$(PYTHON2) setup_cython.py build install --root="${DESTDIR}"; \
30-
else \
31-
$(PYTHON2) setup_cython.py build install; \
32-
fi
33-
34-
install3_cython:
3518
rm -rf src/
3619
if test -n "${DESTDIR}"; then \
3720
$(PYTHON3) setup_cython.py build install --root="${DESTDIR}"; \
@@ -41,21 +24,11 @@ install3_cython:
4124

4225
# build & upload PyPi package with source code of the core
4326
sdist:
44-
rm -rf src/ dist/
45-
$(PYTHON2) setup.py sdist register upload
46-
47-
# build & upload PyPi package with source code of the core
48-
sdist3:
4927
rm -rf src/ dist/
5028
$(PYTHON3) setup.py sdist register upload
5129

5230
# build & upload PyPi package with prebuilt core
5331
bdist:
54-
rm -rf src/ dist/
55-
$(PYTHON2) setup.py bdist_wheel register upload
56-
57-
# build & upload PyPi package with prebuilt core
58-
bdist3:
5932
rm -rf src/ dist/
6033
$(PYTHON3) setup.py bdist_wheel register upload
6134

bindings/python/capstone/__init__.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
2-
import os, sys
3-
from platform import system
4-
_python2 = sys.version_info[0] < 3
5-
if _python2:
6-
range = xrange
2+
import os
3+
import sys
74

85
__all__ = [
96
'Cs',
@@ -549,13 +546,8 @@ class CsError(Exception):
549546
def __init__(self, errno):
550547
self.errno = errno
551548

552-
if _python2:
553-
def __str__(self):
554-
return _cs.cs_strerror(self.errno)
555-
556-
else:
557-
def __str__(self):
558-
return _cs.cs_strerror(self.errno).decode()
549+
def __str__(self):
550+
return _cs.cs_strerror(self.errno).decode()
559551

560552

561553
# return the core's version
@@ -1215,10 +1207,6 @@ def group_name(self, group_id, default=None):
12151207
# Disassemble binary & return disassembled instructions in CsInsn objects
12161208
def disasm(self, code, offset, count=0):
12171209
all_insn = ctypes.POINTER(_cs_insn)()
1218-
'''if not _python2:
1219-
print(code)
1220-
code = code.encode()
1221-
print(code)'''
12221210
# Pass a bytearray by reference
12231211
size = len(code)
12241212
view = memoryview(code)

bindings/python/setup.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
from distutils.command.sdist import sdist
1414
from setuptools.command.bdist_egg import bdist_egg
1515

16-
PYTHON2 = sys.version_info[0] == 2
17-
if PYTHON2:
18-
import io
19-
2016
SYSTEM = sys.platform
2117

2218
# adapted from commit e504b81 of Nguyen Tan Cong
@@ -220,13 +216,11 @@ def run(self):
220216
author_email='[email protected]',
221217
description='Capstone disassembly engine',
222218
url='https://www.capstone-engine.org',
223-
long_description=io.open('README.txt', encoding="utf8").read() if PYTHON2 else open('README.txt', encoding="utf8").read(),
219+
long_description=open('README.txt', encoding="utf8").read(),
224220
long_description_content_type='text/markdown',
225-
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
221+
python_requires='>=3.6',
226222
classifiers=[
227223
'License :: OSI Approved :: BSD License',
228-
'Programming Language :: Python :: 2',
229-
'Programming Language :: Python :: 2.7',
230224
'Programming Language :: Python :: 3',
231225
],
232226
cmdclass=cmdclass,

bindings/python/test_aarch64.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.aarch64 import *
87
from xprint import to_hex, to_x, to_x_32

bindings/python/test_alpha.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Dmitry Sibirtsev <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.alpha import *
87
from xprint import to_x, to_hex

bindings/python/test_arm.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.arm import *
87
from xprint import to_hex, to_x_32

bindings/python/test_basic.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
#!/usr/bin/env python3
22
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
33

4-
from __future__ import print_function
54
from capstone import *
6-
import binascii
7-
import sys
85

96
from xprint import to_hex
107

11-
_python3 = sys.version_info.major == 3
12-
138

149
X86_CODE16 = b"\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
1510
X86_CODE32 = b"\xba\xcd\xab\x00\x00\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
@@ -102,10 +97,7 @@ def test_cs_disasm_quick():
10297

10398

10499
def test_different_data_formats():
105-
if _python3:
106-
data = bytes.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05')
107-
else:
108-
data = bytes(bytearray.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05'))
100+
data = bytes.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05')
109101
mnemonics = ['xor', 'mul', 'add', 'movabs', 'push', 'pop', 'push', 'push', 'push', 'pop', 'syscall']
110102
disassembler = Cs(CS_ARCH_X86, CS_MODE_64)
111103
for name, code in (

bindings/python/test_bpf.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Capstone Python bindings
44
# BPF tests by david942j <[email protected]>, 2019
55

6-
from __future__ import print_function
76
from capstone import *
87
from capstone.bpf import *
98
from xprint import to_hex, to_x, to_x_32

bindings/python/test_customized_mnem.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.x86 import *
87
from xprint import to_hex

bindings/python/test_detail.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
4-
from __future__ import print_function
54
from capstone import *
65

76
from xprint import to_hex

bindings/python/test_evm.py

-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
7-
import sys
86

97
from xprint import to_hex
108

11-
_python3 = sys.version_info.major == 3
12-
139

1410
EVM_CODE = b"\x60\x61\x50"
1511

bindings/python/test_hppa.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Dmitry Sibirtsev <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.hppa import *
87
from xprint import to_x, to_hex

bindings/python/test_iter.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
4-
from __future__ import print_function
54
from capstone import *
65
from xprint import to_hex
76

bindings/python/test_lite.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
4-
from __future__ import print_function
54
from capstone import *
65
from xprint import to_hex
76

bindings/python/test_m680x.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
# Capstone Python bindings, by Wolfgang Schwotzer <[email protected]>
44

5-
from __future__ import print_function
6-
import sys
75
from capstone import *
86
from capstone.m680x import *
9-
_python3 = sys.version_info.major == 3
107

118

129
s_access = (
@@ -40,10 +37,7 @@
4037

4138
# print hex dump from string all upper case
4239
def to_hex_uc(string):
43-
if _python3:
44-
return " ".join("0x%02x" % c for c in string)
45-
else:
46-
return " ".join("0x%02x" % ord(c) for c in string)
40+
return " ".join("0x%02x" % c for c in string)
4741

4842
# print short hex dump from byte array all upper case
4943
def to_hex_short_uc(byte_array):

bindings/python/test_m68k.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
# Capstone Python bindings, by Nicolas PLANEL <[email protected]>
4-
from __future__ import print_function
54
from capstone import *
65
from capstone.m68k import *
76
from xprint import to_hex

bindings/python/test_mips.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
4-
from __future__ import print_function
54
from capstone import *
65
from capstone.mips import *
76
from xprint import to_hex, to_x

bindings/python/test_mos65xx.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
# Capstone Python bindings, by Sebastian Macke <Sebastian Macke>
4-
from __future__ import print_function
54
from capstone import *
65
from capstone.mos65xx import *
76
from xprint import to_hex, to_x

bindings/python/test_ppc.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
4-
from __future__ import print_function
54
from capstone import *
65
from capstone.ppc import *
76
from xprint import to_hex, to_x, to_x_32

bindings/python/test_riscv.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.riscv import *
87
from xprint import to_x, to_hex

bindings/python/test_sh.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Peace-Maker <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.sh import *
87
from xprint import to_x, to_hex

bindings/python/test_skipdata.py

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
7-
import binascii
86
from xprint import to_hex
97

108

bindings/python/test_sparc.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.sparc import *
87
from xprint import to_hex, to_x_32

bindings/python/test_systemz.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
44

5-
from __future__ import print_function
65
from capstone import *
76
from capstone.systemz import *
87
from xprint import to_x, to_hex

0 commit comments

Comments
 (0)