Skip to content

Commit 43e6879

Browse files
committed
Reduce duplicate code to write records
1 parent d9ea918 commit 43e6879

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

zeroconf/_protocol.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -586,21 +586,13 @@ def _write_answers_from_offset(self, answer_offset: int) -> int:
586586
answers_written += 1
587587
return answers_written
588588

589-
def _write_authorities_from_offset(self, authority_offset: int) -> int:
590-
authorities_written = 0
591-
for authority in self.authorities[authority_offset:]:
592-
if not self._write_record(authority, 0):
589+
def _write_records_from_offset(self, records: List[DNSRecord], offset: int) -> int:
590+
records_written = 0
591+
for record in records[offset:]:
592+
if not self._write_record(record, 0):
593593
break
594-
authorities_written += 1
595-
return authorities_written
596-
597-
def _write_additionals_from_offset(self, additional_offset: int) -> int:
598-
additionals_written = 0
599-
for additional in self.additionals[additional_offset:]:
600-
if not self._write_record(additional, 0):
601-
break
602-
additionals_written += 1
603-
return additionals_written
594+
records_written += 1
595+
return records_written
604596

605597
def _has_more_to_add(
606598
self, questions_offset: int, answer_offset: int, authority_offset: int, additional_offset: int
@@ -654,8 +646,8 @@ def packets(self) -> List[bytes]:
654646

655647
questions_written = self._write_questions_from_offset(questions_offset)
656648
answers_written = self._write_answers_from_offset(answer_offset)
657-
authorities_written = self._write_authorities_from_offset(authority_offset)
658-
additionals_written = self._write_additionals_from_offset(additional_offset)
649+
authorities_written = self._write_records_from_offset(self.authorities, authority_offset)
650+
additionals_written = self._write_records_from_offset(self.additionals, additional_offset)
659651

660652
self._insert_short_at_start(additionals_written)
661653
self._insert_short_at_start(authorities_written)

0 commit comments

Comments
 (0)