o
    'èh   ã                   @   s,   d Z ddlmZ ddlZG dd„ deƒZdS )zDNS name dictionaryé    )ÚMutableMappingNc                       sh   e Zd ZdZg d¢Z‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Z‡  ZS )ÚNameDictz·A 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                    s6   t ƒ  ¡  tƒ | _d| _d| _|  t|i |¤Ž¡ d S )Nr   )ÚsuperÚ__init__ÚdictÚ_NameDict__storer   r   Úupdate)ÚselfÚargsÚkwargs©Ú	__class__© úH/var/www/html/olx_land/venv/lib/python3.10/site-packages/dns/namedict.pyr   -   s
   
zNameDict.__init__c                 C   sD   t |ƒ| jkr| jd | _d S t |ƒ| jkr t |ƒ| _d| _d S d S )Né   )Úlenr   r   ©r   Úkeyr   r   r   Ú__update_max_depth6   s   

þzNameDict.__update_max_depthc                 C   s
   | j | S ©N©r
   r   r   r   r   Ú__getitem__=   ó   
zNameDict.__getitem__c                 C   s.   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   Úvaluer   r   r   Ú__setitem__@   s   
zNameDict.__setitem__c                 C   sT   | j  |¡ t|ƒ| jkr| jd | _| jdkr&d| _| j D ]	}|  |¡ qd S d S )Nr   r   )r
   Úpopr   r   r   r!   )r   r   Úkr   r   r   Ú__delitem__F   s   

ýzNameDict.__delitem__c                 C   ó
   t | jƒS r   )Úiterr
   ©r   r   r   r   Ú__iter__O   r   zNameDict.__iter__c                 C   r'   r   )r   r
   r)   r   r   r   Ú__len__R   r   zNameDict.__len__c                 C   s
   || j v S r   r   r   r   r   r   Úhas_keyU   r   zNameDict.has_keyc                 C   sn   t |ƒ}|| jkr| j}t| dƒD ]}tj ||d… ¡}|| v r*|| | f  S q| 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Úvr   r   r   Úget_deepest_matchX   s   
ÿzNameDict.get_deepest_match)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r!   r   r#   r&   r*   r+   r,   r3   Ú__classcell__r   r   r   r   r   $   s    		r   )r7   Úcollections.abcr   Údns.namer   r   r   r   r   r   Ú<module>   s   