FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: restore the ordering convention broken by the repr rebuild and… · python-zeroconf/python-zeroconf@d44c3f8 · GitHub

Repository navigation

Commit d44c3f8

Browse files
authored
chore: restore the ordering convention broken by the repr rebuild and alphabetize the remaining const blocks (#1886)
1 parent 0e7c22a commit d44c3f8

4 files changed

Lines changed: 48 additions & 48 deletions

File tree

‎src/zeroconf/_dns.py‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,17 @@ def __eq__(self, other: Any) -> bool:
7979
"""Equal when key, type and class match."""
8080
return isinstance(other, DNSEntry) and self._dns_entry_matches(other)
8181

82-
@property
83-
def type_label(self) -> str:
84-
"""Human readable label for the record type."""
85-
return _type_label(self.type)
86-
8782
@property
8883
def class_label(self) -> str:
8984
"""Human readable label for the record class."""
9085
return _class_label(self.class_)
9186

92-
def _display_fields(self) -> list[tuple[str, str]]:
93-
fields = [("name", self.name), ("type", self.type_label), ("class", self.class_label)]
94-
if self.unique:
95-
fields.append(("", "unique"))
96-
return fields
87+
def entry_to_string(self, hdr: str, other: bytes | str | None) -> str:
88+
"""Compatibility alias rendering through the display formatter."""
89+
fields = self._display_fields()
90+
if other is not None:
91+
fields.append(("data", str(other)))
92+
return _format_display(hdr, fields)
9793

9894
@staticmethod
9995
def get_class_(class_: int) -> str:
@@ -105,12 +101,16 @@ def get_type(t: int) -> str:
105101
"""Compatibility alias for the type_label property."""
106102
return _type_label(t)
107103

108-
def entry_to_string(self, hdr: str, other: bytes | str | None) -> str:
109-
"""Compatibility alias rendering through the display formatter."""
110-
fields = self._display_fields()
111-
if other is not None:
112-
fields.append(("data", str(other)))
113-
return _format_display(hdr, fields)
104+
@property
105+
def type_label(self) -> str:
106+
"""Human readable label for the record type."""
107+
return _type_label(self.type)
108+
109+
def _display_fields(self) -> list[tuple[str, str]]:
110+
fields = [("name", self.name), ("type", self.type_label), ("class", self.class_label)]
111+
if self.unique:
112+
fields.append(("", "unique"))
113+
return fields
114114

115115
def _dns_entry_matches(self, other: DNSEntry) -> bool:
116116
return self.key == other.key and self.type == other.type and self.class_ == other.class_
@@ -222,35 +222,35 @@ def suppressed_by(self, msg: DNSIncoming) -> bool:
222222
return True
223223
return False
224224

225+
def to_string(self, other: bytes | str) -> str:
226+
"""Compatibility alias rendering through the display formatter."""
227+
return self._repr_with(("data", str(other)))
228+
225229
def write(self, out: DNSOutgoing) -> None:
226230
raise AbstractMethodException(f"{type(self).__name__} is missing write")
227231

232+
def _display_fields(self) -> list[tuple[str, str]]:
233+
remaining = int(self.get_remaining_ttl(current_time_millis()))
234+
return [*DNSEntry._display_fields(self), ("ttl", f"{self.ttl} ({remaining} remaining)")]
235+
228236
def _fast_init_record(self, name: str, type_: _int, class_: _int, ttl: _int, created: _float) -> None:
229237
"""Fast init for reuse."""
230238
self._fast_init_entry(name, type_, class_)
231239
self.ttl = ttl
232240
self.created = created
233241

242+
def _repr_with(self, *details: tuple[str, str]) -> str:
243+
return _format_display(type(self).__name__, [*self._display_fields(), *details])
244+
234245
def _set_created_ttl(self, created: _float, ttl: _int) -> None:
235246
"""Set the created and ttl of a record."""
236247
# It would be better if we made a copy instead of mutating the record
237248
# in place, but records currently don't have a copy method.
238249
self.created = created
239250
self.ttl = ttl
240251

241-
def _display_fields(self) -> list[tuple[str, str]]:
242-
remaining = int(self.get_remaining_ttl(current_time_millis()))
243-
return [*DNSEntry._display_fields(self), ("ttl", f"{self.ttl} ({remaining} remaining)")]
244-
245-
def _repr_with(self, *details: tuple[str, str]) -> str:
246-
return _format_display(type(self).__name__, [*self._display_fields(), *details])
247-
248-
def to_string(self, other: bytes | str) -> str:
249-
"""Compatibility alias rendering through the display formatter."""
250-
return self._repr_with(("data", str(other)))
251-
252252
def _suppressed_by_answer(self, answer: DNSRecord) -> bool:
253-
"""True when the answer matches this record with at least half its TTL left."""
253+
"""RFC 6762 section 7.1 known answer test: an equal record whose TTL is at least half of ours."""
254254
return self == answer and self.ttl / 2 < answer.ttl
255255

256256

@@ -618,17 +618,17 @@ def lookup_set(self) -> set[DNSRecord]:
618618
"""Return the lookup table as aset."""
619619
return set(self._get_lookup())
620620

621-
def _get_lookup(self) -> dict[DNSRecord, DNSRecord]:
622-
"""Return the lookup table, building it if needed."""
623-
if self._lookup is None:
624-
# Build the hash table so we can lookup the record ttl
625-
self._lookup = {record: record for record in self._records}
626-
return self._lookup
627-
628621
def suppresses(self, record: _DNSRecord) -> bool:
629622
"""True when the set holds a match with over half the record's TTL left."""
630623
lookup = self._get_lookup()
631624
other = lookup.get(record)
632625
if other is None:
633626
return False
634627
return other.ttl > (record.ttl / 2)
628+
629+
def _get_lookup(self) -> dict[DNSRecord, DNSRecord]:
630+
"""Return the lookup table, building it if needed."""
631+
if self._lookup is None:
632+
# Build the hash table so we can lookup the record ttl
633+
self._lookup = {record: record for record in self._records}
634+
return self._lookup

‎src/zeroconf/_protocol/incoming.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def _read_name(self) -> str:
399399
return name
400400

401401
def _read_others(self) -> None:
402-
"""Read the answer, authority and additional sections."""
402+
"""Parse everything after the question section in one pass."""
403403
self._did_read_others = True
404404
buf = self._buf
405405
answers = self._answers

‎src/zeroconf/_protocol/outgoing.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def write_name(self, name: str_) -> None:
326326
self._write_byte(0)
327327

328328
def write_short(self, value: int_) -> None:
329-
"""Append an unsigned short."""
329+
"""Append a 16 bit value in network order."""
330330
self.data.append(self._get_short(value))
331331
self.size += 2
332332

@@ -361,7 +361,7 @@ def _check_data_limit_or_rollback(self, start_data_length: int_, start_size: int
361361
return False
362362

363363
def _get_short(self, value: int_) -> bytes:
364-
"""Convert an unsigned short to 2 bytes."""
364+
"""Encode a 16 bit value as two network order bytes."""
365365
return SHORT_LOOKUP[value] if value < SHORT_CACHE_MAX else PACK_SHORT(value)
366366

367367
def _has_more_to_add(
@@ -380,11 +380,11 @@ def _has_more_to_add(
380380
)
381381

382382
def _insert_short_at_start(self, value: int_) -> None:
383-
"""Prepend an unsigned short as the first chunk."""
383+
"""Prepend a 16 bit value as the first chunk."""
384384
self.data.insert(0, self._get_short(value))
385385

386386
def _replace_short(self, index: int_, value: int_) -> None:
387-
"""Overwrite the chunk at index with an unsigned short."""
387+
"""Overwrite the chunk at index with a 16 bit value."""
388388
self.data[index] = self._get_short(value)
389389

390390
def _reset_for_next_packet(self) -> None:

‎src/zeroconf/const.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import re
1111
import socket
1212

13-
_UNREGISTER_TIME = 125 # ms
13+
_BROWSER_TIME = 10000 # ms
1414
_CHECK_TIME = 500 # ms
15-
_REGISTER_TIME = 225 # ms
1615
_LISTENER_TIME = 200 # ms
17-
_BROWSER_TIME = 10000 # ms
16+
_REGISTER_TIME = 225 # ms
17+
_UNREGISTER_TIME = 125 # ms
1818
_DUPLICATE_PACKET_SUPPRESSION_INTERVAL = 1000 # ms
1919
# Per-listener bounded recency window. 16 is large enough to defeat
2020
# the alternating-payload bypass (RFC 6762 §6.2, issue #1724 — even a
@@ -94,16 +94,16 @@
9494
_MAX_MSG_TYPICAL = 1460
9595

9696
# DNS header flag bits, RFC 1035 section 4.1.1 and RFC 6762 section 18
97+
_FLAGS_AA = 0x0400
98+
_FLAGS_AD = 0x0020
99+
_FLAGS_CD = 0x0010
97100
_FLAGS_QR_MASK = 0x8000
98101
_FLAGS_QR_QUERY = 0x0000
99102
_FLAGS_QR_RESPONSE = 0x8000
100-
_FLAGS_AA = 0x0400
101-
_FLAGS_TC = 0x0200
102-
_FLAGS_RD = 0x0100
103103
_FLAGS_RA = 0x8000
104+
_FLAGS_RD = 0x0100
105+
_FLAGS_TC = 0x0200
104106
_FLAGS_Z = 0x0040
105-
_FLAGS_AD = 0x0020
106-
_FLAGS_CD = 0x0010
107107

108108

109109
_CLASS_IN = 1

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL