Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def build(setup_kwargs: Any) -> None:
ext_modules=cythonize(
[
"src/zeroconf/_cache.py",
"src/zeroconf/_core.py",
"src/zeroconf/_dns.py",
"src/zeroconf/_handlers.py",
"src/zeroconf/_protocol/incoming.py",
"src/zeroconf/_protocol/outgoing.py",
],
Expand Down
2 changes: 2 additions & 0 deletions src/zeroconf/_core.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from ._handlers import QueryHandler, RecordManager
34 changes: 34 additions & 0 deletions src/zeroconf/_handlers.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

import cython

from ._cache cimport DNSCache
from ._dns cimport DNSAddress, DNSNsec, DNSPointer, DNSQuestion, DNSRecord, DNSRRSet
from ._protocol.incoming cimport DNSIncoming
from ._protocol.outgoing cimport DNSOutgoing


cdef object RecordUpdate

cdef class QueryHandler:

cdef object registry
cdef DNSCache cache
cdef object question_history

cdef class RecordManager:

cdef object zc
cdef DNSCache cache
cdef public cython.list listeners

cdef class _QueryResponse:

cdef bint _is_probe
cdef DNSIncoming _msg
cdef object _now
cdef DNSCache _cache
cdef object _additionals
cdef cython.set _ucast
cdef cython.set _mcast_now
cdef cython.set _mcast_aggregate
cdef cython.set _mcast_aggregate_last_second
35 changes: 25 additions & 10 deletions src/zeroconf/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
Dict,
Iterable,
List,
NamedTuple,
Optional,
Set,
Tuple,
Expand Down Expand Up @@ -75,19 +74,35 @@
_RESPOND_IMMEDIATE_TYPES = {_TYPE_NSEC, _TYPE_SRV, *_ADDRESS_RECORD_TYPES}


class QuestionAnswers(NamedTuple):
ucast: _AnswerWithAdditionalsType
mcast_now: _AnswerWithAdditionalsType
mcast_aggregate: _AnswerWithAdditionalsType
mcast_aggregate_last_second: _AnswerWithAdditionalsType
class QuestionAnswers:
"""A group of answers for a question."""

__slots__ = ("ucast", "mcast_now", "mcast_aggregate", "mcast_aggregate_last_second")

class AnswerGroup(NamedTuple):
def __init__(
self,
ucast: _AnswerWithAdditionalsType,
mcast_now: _AnswerWithAdditionalsType,
mcast_aggregate: _AnswerWithAdditionalsType,
mcast_aggregate_last_second: _AnswerWithAdditionalsType,
) -> None:
"""Initialize the question answers."""
self.ucast = ucast
self.mcast_now = mcast_now
self.mcast_aggregate = mcast_aggregate
self.mcast_aggregate_last_second = mcast_aggregate_last_second


class AnswerGroup:
"""A group of answers scheduled to be sent at the same time."""

send_after: float # Must be sent after this time
send_before: float # Must be sent before this time
answers: _AnswerWithAdditionalsType
__slots__ = ("send_after", "send_before", "answers")

def __init__(self, send_after: float, send_before: float, answers: _AnswerWithAdditionalsType) -> None:
"""Initialize the answer group."""
self.send_after = send_after # Must be sent after this time
self.send_before = send_before # Must be sent before this time
self.answers = answers


def _message_is_probe(msg: DNSIncoming) -> bool:
Expand Down
9 changes: 7 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
from typing import Set, cast
from unittest.mock import patch

try:
from unittest.mock import AsyncMock
except ImportError:
from unittest.mock import Mock as AsyncMock # type: ignore[misc]

import pytest

import zeroconf as r
Expand Down Expand Up @@ -818,8 +823,8 @@ def _background_register():
@pytest.mark.asyncio
@unittest.skipIf(sys.version_info[:3][1] < 8, 'Requires Python 3.8 or later to patch _async_setup')
@patch("zeroconf._core._STARTUP_TIMEOUT", 0)
@patch("zeroconf._core.AsyncEngine._async_setup")
async def test_event_loop_blocked(mock_start):
@patch("zeroconf._core.AsyncEngine._async_setup", AsyncMock())
async def test_event_loop_blocked():
"""Test we raise NotRunningException when waiting for startup that times out."""
aiozc = AsyncZeroconf(interfaces=['127.0.0.1'])
with pytest.raises(NotRunningException):
Expand Down