Skip to content

Commit 6599d29

Browse files
committed
Add python3 support
1 parent 8e9727b commit 6599d29

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: python
33

44
python:
55
- 2.7
6+
- 3.4
67

78
install: pip install -e .
89

autopxd/__init__.py

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

33
import os
44
import os.path
5+
import six
56
import subprocess
67
import sys
78

@@ -212,7 +213,7 @@ def visit_TypeDecl(self, node):
212213
if not decls:
213214
return
214215
assert len(decls) == 1
215-
if isinstance(decls[0], basestring):
216+
if isinstance(decls[0], six.string_types):
216217
self.append(IdentifierType(node.declname, decls[0]))
217218
else:
218219
self.append(decls[0])
@@ -222,7 +223,7 @@ def visit_Decl(self, node):
222223
if not decls:
223224
return
224225
assert len(decls) == 1
225-
if isinstance(decls[0], basestring):
226+
if isinstance(decls[0], six.string_types):
226227
self.append(IdentifierType(node.name, decls[0]))
227228
else:
228229
self.append(decls[0])
@@ -248,7 +249,7 @@ def visit_FuncDecl(self, node):
248249
def visit_PtrDecl(self, node):
249250
decls = self.collect(node)
250251
assert len(decls) == 1
251-
if isinstance(decls[0], basestring):
252+
if isinstance(decls[0], six.string_types):
252253
self.append(decls[0])
253254
else:
254255
self.append(Ptr(decls[0]))
@@ -306,12 +307,12 @@ def preprocess(code, extra_cpp_args=[]):
306307
'cpp', '-nostdinc', '-D__attribute__(x)=', '-I', BUILTIN_HEADERS_DIR,
307308
] + extra_cpp_args + ['-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
308309
result = []
309-
result.append(proc.communicate(input=code)[0])
310+
result.append(proc.communicate(input=code.encode('utf-8'))[0])
310311
while proc.poll() is None:
311312
result.append(proc.communicate()[0])
312313
if proc.returncode:
313314
raise Exception('Invoking C preprocessor failed')
314-
return ''.join(result)
315+
return b''.join(result).decode('utf-8')
315316

316317

317318
def parse(code, extra_cpp_args=[]):

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def run(self):
5454
'sdist': install_libc_headers_and(sdist)
5555
},
5656
install_requires=[
57+
'six',
5758
'Click',
5859
'pycparser',
5960
],

0 commit comments

Comments
 (0)