
    g                     2    S r SSKJr  SSKr " S S\5      rg)zDNS name dictionary    )MutableMappingNc                   d   ^  \ rS rSrSr/ SQrU 4S jrS rS rS r	S r
S	 rS
 rS rS rSrU =r$ )NameDict$   zA 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U ]  5         [        5       U l        SU l        SU l        U R                  [        U0 UD65        g )Nr   )super__init__dict_NameDict__storer   r   update)selfargskwargs	__class__s      E/home/matz/Project1/venv/lib/python3.13/site-packages/dns/namedict.pyr   NameDict.__init__-   s<    v D$)&)*    c                     [        U5      U R                  :X  a  U R                  S-   U l        g [        U5      U R                  :  a  [        U5      U l        SU l        g g )N   )lenr   r   r   keys     r   __update_max_depthNameDict.__update_max_depth6   sM    s8t~~%#'#7#7!#;D X& XDN#$D  'r   c                      U R                   U   $ Nr   r   s     r   __getitem__NameDict.__getitem__=   s    ||C  r   c                     [        U[        R                  R                  5      (       d  [	        S5      eX R
                  U'   U R                  U5        g )NzNameDict key must be a name)
isinstancednsnameName
ValueErrorr   _NameDict__update_max_depth)r   r   values      r   __setitem__NameDict.__setitem__@   s=    #sxx}}--:;;!S$r   c                    U R                   R                  U5        [        U5      U R                  :X  a  U R                  S-
  U l        U R                  S:X  a,  SU l        U R                    H  nU R                  U5        M     g g )Nr   r   )r   popr   r   r   r)   )r   r   ks      r   __delitem__NameDict.__delitem__F   sm    s8t~~%#'#7#7!#;D 1$DN\\''* " %r   c                 ,    [        U R                  5      $ r   )iterr   r   s    r   __iter__NameDict.__iter__O   s    DLL!!r   c                 ,    [        U R                  5      $ r   )r   r   r4   s    r   __len__NameDict.__len__R   s    4<<  r   c                     XR                   ;   $ r   r    r   s     r   has_keyNameDict.has_keyU   s    ll""r   c                 D   [        U5      nX R                  :  a  U R                  n[        U* S5       H1  n[        R                  R                  XS 5      nX@;   d  M+  X@U   4s  $    U [        R                  R                     n[        R                  R                  U4$ )as  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_matchNameDict.get_deepest_matchX   s     D	>>!NNEvq!Ad2h'Ay7|# "  ""r   )r	   r   r   )__name__
__module____qualname____firstlineno____doc__	__slots__r   r)   r!   r+   r0   r5   r8   r;   rD   __static_attributes____classcell__)r   s   @r   r   r   $   sA     <I+%!%+"!## #r   r   )rJ   collections.abcr   dns.namer%   r    r   r   <module>rQ      s    8  + I#~ I#r   