Skip to content

Commit 26fa2fb

Browse files
authored
Abstract DNSOutgoing ttl write into _write_ttl (#695)
1 parent 767546b commit 26fa2fb

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

zeroconf/_dns.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,10 @@ def _write_record_class(self, record: Union[DNSQuestion, DNSRecord]) -> None:
810810
else:
811811
self.write_short(record.class_)
812812

813+
def _write_ttl(self, record: DNSRecord, now: float) -> None:
814+
"""Write out the record ttl."""
815+
self._write_int(record.ttl if now == 0 else record.get_remaining_ttl(now))
816+
813817
def _write_record(self, record: DNSRecord, now: float) -> bool:
814818
"""Writes a record (answer, authoritative answer, additional) to
815819
the packet. Returns True on success, or False if we did not
@@ -818,10 +822,7 @@ def _write_record(self, record: DNSRecord, now: float) -> bool:
818822
self.write_name(record.name)
819823
self.write_short(record.type)
820824
self._write_record_class(record)
821-
if now == 0:
822-
self._write_int(record.ttl)
823-
else:
824-
self._write_int(record.get_remaining_ttl(now))
825+
self._write_ttl(record, now)
825826
index = len(self.data)
826827
self.write_short(0) # Will get replaced with the actual size
827828
record.write(self)

0 commit comments

Comments
 (0)