Skip to content

Commit 541c9e7

Browse files
committed
Switch back to _impl and fix names
1 parent 1cbea51 commit 541c9e7

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

netfilterqueue/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from ._impl import (
2+
COPY_NONE as COPY_NONE,
3+
COPY_META as COPY_META,
4+
COPY_PACKET as COPY_PACKET,
5+
Packet as Packet,
6+
NetfilterQueue as NetfilterQueue,
7+
PROTOCOLS as PROTOCOLS,
8+
)
9+
from ._version import (
10+
VERSION as VERSION,
11+
__version__ as __version__,
12+
)
File renamed without changes.
File renamed without changes.

netfilterqueue/__init__.pyx renamed to netfilterqueue/_impl.pyx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ DEF SockCopySize = MaxCopySize + SockOverhead
2323
# Socket queue should hold max number of packets of copysize bytes
2424
DEF SockRcvSize = DEFAULT_MAX_QUEUELEN * SockCopySize // 2
2525

26-
__package__ = "netfilterqueue"
27-
28-
from ._version import __version__, VERSION
29-
3026
from cpython.exc cimport PyErr_CheckSignals
3127

28+
cdef extern from "Python.h":
29+
ctypedef struct PyTypeObject:
30+
const char* tp_name
31+
3232
# A negative return value from this callback will stop processing and
3333
# make nfq_handle_packet return -1, so we use that as the error flag.
3434
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
@@ -346,6 +346,17 @@ cdef class NetfilterQueue:
346346
else:
347347
nfq_handle_packet(self.h, buf, len(buf))
348348

349+
cdef void _fix_names():
350+
# Avoid ._impl showing up in reprs. This doesn't work on PyPy; there we would
351+
# need to modify the name before PyType_Ready(), but I can't find any way to
352+
# write Cython code that would execute at that time.
353+
cdef PyTypeObject* tp = <PyTypeObject*>Packet
354+
tp.tp_name = "netfilterqueue.Packet"
355+
tp = <PyTypeObject*>NetfilterQueue
356+
tp.tp_name = "netfilterqueue.NetfilterQueue"
357+
358+
_fix_names()
359+
349360
PROTOCOLS = {
350361
0: "HOPOPT",
351362
1: "ICMP",

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
ext_modules = cythonize(
1212
Extension(
13-
"netfilterqueue.__init__",
14-
["netfilterqueue/__init__.pyx"],
13+
"netfilterqueue._impl",
14+
["netfilterqueue/_impl.pyx"],
1515
libraries=["netfilter_queue"],
1616
),
1717
compiler_directives={"language_level": "3str"},
@@ -23,7 +23,7 @@
2323
# setup_requires below.
2424
setup_requires = ["cython"]
2525
elif not os.path.exists(
26-
os.path.join(os.path.dirname(__file__), "netfilterqueue/__init__.c")
26+
os.path.join(os.path.dirname(__file__), "netfilterqueue/_impl.c")
2727
):
2828
sys.stderr.write(
2929
"You must have Cython installed (`pip install cython`) to build this "
@@ -34,8 +34,8 @@
3434
sys.exit(1)
3535
ext_modules = [
3636
Extension(
37-
"netfilterqueue.__init__",
38-
["netfilterqueue/__init__.c"],
37+
"netfilterqueue._impl",
38+
["netfilterqueue/_impl.c"],
3939
libraries=["netfilter_queue"],
4040
)
4141
]

0 commit comments

Comments
 (0)