use self.payload[:self.payload_len] for getting python string
This is more Cythonic way, documented here http://cython.readthedocs.io/en/latest/src/tutorial/strings.html#passing-byte-strings It compiles to __Pyx_PyBytes_FromStringAndSize( __pyx_v_self->payload + 0, __pyx_v_self->payload_len - 0) Which is the Cython macro wrapper which handles both Python 2 and Python3. Fixes #17
This commit is contained in:
parent
9c74558250
commit
949f894256
804
netfilterqueue.c
804
netfilterqueue.c
File diff suppressed because it is too large
Load Diff
|
@ -100,12 +100,7 @@ cdef class Packet:
|
|||
def get_payload(self):
|
||||
"""Return payload as Python string."""
|
||||
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)
|
||||
py_string = self.payload[:self.payload_len]
|
||||
return py_string
|
||||
|
||||
cpdef Py_ssize_t get_payload_len(self):
|
||||
|
|
Loading…
Reference in New Issue