Skip to content

Commit

Permalink
chore: prepare ServiceInfo base class RecordUpdateListener for cython (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Sep 10, 2023
1 parent a537a31 commit 6bf5d95
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def build(setup_kwargs: Any) -> None:
"src/zeroconf/_handlers/record_manager.py",
"src/zeroconf/_handlers/query_handler.py",
"src/zeroconf/_services/registry.py",
"src/zeroconf/_updates.py",
"src/zeroconf/_utils/time.py",
],
compiler_directives={"language_level": "3"}, # Python 3
Expand Down
3 changes: 2 additions & 1 deletion src/zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from ._logger import QuietLogger, log # noqa # import needed for backwards compat
from ._protocol.incoming import DNSIncoming # noqa # import needed for backwards compat
from ._protocol.outgoing import DNSOutgoing # noqa # import needed for backwards compat
from ._record_update import RecordUpdate
from ._services import ( # noqa # import needed for backwards compat
ServiceListener,
ServiceStateChange,
Expand All @@ -65,7 +66,7 @@
ServiceRegistry,
)
from ._services.types import ZeroconfServiceTypes
from ._updates import RecordUpdate, RecordUpdateListener
from ._updates import RecordUpdateListener
from ._utils.name import service_type_name # noqa # import needed for backwards compat
from ._utils.net import ( # noqa # import needed for backwards compat
InterfaceChoice,
Expand Down
2 changes: 1 addition & 1 deletion src/zeroconf/_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import threading
from typing import TYPE_CHECKING, List, Optional, cast

from ._updates import RecordUpdate
from ._record_update import RecordUpdate
from ._utils.asyncio import get_running_loop, run_coro_with_timeout
from ._utils.time import current_time_millis
from .const import _CACHE_CLEANUP_INTERVAL
Expand Down
3 changes: 2 additions & 1 deletion src/zeroconf/_handlers/record_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from .._dns import DNSQuestion, DNSRecord
from .._logger import log
from .._protocol.incoming import DNSIncoming
from .._updates import RecordUpdate, RecordUpdateListener
from .._record_update import RecordUpdate
from .._updates import RecordUpdateListener
from .._utils.time import current_time_millis
from ..const import _ADDRESS_RECORD_TYPES, _DNS_PTR_MIN_TTL, _TYPE_PTR

Expand Down
30 changes: 30 additions & 0 deletions src/zeroconf/_record_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
""" Multicast DNS Service Discovery for Python, v0.14-wmcbrine
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine
This module provides a framework for the use of DNS Service Discovery
using IP multicast.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
"""

from typing import NamedTuple, Optional

from ._dns import DNSRecord


class RecordUpdate(NamedTuple):
new: DNSRecord
old: Optional[DNSRecord]
3 changes: 2 additions & 1 deletion src/zeroconf/_services/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
from .._dns import DNSPointer, DNSQuestion, DNSQuestionType
from .._logger import log
from .._protocol.outgoing import DNSOutgoing
from .._record_update import RecordUpdate
from .._services import (
ServiceListener,
ServiceStateChange,
Signal,
SignalRegistrationInterface,
)
from .._updates import RecordUpdate, RecordUpdateListener
from .._updates import RecordUpdateListener
from .._utils.name import cached_possible_types, service_type_name
from .._utils.time import current_time_millis, millis_to_seconds
from ..const import (
Expand Down
3 changes: 2 additions & 1 deletion src/zeroconf/_services/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
from .._exceptions import BadTypeInNameException
from .._logger import log
from .._protocol.outgoing import DNSOutgoing
from .._updates import RecordUpdate, RecordUpdateListener
from .._record_update import RecordUpdate
from .._updates import RecordUpdateListener
from .._utils.asyncio import (
_resolve_all_futures_to_none,
get_running_loop,
Expand Down
9 changes: 9 additions & 0 deletions src/zeroconf/_updates.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import cython


cdef class RecordUpdateListener:

cpdef async_update_records(self, object zc, object now, cython.list records)

cpdef async_update_records_complete(self)
9 changes: 4 additions & 5 deletions src/zeroconf/_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
USA
"""

from typing import TYPE_CHECKING, List, NamedTuple, Optional
from typing import TYPE_CHECKING, List

from ._dns import DNSRecord
from ._record_update import RecordUpdate

if TYPE_CHECKING:
from ._core import Zeroconf


class RecordUpdate(NamedTuple):
new: DNSRecord
old: Optional[DNSRecord]
float_ = float


class RecordUpdateListener:
Expand All @@ -50,7 +49,7 @@ def update_record( # pylint: disable=no-self-use
"""
raise RuntimeError("update_record is deprecated and will be removed in a future version.")

def async_update_records(self, zc: 'Zeroconf', now: float, records: List[RecordUpdate]) -> None:
def async_update_records(self, zc: 'Zeroconf', now: float_, records: List[RecordUpdate]) -> None:
"""Update multiple records in one shot.
All records that are received in a single packet are passed
Expand Down

0 comments on commit 6bf5d95

Please sign in to comment.