
    Eqg                     :    d Z ddlmZ ddlZ G d de          ZdS )zDNS name dictionary    )MutableMappingNc                   Z     e Zd ZdZg dZ fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z xZS )NameDictzA dictionary whose keys are dns.name.Name objects.

    In addition to being like a regular Python dictionary, this
    dictionary can also get the deepest match for a given key.
    )	max_depthmax_depth_items__storec                     t                                                       t                      | _        d| _        d| _        |                     t          |i |           d S )Nr   )super__init__dict_NameDict__storer   r   update)selfargskwargs	__class__s      >/var/www/html/env/lib/python3.11/site-packages/dns/namedict.pyr   zNameDict.__init__-   sX    vv D$)&))*****    c                     t          |          | j        k    r| j        dz   | _        d S t          |          | j        k    rt          |          | _        d| _        d S d S )N   )lenr   r   r   keys     r   __update_max_depthzNameDict.__update_max_depth6   sa    s88t~%%#'#7!#;D   XX&& XXDN#$D    '&r   c                     | j         |         S Nr   r   s     r   __getitem__zNameDict.__getitem__=   s    |C  r   c                     t          |t          j        j                  st	          d          || j        |<   |                     |           d S )NzNameDict key must be a name)
isinstancednsnameName
ValueErrorr   _NameDict__update_max_depth)r   r   values      r   __setitem__zNameDict.__setitem__@   sM    #sx}-- 	<:;;;!S$$$$$r   c                     | j                             |           t          |          | j        k    r| j        dz
  | _        | j        dk    r&d| _        | j         D ]}|                     |           d S d S )Nr   r   )r   popr   r   r   r%   )r   r   ks      r   __delitem__zNameDict.__delitem__F   s    s88t~%%#'#7!#;D 1$$DN\ + +''**** %$+ +r   c                 *    t          | j                  S r   )iterr   r   s    r   __iter__zNameDict.__iter__O   s    DL!!!r   c                 *    t          | j                  S r   )r   r   r.   s    r   __len__zNameDict.__len__R   s    4<   r   c                     || j         v S r   r   r   s     r   has_keyzNameDict.has_keyU   s    dl""r   c                 .   t          |          }|| j        k    r| j        }t          | d          D ]9}t          j                            ||d                   }|| v r|| |         fc S :| t          j        j                 }t          j        j        |fS )a  Find the deepest match to *name* in the dictionary.

        The deepest match is the longest name in the dictionary which is
        a superdomain of *name*.  Note that *superdomain* includes matching
        *name* itself.

        *name*, a ``dns.name.Name``, the name to find.

        Returns a ``(key, value)`` where *key* is the deepest
        ``dns.name.Name``, and *value* is the value associated with *key*.
        r   N)r   r   ranger!   r"   r#   empty)r   r"   depthinvs         r   get_deepest_matchzNameDict.get_deepest_matchX   s     D		4>!!NEvq!! 	$ 	$Ad122h''ADyy47|###  ""r   )__name__
__module____qualname____doc__	__slots__r   r%   r   r'   r+   r/   r1   r3   r;   __classcell__)r   s   @r   r   r   $   s          <;;I+ + + + +% % %! ! !% % %+ + +" " "! ! !# # ## # # # # # #r   r   )r?   collections.abcr   dns.namer!   r    r   r   <module>rE      sh   8   + * * * * * I# I# I# I# I#~ I# I# I# I# I#r   