compatible with Python 3

This commit is contained in:
lilydjwg 2015-05-16 15:25:44 +08:00
parent 6b8be8a5ec
commit a008498677
4 changed files with 3262 additions and 2759 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,7 @@ cdef enum:
IPPROTO_MAX
cdef extern from "Python.h":
object PyBytes_FromStringAndSize(char *s, Py_ssize_t len)
object PyString_FromStringAndSize(char *s, Py_ssize_t len)
cdef extern from "sys/time.h":

View File

@ -20,6 +20,8 @@ DEF BufferSize = 4096
DEF MetadataSize = 80
DEF MaxCopySize = BufferSize - MetadataSize
cimport cpython.version
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
nfq_data *nfa, void *data) with gil:
"""Create a Packet and pass it to appropriate callback."""
@ -93,8 +95,13 @@ cdef class Packet:
def get_payload(self):
"""Return payload as Python string."""
cdef object py_string = PyString_FromStringAndSize(self.payload,
self.payload_len)
cdef object py_string
if cpython.version.PY_MAJOR_VERSION >= 3:
py_string = PyBytes_FromStringAndSize(
self.payload, self.payload_len)
else:
py_string = PyString_FromStringAndSize(
self.payload, self.payload_len)
return py_string
cpdef Py_ssize_t get_payload_len(self):

View File

@ -42,5 +42,6 @@ setup(
"Intended Audience :: Telecommunications Industry",
"Programming Language :: Cython",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
]
)