2323import enum
2424import errno
2525import ipaddress
26+ import itertools
2627import logging
2728import platform
2829import re
@@ -2936,9 +2937,7 @@ def handle_response(self, msg: DNSIncoming) -> None: # pylint: disable=too-many
29362937 # zc.get_service_info will see the cached value
29372938 # but ONLY after all the record updates have been
29382939 # processsed.
2939- for record in address_adds :
2940- self .cache .add (record )
2941- for record in other_adds :
2940+ for record in itertools .chain (address_adds , other_adds ):
29422941 self .cache .add (record )
29432942 # Removes are processed last since
29442943 # ServiceInfo could generate an un-needed query
@@ -2951,21 +2950,19 @@ def handle_query( # pylint: disable=too-many-branches
29512950 ) -> None :
29522951 """Deal with incoming query packets. Provides a response if
29532952 possible."""
2954- out = None
2955-
29562953 # Support unicast client responses
29572954 #
29582955 if port != _MDNS_PORT :
29592956 out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA , multicast = False )
29602957 for question in msg .questions :
29612958 out .add_question (question )
2959+ else :
2960+ out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA )
29622961
29632962 for question in msg .questions :
29642963 if question .type == _TYPE_PTR :
29652964 if question .name == "_services._dns-sd._udp.local." :
29662965 for stype in self .registry .get_types ():
2967- if out is None :
2968- out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA )
29692966 out .add_answer (
29702967 msg ,
29712968 DNSPointer (
@@ -2979,8 +2976,6 @@ def handle_query( # pylint: disable=too-many-branches
29792976 continue
29802977
29812978 for service in self .registry .get_infos_type (question .name ):
2982- if out is None :
2983- out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA )
29842979 out .add_answer (msg , service .dns_pointer ())
29852980 # Add recommended additional answers according to
29862981 # https://tools.ietf.org/html/rfc6763#section-12.1.
@@ -2991,9 +2986,6 @@ def handle_query( # pylint: disable=too-many-branches
29912986
29922987 continue
29932988
2994- if out is None :
2995- out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA )
2996-
29972989 name_to_find = question .name .lower ()
29982990 # Answer A record queries for any service addresses we know
29992991 if question .type in (_TYPE_A , _TYPE_ANY ):
0 commit comments