Skip to content

Commit 64729cf

Browse files
chore(pre-commit.ci): auto fixes
1 parent ee1cebd commit 64729cf

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

src/zeroconf/_engine.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ async def _async_create_endpoints(self) -> None:
109109
reader_socket_tuples.append((s, 0))
110110
sender_sockets.append(s)
111111

112-
log.info("Creating %d reader sockets (%s) and %d sender sockets", len(reader_socket_tuples), reader_socket_tuples, len(sender_sockets))
112+
log.info(
113+
"Creating %d reader sockets (%s) and %d sender sockets",
114+
len(reader_socket_tuples),
115+
reader_socket_tuples,
116+
len(sender_sockets),
117+
)
113118
for s, interface_idx in reader_socket_tuples:
114119
log.debug("Creating endpoint for socket %s", s)
115120
transport, protocol = await loop.create_datagram_endpoint( # type: ignore[type-var]

src/zeroconf/_services/info.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def _process_record_threadsafe(self, zc: Zeroconf, record: DNSRecord, now: float
507507
assert isinstance(dns_address_record, DNSAddress)
508508
ip_addr = get_ip_address_object_from_record(dns_address_record)
509509

510-
#log.info("Got ip addr: %r with scope %d from %r", ip_addr, ip_addr.scope_id if ip_addr.scope_id else 0, dns_address_record)
510+
# log.info("Got ip addr: %r with scope %d from %r", ip_addr, ip_addr.scope_id if ip_addr.scope_id else 0, dns_address_record)
511511
if ip_addr is None:
512512
log.warning(
513513
"Encountered invalid address while processing %s: %s",
@@ -844,11 +844,7 @@ async def async_request(
844844
:param addr: address to send the request to
845845
:param port: port to send the request to
846846
"""
847-
log.info(
848-
"Asking for %s %s",
849-
question_type,
850-
self._name
851-
)
847+
log.info("Asking for %s %s", question_type, self._name)
852848
if not zc.started:
853849
await zc.async_wait_for_start()
854850

@@ -871,11 +867,7 @@ async def async_request(
871867
return False
872868
if next_ <= now:
873869
this_question_type = question_type or (QU_QUESTION if first_request else QM_QUESTION)
874-
log.info(
875-
"Generating request for %s %s",
876-
this_question_type,
877-
self._name
878-
)
870+
log.info("Generating request for %s %s", this_question_type, self._name)
879871
out = self._generate_request_query(zc, now, this_question_type)
880872
first_request = False
881873
if out.questions:

src/zeroconf/_utils/ipaddress.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
from functools import cache, lru_cache
2626
from ipaddress import AddressValueError, IPv4Address, IPv6Address, NetmaskValueError
2727
from typing import Any
28-
from .._logger import log
28+
2929
from .._dns import DNSAddress
30+
from .._logger import log
3031
from ..const import _TYPE_AAAA
3132

3233
bytes_ = bytes
@@ -124,8 +125,13 @@ def get_ip_address_object_from_record(
124125
) -> ZeroconfIPv4Address | ZeroconfIPv6Address | None:
125126
"""Get the IP address object from the record."""
126127

127-
log.info("Got ip addr: %r from %r with scope %d", record.address, record, record.scope_id if record.scope_id else 0)
128-
128+
log.info(
129+
"Got ip addr: %r from %r with scope %d",
130+
record.address,
131+
record,
132+
record.scope_id if record.scope_id else 0,
133+
)
134+
129135
if record.type == _TYPE_AAAA and record.scope_id:
130136
return ip_bytes_and_scope_to_address(record.address, record.scope_id)
131137
return cached_ip_addresses_wrapper(record.address)

src/zeroconf/_utils/net.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
import enum
2626
import errno
27-
from functools import lru_cache
2827
import ipaddress
2928
import socket
3029
import struct
3130
import sys
3231
import warnings
3332
from collections.abc import Iterable, Sequence
33+
from functools import lru_cache
3434
from typing import Any, Union, cast
3535

3636
import ifaddr
@@ -74,14 +74,17 @@ def _encode_address(address: str) -> bytes:
7474
address_family = socket.AF_INET6 if is_ipv6 else socket.AF_INET
7575
return socket.inet_pton(address_family, address)
7676

77+
7778
@lru_cache(maxsize=512)
7879
def _get_interface_name(iface: int) -> str:
7980
"""Get the interface name from the interface index."""
8081
return socket.if_indextoname(iface)
8182

8283

8384
def get_all_addresses_ipv4(adapters: Iterable[ifaddr.Adapter]) -> list[str]:
84-
return list({(addr.ip, iface.index) for iface in ifaddr.get_adapters() for addr in iface.ips if addr.is_IPv4}) # type: ignore[misc]
85+
return list(
86+
{(addr.ip, iface.index) for iface in ifaddr.get_adapters() for addr in iface.ips if addr.is_IPv4}
87+
) # type: ignore[misc]
8588

8689

8790
def get_all_addresses_ipv6(adapters: Iterable[ifaddr.Adapter]) -> list[tuple[tuple[str, int, int], int]]:
@@ -91,14 +94,18 @@ def get_all_addresses_ipv6(adapters: Iterable[ifaddr.Adapter]) -> list[tuple[tup
9194
{(addr.ip, iface.index) for iface in adapters for addr in iface.ips if addr.is_IPv6} # type: ignore[misc]
9295
)
9396

94-
def get_all_addresses_ipv6_link_local(adapters: Iterable[ifaddr.Adapter]) -> list[tuple[tuple[str, int, int], int]]:
97+
98+
def get_all_addresses_ipv6_link_local(
99+
adapters: Iterable[ifaddr.Adapter],
100+
) -> list[tuple[tuple[str, int, int], int]]:
95101
return [
96102
(ip.ip, iface.index)
97103
for iface in adapters
98104
for ip in iface.ips
99105
if ip.is_IPv6 and ip.ip[2] == iface.index
100106
]
101107

108+
102109
def get_all_addresses() -> list[str]:
103110
warnings.warn(
104111
"get_all_addresses is deprecated, and will be removed in a future version. Use ifaddr"
@@ -119,14 +126,16 @@ def get_all_addresses_v6() -> list[tuple[tuple[str, int, int], int]]:
119126
return get_all_addresses_ipv6(ifaddr.get_adapters())
120127

121128

122-
def ip_to_address_and_index(adapters: Iterable[ifaddr.Adapter], ip: str) -> tuple[tuple[str, int, int], int] | tuple[str, int]:
129+
def ip_to_address_and_index(
130+
adapters: Iterable[ifaddr.Adapter], ip: str
131+
) -> tuple[tuple[str, int, int], int] | tuple[str, int]:
123132
"""Convert IP to IP address and interface index.
124133
125134
:param adapters: List of adapters.
126135
:param ip: IP address to convert. If the address is an IPv6 with scope id, the scope id is being validated.
127136
:returns: Tuple of IP address and interface index.
128137
"""
129-
addr, sep, scope_id = ip.partition('%')
138+
addr, sep, scope_id = ip.partition("%")
130139
if not sep:
131140
scope_id = None
132141

@@ -144,10 +153,7 @@ def ip_to_address_and_index(adapters: Iterable[ifaddr.Adapter], ip: str) -> tupl
144153
return (adapter_ip.ip, adapter.index)
145154

146155
# IPv4 addresses are represented as strings
147-
if (
148-
isinstance(adapter_ip.ip, str)
149-
and ipaddress.ip_address(adapter_ip.ip) == ipaddr
150-
):
156+
if isinstance(adapter_ip.ip, str) and ipaddress.ip_address(adapter_ip.ip) == ipaddr:
151157
return (adapter_ip.ip, adapter.index)
152158

153159
raise RuntimeError(f"No adapter found for IP address {ip}")
@@ -347,11 +353,12 @@ def new_socket(
347353
log.debug("Created socket %s", s)
348354
return s
349355

356+
350357
def _bind_to_interface(
351358
s: socket.socket,
352359
ifaceidx: int,
353360
) -> None:
354-
if hasattr(socket,'SO_BINDTODEVICE'):
361+
if hasattr(socket, "SO_BINDTODEVICE"):
355362
iface = _get_interface_name(ifaceidx).encode()
356363
s.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, iface)
357364
elif sys.platform != "win32":
@@ -377,7 +384,7 @@ def add_multicast_member(
377384
err_einval |= {cast(Any, errno).WSAEINVAL} # pylint: disable=no-member
378385
log.debug("Adding %r (socket %d) to multicast group", interface, listen_socket.fileno())
379386
try:
380-
#_bind_to_interface(listen_socket, interface[1])
387+
# _bind_to_interface(listen_socket, interface[1])
381388
if is_v6:
382389
try:
383390
mdns_addr6_bytes = socket.inet_pton(socket.AF_INET6, _MDNS_ADDR6)
@@ -461,7 +468,7 @@ def new_respond_socket(
461468
# - Use ephemeral ports if in unicast mode
462469
# - Create socket according to the interface IP type (IPv4 or IPv6)
463470
respond_socket = new_socket(
464-
#bind_addr=cast(tuple[tuple[str, int, int], int], interface)[0] if is_v6 else (cast(tuple[str, int], interface)[0],),
471+
# bind_addr=cast(tuple[tuple[str, int, int], int], interface)[0] if is_v6 else (cast(tuple[str, int], interface)[0],),
465472
bind_addr=("::", 0, interface[1]),
466473
port=0 if unicast else _MDNS_PORT,
467474
ip_version=(IPVersion.V6Only if is_v6 else IPVersion.V4Only),

0 commit comments

Comments
 (0)