Skip to content
Merged
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
111 changes: 0 additions & 111 deletions examples/async_browser.py

This file was deleted.

75 changes: 0 additions & 75 deletions examples/async_registration.py

This file was deleted.

17 changes: 0 additions & 17 deletions src/zeroconf/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ def async_expire(self, now: _float) -> list[DNSRecord]:
return expired

def async_get_unique(self, entry: _UniqueRecordsType) -> DNSRecord | None:
"""Gets a unique entry by key. Will return None if there is no
matching entry.

This function is not threadsafe and must be called from
the event loop.
"""
store = self.cache.get(entry.key)
if store is None:
return None
Expand All @@ -238,19 +232,9 @@ def async_all_by_details(self, name: _str, type_: _int, class_: _int) -> list[DN
return matches

def async_entries_with_name(self, name: str) -> list[DNSRecord]:
"""Returns a dict of entries whose key matches the name.

This function is not threadsafe and must be called from
the event loop.
"""
return self.entries_with_name(name)

def async_entries_with_server(self, name: str) -> list[DNSRecord]:
"""Returns a dict of entries whose key matches the server.

This function is not threadsafe and must be called from
the event loop.
"""
return self.entries_with_server(name)

# The below functions are threadsafe and do not need to be run in the
Expand Down Expand Up @@ -295,7 +279,6 @@ def get_all_by_details(self, name: str, type_: _int, class_: _int) -> list[DNSRe
return [entry for entry in list(records.values()) if type_ == entry.type and class_ == entry.class_]

def entries_with_server(self, server: str) -> list[DNSRecord]:
"""Returns a list of entries whose server matches the name."""
if entries := self.service_cache.get(server.lower()):
return list(entries.values())
return []
Expand Down
47 changes: 0 additions & 47 deletions src/zeroconf/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ def listeners(self) -> set[RecordUpdateListener]:
return self.record_manager.listeners

async def async_wait(self, timeout: float) -> None:
"""Calling task waits for a given number of milliseconds or until notified."""
loop = self.loop
assert loop is not None
await wait_for_future_set_or_timeout(loop, self._notify_futures, timeout)
Expand All @@ -303,15 +302,6 @@ def get_service_info(
timeout: int = 3000,
question_type: DNSQuestionType | None = None,
) -> ServiceInfo | None:
"""Returns network's service information for a particular
name and type, or None if no service matches by the timeout,
which defaults to 3 seconds.

:param type_: fully qualified service type name
:param name: the name of the service
:param timeout: milliseconds to wait for a response
:param question_type: The type of questions to ask (DNSQuestionType.QM or DNSQuestionType.QU)
"""
info = ServiceInfo(type_, name)
if info.request(self, timeout, question_type):
return info
Expand Down Expand Up @@ -341,17 +331,6 @@ def register_service(
cooperating_responders: bool = False,
strict: bool = True,
) -> None:
"""Registers service information to the network with a default TTL.
Zeroconf will then respond to requests for information for that
service. The name of the service may be changed if needed to make
it unique on the network. Additionally multiple cooperating responders
can register the same service on the network for resilience
(if you want this behavior set `cooperating_responders` to `True`).

While it is not expected during normal operation,
this function may raise EventLoopBlocked if the underlying
call to `register_service` cannot be completed.
"""
assert self.loop is not None
run_coro_with_timeout(
await_awaitable(
Expand All @@ -369,12 +348,6 @@ async def async_register_service(
cooperating_responders: bool = False,
strict: bool = True,
) -> Awaitable:
"""Registers service information to the network with a default TTL.
Zeroconf will then respond to requests for information for that
service. The name of the service may be changed if needed to make
it unique on the network. Additionally multiple cooperating responders
can register the same service on the network for resilience
(if you want this behavior set `cooperating_responders` to `True`)."""
if ttl is not None:
# ttl argument is used to maintain backward compatibility
# Setting TTLs via ServiceInfo is preferred
Expand All @@ -388,14 +361,6 @@ async def async_register_service(
return asyncio.ensure_future(self._async_broadcast_service(info, _REGISTER_TIME, None))

def update_service(self, info: ServiceInfo) -> None:
"""Registers service information to the network with a default TTL.
Zeroconf will then respond to requests for information for that
service.

While it is not expected during normal operation,
this function may raise EventLoopBlocked if the underlying
call to `async_update_service` cannot be completed.
"""
assert self.loop is not None
run_coro_with_timeout(
await_awaitable(self.async_update_service(info)),
Expand All @@ -404,9 +369,6 @@ def update_service(self, info: ServiceInfo) -> None:
)

async def async_update_service(self, info: ServiceInfo) -> Awaitable:
"""Registers service information to the network with a default TTL.
Zeroconf will then respond to requests for information for that
service."""
self.registry.async_update(info)
return asyncio.ensure_future(self._async_broadcast_service(info, _REGISTER_TIME, None))

Expand Down Expand Up @@ -502,15 +464,6 @@ async def async_get_service_info(
timeout: int = 3000,
question_type: DNSQuestionType | None = None,
) -> AsyncServiceInfo | None:
"""Returns network's service information for a particular
name and type, or None if no service matches by the timeout,
which defaults to 3 seconds.

:param type_: fully qualified service type name
:param name: the name of the service
:param timeout: milliseconds to wait for a response
:param question_type: The type of questions to ask (DNSQuestionType.QM or DNSQuestionType.QU)
"""
info = AsyncServiceInfo(type_, name)
if await info.async_request(self, timeout, question_type):
return info
Expand Down
11 changes: 0 additions & 11 deletions src/zeroconf/_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ def __repr__(self) -> str:


class DNSRecord(DNSEntry): # noqa: PLW1641
"""A DNS record - like a DNS entry, but has a TTL"""

__slots__ = ("created", "ttl")

def __init__(
Expand Down Expand Up @@ -203,12 +201,10 @@ def get_expiration_time(self, percent: _int) -> float:

# TODO: Switch to just int here
def get_remaining_ttl(self, now: _float) -> int | float:
"""Returns the remaining TTL in seconds."""
remain = (self.created + (_EXPIRE_FULL_TIME_MS * self.ttl) - now) / 1000.0
return 0 if remain < 0 else remain

def is_expired(self, now: _float) -> bool:
"""Returns true if this record has expired."""
return self.created + (_EXPIRE_FULL_TIME_MS * self.ttl) <= now

def is_stale(self, now: _float) -> bool:
Expand Down Expand Up @@ -322,16 +318,13 @@ def _fast_init(
self._hash = hash((self.key, type_, self.class_, cpu, os))

def write(self, out: DNSOutgoing) -> None:
"""Used in constructing an outgoing packet"""
out.write_character_string(self.cpu.encode("utf-8"))
out.write_character_string(self.os.encode("utf-8"))

def __eq__(self, other: Any) -> bool:
"""Tests equality on cpu and os."""
return isinstance(other, DNSHinfo) and self._eq(other)

def _eq(self, other: DNSHinfo) -> bool:
"""Tests equality on cpu and os."""
return self.cpu == other.cpu and self.os == other.os and self._dns_entry_matches(other)

def __hash__(self) -> int:
Expand Down Expand Up @@ -490,7 +483,6 @@ def __eq__(self, other: Any) -> bool:
return isinstance(other, DNSService) and self._eq(other)

def _eq(self, other: DNSService) -> bool:
"""Tests equality on priority, weight, port and server."""
return (
self.priority == other.priority
and self.weight == other.weight
Expand Down Expand Up @@ -541,7 +533,6 @@ def _fast_init(
self._hash = hash((self.key, type_, self.class_, next_name, *self.rdtypes))

def write(self, out: DNSOutgoing) -> None:
"""Used in constructing an outgoing packet."""
bitmap = bytearray(b"\0" * 32)
total_octets = 0
for rdtype in self.rdtypes:
Expand Down Expand Up @@ -613,8 +604,6 @@ def _get_lookup(self) -> dict[DNSRecord, DNSRecord]:
return self._lookup

def suppresses(self, record: _DNSRecord) -> bool:
"""Returns true if any answer in the rrset can suffice for the
information held in this record."""
lookup = self._get_lookup()
other = lookup.get(record)
if other is None:
Expand Down
Loading
Loading