
    |;i                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
 dd	lmZmZmZmZ ej                   Zerdd
lmZ eZeZ G d d      Zy)a  Multicast DNS Service Discovery for Python, v0.14-wmcbrine
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine

This module provides a framework for the use of DNS Service Discovery
using IP multicast.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
    )annotationsN)deque)TYPE_CHECKING   )current_time_millismillis_to_seconds   )MULTICAST_DELAY_RANDOM_INTERVALAnswerGroup_AnswerWithAdditionalsType$construct_outgoing_multicast_answers)Zeroconfc                  4    e Zd ZdZdZddZd	dZd
dZddZy)MulticastOutgoingQueuez8An outgoing queue used to aggregate multicast responses.)_additional_delay_aggregation_delay_multicast_delay_random_max_multicast_delay_random_minqueuezcc                    || _         t               | _        t        d   | _        t        d   | _        || _        || _        y )Nr   r	   )r   r   r   r
   r   r   r   r   )selfzeroconfadditional_delaymax_aggregation_delays       ^/home/ubuntu/myenv/lib/python3.12/site-packages/zeroconf/_handlers/multicast_outgoing_queue.py__init__zMulticastOutgoingQueue.__init__:   s?    ).
 ,K1+M(+J1+M(!1"7    c                :   | j                   j                  }t        r|J t        | j                  | j
                        }|| j                  z   }||z   }|| j                  z   | j                  z   }t        | j                        r:| j                  d   }||j                  k  rR|j                  j                  |       y|j                  |j                         t        |      z   | j                          | j                  j#                  t%        |||             y)z>Add a group of answers with additionals to the outgoing queue.N)r   loopr   RAND_INTr   r   r   r   lenr   
send_afteranswersupdatecall_attimer   async_readyappendr   )	r   nowr%   r!   
random_intrandom_delayr$   send_before
last_groups	            r   	async_addz MulticastOutgoingQueue.async_addE   s    ww||###d>>@`@`a
!D$:$::<'
D333d6L6LLtzz?
 BJZ222""))'2LL'8'FFHXHXY

+j+wGHr   c                l    | j                   D ]%  }|D ]  }|j                  j                  |d         ' y)z0Remove a set of answers from the outgoing queue.N)r   r%   pop)r   r%   pendingrecords       r   _remove_answers_from_queuez1MulticastOutgoingQueue._remove_answers_from_queue[   s8    zz 	2G! 2##FD12	2r   c                   | j                   }|j                  }t        r|J t               }t	        | j
                        dkD  rm| j
                  d   j                  |kD  rQ|j                  |j                         t        | j
                  d   j                  |z
        z   | j                         yi }t	        | j
                        r| j
                  d   j                  |k  re|j                  | j
                  j                         j                         t	        | j
                        r| j
                  d   j                  |k  ret	        | j
                        rP|j                  |j                         t        | j
                  d   j                  |z
        z   | j                         |r,| j                  |       |j!                  t#        |             yy)z,Process anything in the queue that is ready.Nr	   r   )r   r!   r   r   r#   r   r.   r'   r(   r   r)   r$   r&   popleftr%   r5   
async_sendr   )r   r   r!   r+   r%   s        r   r)   z"MulticastOutgoingQueue.async_readya   sn   WWww###!#tzz?Q4::a=#<#<s#B LL		/

10I0IC0OPP   .0$**o$**Q-":":c"ANN4::--/778 $**o$**Q-":":c"A tzz? LL		/

10H0H30NOO  
 ++G4MM>wGH r   N)r   r   r   _intr   r9   returnNone)r+   _floatr%   r   r:   r;   )r%   r   r:   r;   )r:   r;   )	__name__
__module____qualname____doc__	__slots__r   r0   r5   r)    r   r   r   r   .   s"    BI	8I,2!Ir   r   )r@   
__future__r   randomcollectionsr   typingr   _utils.timer   r   r%   r
   r   r   r   randintr"   _corer   floatr<   intr9   r   rB   r   r   <module>rL      sN   , #     @  >> 	
TI TIr   