102102
103103_REGISTER_BROADCASTS = 3
104104
105+ _str = str
106+ _int = int
107+ _bytes = bytes
108+
105109
106110def async_send_with_transport (
107111 log_debug : bool ,
108112 transport : _WrappedTransport ,
109- packet : bytes ,
110- packet_num : int ,
113+ packet : _bytes ,
114+ packet_num : _int ,
111115 out : DNSOutgoing ,
112- addr : Optional [str ],
113- port : int ,
114- v6_flow_scope : Union [Tuple [()], Tuple [int , int ]] = () ,
116+ addr : Optional [_str ],
117+ port : _int ,
118+ v6_flow_scope : Union [Tuple [()], Tuple [int , int ]],
115119) -> None :
116120 ipv6_socket = transport .is_ipv6
117121 if addr is None :
@@ -140,7 +144,7 @@ def async_send_with_transport(
140144 transport .transport .sendto (packet , (real_addr , port or _MDNS_PORT , * v6_flow_scope ))
141145
142146
143- class Zeroconf ( QuietLogger ) :
147+ class Zeroconf :
144148
145149 """Implementation of Zeroconf Multicast DNS Service Discovery
146150
@@ -561,17 +565,11 @@ def async_remove_listener(self, listener: RecordUpdateListener) -> None:
561565 """
562566 self .record_manager .async_remove_listener (listener )
563567
564- def handle_response (self , msg : DNSIncoming ) -> None :
565- """Deal with incoming response packets. All answers
566- are held in the cache, and listeners are notified."""
567- self .log_warning_once ("handle_response is deprecated, use record_manager.async_updates_from_response" )
568- self .record_manager .async_updates_from_response (msg )
569-
570568 def handle_assembled_query (
571569 self ,
572570 packets : List [DNSIncoming ],
573- addr : str ,
574- port : int ,
571+ addr : _str ,
572+ port : _int ,
575573 transport : _WrappedTransport ,
576574 v6_flow_scope : Union [Tuple [()], Tuple [int , int ]],
577575 ) -> None :
@@ -587,17 +585,20 @@ def handle_assembled_query(
587585 question_answers = self .query_handler .async_response (packets , ucast_source )
588586 if not question_answers :
589587 return
590- now = packets [0 ].now
588+ first_packet = packets [0 ]
589+ now = first_packet .now
591590 if question_answers .ucast :
592- questions = packets [ 0 ] .questions
593- id_ = packets [ 0 ] .id
591+ questions = first_packet .questions
592+ id_ = first_packet .id
594593 out = construct_outgoing_unicast_answers (question_answers .ucast , ucast_source , questions , id_ )
595594 # When sending unicast, only send back the reply
596595 # via the same socket that it was recieved from
597596 # as we know its reachable from that socket
598- self .async_send (out , addr , port , v6_flow_scope , transport )
597+ self ._async_send (out , addr , port , v6_flow_scope , transport )
599598 if question_answers .mcast_now :
600- self .async_send (construct_outgoing_multicast_answers (question_answers .mcast_now ))
599+ self ._async_send (
600+ construct_outgoing_multicast_answers (question_answers .mcast_now ), None , _MDNS_PORT , (), None
601+ )
601602 if question_answers .mcast_aggregate :
602603 self ._out_queue .async_add (now , question_answers .mcast_aggregate )
603604 if question_answers .mcast_aggregate_last_second :
@@ -616,7 +617,10 @@ def send(
616617 ) -> None :
617618 """Sends an outgoing packet threadsafe."""
618619 assert self .loop is not None
619- self .loop .call_soon_threadsafe (self .async_send , out , addr , port , v6_flow_scope , transport )
620+ self .loop .call_soon_threadsafe (self ._async_send , out , addr , port , v6_flow_scope , transport )
621+
622+ def _debug_enabled (self ) -> bool :
623+ return log .isEnabledFor (logging .DEBUG )
620624
621625 def async_send (
622626 self ,
@@ -625,6 +629,17 @@ def async_send(
625629 port : int = _MDNS_PORT ,
626630 v6_flow_scope : Union [Tuple [()], Tuple [int , int ]] = (),
627631 transport : Optional [_WrappedTransport ] = None ,
632+ ) -> None :
633+ """Sends an outgoing packet."""
634+ self ._async_send (out , addr , port , v6_flow_scope , transport )
635+
636+ def _async_send (
637+ self ,
638+ out : DNSOutgoing ,
639+ addr : Optional [str ],
640+ port : _int ,
641+ v6_flow_scope : Union [Tuple [()], Tuple [int , int ]],
642+ transport : Optional [_WrappedTransport ],
628643 ) -> None :
629644 """Sends an outgoing packet."""
630645 if self .done :
@@ -633,11 +648,14 @@ def async_send(
633648 # If no transport is specified, we send to all the ones
634649 # with the same address family
635650 transports = [transport ] if transport else self .engine .senders
636- log_debug = log .isEnabledFor (logging .DEBUG )
651+ log_debug = self ._debug_enabled ()
652+ max_size = _MAX_MSG_ABSOLUTE
637653
638654 for packet_num , packet in enumerate (out .packets ()):
639- if len (packet ) > _MAX_MSG_ABSOLUTE :
640- self .log_warning_once ("Dropping %r over-sized packet (%d bytes) %r" , out , len (packet ), packet )
655+ if len (packet ) > max_size :
656+ QuietLogger .log_warning_once (
657+ "Dropping %r over-sized packet (%d bytes) %r" , out , len (packet ), packet
658+ )
641659 return
642660 for send_transport in transports :
643661 async_send_with_transport (
0 commit comments