Skip to content

Commit 5e24da0

Browse files
authored
Reduce branching in Zeroconf.handle_query (#460)
1 parent 6fafdee commit 5e24da0

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

zeroconf/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,21 +2950,19 @@ def handle_query( # pylint: disable=too-many-branches
29502950
) -> None:
29512951
"""Deal with incoming query packets. Provides a response if
29522952
possible."""
2953-
out = None
2954-
29552953
# Support unicast client responses
29562954
#
29572955
if port != _MDNS_PORT:
29582956
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA, multicast=False)
29592957
for question in msg.questions:
29602958
out.add_question(question)
2959+
else:
2960+
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
29612961

29622962
for question in msg.questions:
29632963
if question.type == _TYPE_PTR:
29642964
if question.name == "_services._dns-sd._udp.local.":
29652965
for stype in self.registry.get_types():
2966-
if out is None:
2967-
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
29682966
out.add_answer(
29692967
msg,
29702968
DNSPointer(
@@ -2978,8 +2976,6 @@ def handle_query( # pylint: disable=too-many-branches
29782976
continue
29792977

29802978
for service in self.registry.get_infos_type(question.name):
2981-
if out is None:
2982-
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
29832979
out.add_answer(msg, service.dns_pointer())
29842980
# Add recommended additional answers according to
29852981
# https://tools.ietf.org/html/rfc6763#section-12.1.
@@ -2990,9 +2986,6 @@ def handle_query( # pylint: disable=too-many-branches
29902986

29912987
continue
29922988

2993-
if out is None:
2994-
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
2995-
29962989
name_to_find = question.name.lower()
29972990
# Answer A record queries for any service addresses we know
29982991
if question.type in (_TYPE_A, _TYPE_ANY):

0 commit comments

Comments
 (0)