Skip to content

Commit 5bbd49d

Browse files
committed
feat: cythonize handlers
1 parent d45c2f9 commit 5bbd49d

4 files changed

Lines changed: 44 additions & 3 deletions

File tree

build_ext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def build(setup_kwargs: Any) -> None:
2424
ext_modules=cythonize(
2525
[
2626
"src/zeroconf/_cache.py",
27+
"src/zeroconf/_core.py",
2728
"src/zeroconf/_dns.py",
29+
"src/zeroconf/_handlers.py",
2830
"src/zeroconf/_protocol/incoming.py",
2931
"src/zeroconf/_protocol/outgoing.py",
3032
],

src/zeroconf/_core.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
from ._handlers import QueryHandler, RecordManager

src/zeroconf/_handlers.pxd

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import cython
3+
4+
from ._cache cimport DNSCache
5+
from ._dns cimport DNSAddress, DNSNsec, DNSPointer, DNSQuestion, DNSRecord, DNSRRSet
6+
from ._protocol.incoming cimport DNSIncoming
7+
from ._protocol.outgoing cimport DNSOutgoing
8+
9+
10+
cdef object RecordUpdate
11+
cdef object _DNS_PTR_MIN_TTL
12+
13+
cdef class QueryHandler:
14+
15+
cdef object registry
16+
cdef DNSCache cache
17+
cdef object question_history
18+
19+
cdef class RecordManager:
20+
21+
cdef object zc
22+
cdef DNSCache cache
23+
cdef public cython.list listeners
24+
25+
cdef class _QueryResponse:
26+
27+
cdef bint _is_probe
28+
cdef DNSIncoming _msg
29+
cdef object _now
30+
cdef DNSCache _cache
31+
cdef object _additionals
32+
cdef cython.set _ucast
33+
cdef cython.set _mcast_now
34+
cdef cython.set _mcast_aggregate
35+
cdef cython.set _mcast_aggregate_last_second

src/zeroconf/_handlers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import itertools
2424
import random
2525
from collections import deque
26+
from dataclasses import dataclass
2627
from typing import (
2728
TYPE_CHECKING,
2829
Dict,
2930
Iterable,
3031
List,
31-
NamedTuple,
3232
Optional,
3333
Set,
3434
Tuple,
@@ -75,14 +75,16 @@
7575
_RESPOND_IMMEDIATE_TYPES = {_TYPE_NSEC, _TYPE_SRV, *_ADDRESS_RECORD_TYPES}
7676

7777

78-
class QuestionAnswers(NamedTuple):
78+
@dataclass
79+
class QuestionAnswers:
7980
ucast: _AnswerWithAdditionalsType
8081
mcast_now: _AnswerWithAdditionalsType
8182
mcast_aggregate: _AnswerWithAdditionalsType
8283
mcast_aggregate_last_second: _AnswerWithAdditionalsType
8384

8485

85-
class AnswerGroup(NamedTuple):
86+
@dataclass
87+
class AnswerGroup:
8688
"""A group of answers scheduled to be sent at the same time."""
8789

8890
send_after: float # Must be sent after this time

0 commit comments

Comments
 (0)