Skip to content

Commit 6bf5d95

Browse files
authored
chore: prepare ServiceInfo base class RecordUpdateListener for cython (#1263)
1 parent a537a31 commit 6bf5d95

9 files changed

Lines changed: 53 additions & 10 deletions

File tree

build_ext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def build(setup_kwargs: Any) -> None:
3333
"src/zeroconf/_handlers/record_manager.py",
3434
"src/zeroconf/_handlers/query_handler.py",
3535
"src/zeroconf/_services/registry.py",
36+
"src/zeroconf/_updates.py",
3637
"src/zeroconf/_utils/time.py",
3738
],
3839
compiler_directives={"language_level": "3"}, # Python 3

src/zeroconf/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from ._logger import QuietLogger, log # noqa # import needed for backwards compat
5151
from ._protocol.incoming import DNSIncoming # noqa # import needed for backwards compat
5252
from ._protocol.outgoing import DNSOutgoing # noqa # import needed for backwards compat
53+
from ._record_update import RecordUpdate
5354
from ._services import ( # noqa # import needed for backwards compat
5455
ServiceListener,
5556
ServiceStateChange,
@@ -65,7 +66,7 @@
6566
ServiceRegistry,
6667
)
6768
from ._services.types import ZeroconfServiceTypes
68-
from ._updates import RecordUpdate, RecordUpdateListener
69+
from ._updates import RecordUpdateListener
6970
from ._utils.name import service_type_name # noqa # import needed for backwards compat
7071
from ._utils.net import ( # noqa # import needed for backwards compat
7172
InterfaceChoice,

src/zeroconf/_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import threading
2727
from typing import TYPE_CHECKING, List, Optional, cast
2828

29-
from ._updates import RecordUpdate
29+
from ._record_update import RecordUpdate
3030
from ._utils.asyncio import get_running_loop, run_coro_with_timeout
3131
from ._utils.time import current_time_millis
3232
from .const import _CACHE_CLEANUP_INTERVAL

src/zeroconf/_handlers/record_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from .._dns import DNSQuestion, DNSRecord
2727
from .._logger import log
2828
from .._protocol.incoming import DNSIncoming
29-
from .._updates import RecordUpdate, RecordUpdateListener
29+
from .._record_update import RecordUpdate
30+
from .._updates import RecordUpdateListener
3031
from .._utils.time import current_time_millis
3132
from ..const import _ADDRESS_RECORD_TYPES, _DNS_PTR_MIN_TTL, _TYPE_PTR
3233

src/zeroconf/_record_update.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
""" Multicast DNS Service Discovery for Python, v0.14-wmcbrine
2+
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine
3+
4+
This module provides a framework for the use of DNS Service Discovery
5+
using IP multicast.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20+
USA
21+
"""
22+
23+
from typing import NamedTuple, Optional
24+
25+
from ._dns import DNSRecord
26+
27+
28+
class RecordUpdate(NamedTuple):
29+
new: DNSRecord
30+
old: Optional[DNSRecord]

src/zeroconf/_services/browser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@
4444
from .._dns import DNSPointer, DNSQuestion, DNSQuestionType
4545
from .._logger import log
4646
from .._protocol.outgoing import DNSOutgoing
47+
from .._record_update import RecordUpdate
4748
from .._services import (
4849
ServiceListener,
4950
ServiceStateChange,
5051
Signal,
5152
SignalRegistrationInterface,
5253
)
53-
from .._updates import RecordUpdate, RecordUpdateListener
54+
from .._updates import RecordUpdateListener
5455
from .._utils.name import cached_possible_types, service_type_name
5556
from .._utils.time import current_time_millis, millis_to_seconds
5657
from ..const import (

src/zeroconf/_services/info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
from .._exceptions import BadTypeInNameException
3939
from .._logger import log
4040
from .._protocol.outgoing import DNSOutgoing
41-
from .._updates import RecordUpdate, RecordUpdateListener
41+
from .._record_update import RecordUpdate
42+
from .._updates import RecordUpdateListener
4243
from .._utils.asyncio import (
4344
_resolve_all_futures_to_none,
4445
get_running_loop,

src/zeroconf/_updates.pxd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
import cython
3+
4+
5+
cdef class RecordUpdateListener:
6+
7+
cpdef async_update_records(self, object zc, object now, cython.list records)
8+
9+
cpdef async_update_records_complete(self)

src/zeroconf/_updates.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
USA
2121
"""
2222

23-
from typing import TYPE_CHECKING, List, NamedTuple, Optional
23+
from typing import TYPE_CHECKING, List
2424

2525
from ._dns import DNSRecord
26+
from ._record_update import RecordUpdate
2627

2728
if TYPE_CHECKING:
2829
from ._core import Zeroconf
2930

3031

31-
class RecordUpdate(NamedTuple):
32-
new: DNSRecord
33-
old: Optional[DNSRecord]
32+
float_ = float
3433

3534

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

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

0 commit comments

Comments
 (0)