
    8j                    X    d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 e
Z G d d          ZdS )	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
    )annotations   )DNSQuestion	DNSRecord)_DUPLICATE_QUESTION_INTERVAL$_MAX_KNOWN_ANSWERS_PER_HISTORY_ENTRY_MAX_QUESTION_HISTORY_ENTRIESc                  B    e Zd ZdZddZddZddZddZddZddZ	dS )QuestionHistoryz%Remember questions and known answers.returnNonec                    i | _         dS )zInit a new QuestionHistory.N)_historyselfs    G/home/user/adhan/venv/lib/python3.11/site-packages/zeroconf/_history.py__init__zQuestionHistory.__init__)   s    IK    questionr   now_floatknown_answersset[DNSRecord]c                    t          |          t          k    rdS || j        vr2t          | j                  t          k    r|                     |           ||f| j        |<   dS )z'Remember a question with known answers.N)lenr   r   r	   _evict_to_make_room)r   r   r   r   s       r   add_question_at_timez$QuestionHistory.add_question_at_time-   sj    } DDD F4=((S-?-?C`-`-`$$S)))#&"6hr   boolc                t    | j                             |          }|sdS |\  }}||z
  t          k    rdS ||z
   S )a/  Check to see if a question should be suppressed.

        https://datatracker.ietf.org/doc/html/rfc6762#section-7.3
        When multiple queriers on the network are querying
        for the same resource records, there is no need for them to all be
        repeatedly asking the same question.
        F)r   getr   )r   r   r   r   previous_questionthanprevious_known_answerss          r   
suppresseszQuestionHistory.suppresses<   sW     !M--h77  	5'8$$:4445 *M999r   c                    g }| j                                         D ]-\  }}|\  }}||z
  t          k    r|                    |           .|D ]
}| j         |= dS )z$Expire the history of old questions.N)r   itemsr   append)r   r   removesr   now_known_answersr"   _s          r   async_expirezQuestionHistory.async_expireP   s|    %'+/=+>+>+@+@ 	) 	)'H''GD!Tz888x((( 	( 	(Hh''	( 	(r   c                8    | j                                          dS )zClear the history.N)r   clearr   s    r   r-   zQuestionHistory.clearZ   s    r   c                ~   t          t          | j                            }| j        |         }|d         }||z
  t          k    r|                     |           t          | j                  t          k    rF| j        t          t          | j                            = t          | j                  t          k    DdS dS )uT  Drop expired or oldest entries when the history is at cap.

        Peeks at the oldest insertion (dict is ordered) — only runs the
        full O(n) async_expire sweep if it could actually reclaim
        something, else a sustained flood at cap turns each insert into
        a wasted scan. Falls back to oldest-first eviction.
        r   N)nextiterr   r   r+   r   r	   )r   r   oldestoldest_entryoldest_thans        r   r   z#QuestionHistory._evict_to_make_room^   s     d4=))**}V,"1o;;;c"""$-  $AAAd4#6#6778 $-  $AAAAAAAr   N)r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   )
__name__
__module____qualname____doc__r   r   r$   r+   r-   r    r   r   r   r   &   s        //L L L L7 7 7 7: : : :(( ( ( (   9 9 9 9 9 9r   r   N)r7   
__future__r   _dnsr   r   constr   r   r	   floatr   r   r8   r   r   <module>r=      s    , # " " " " " ( ( ( ( ( ( ( (          
F9 F9 F9 F9 F9 F9 F9 F9 F9 F9r   