
    v                     N    S r SSKrSSKrSSKJr   " S S\R                  5      rg)zDNS name dictionary    N   )xrangec                   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                    > [         [        U ]  5         [        5       U l        SU l        SU l        U R                  [        U0 UD65        g )Nr   )superr   __init__dict_NameDict__storer   r	   update)selfargskwargs	__class__s      lib/third_party/dns/namedict.pyr   NameDict.__init__,   s>    h&(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 )Nr   )lenr   r	   r   keys     r   __update_max_depthNameDict.__update_max_depth5   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      n[        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   r*   ks       r   __delitem__NameDict.__delitem__E   so      %u:'#'#7#7!#;D 1$DN\\''* " %r   c                 ,    [        U R                  5      $ r   )iterr   r   s    r   __iter__NameDict.__iter__N   s    DLL!!r   c                 ,    [        U R                  5      $ r   )r   r   r4   s    r   __len__NameDict.__len__Q   s    4<<  r   c                     XR                   ;   $ r   r    r   s     r   has_keyNameDict.has_keyT   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$ )at  Find the deepest match to *fname* 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   r   r%   r&   r'   empty)r   r&   depthinvs         r   get_deepest_matchNameDict.get_deepest_matchW   s     D	>>!NNE"Ad2h'Ay7|# #  ""r   )r
   r   r	   )__name__
__module____qualname____firstlineno____doc__	__slots__r   r)   r!   r+   r0   r5   r8   r;   rC   __static_attributes____classcell__)r   s   @r   r   r   #   sA     <I+%!%+"!## #r   r   )rI   collectionsdns.namer%   _compatr   MutableMappingr    r   r   <module>rR      s'   8    I#{)) I#r   