U
    î¤ùd,  ã                   @   sL   d dl Zd dlmZ d dlmZ eG dd„ dejjƒƒZeedœdd„Z	dS )	é    N)ÚAny)Ú	immutablec                   @   s>   e Zd Zdeedœdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚDictF)Ú
dictionaryÚno_copyc                 C   s*   |rt |tƒr|| _n
t|ƒ| _d| _dS )a  Make an immutable dictionary from the specified dictionary.

        If *no_copy* is `True`, then *dictionary* will be wrapped instead
        of copied.  Only set this if you are sure there will be no external
        references to the dictionary.
        N)Ú
isinstanceÚdictÚ_odictÚ_hash)Úselfr   r   © r   ú1/tmp/pip-unpacked-wheel-pk5slln3/dns/immutable.pyÚ__init__   s    
zDict.__init__c                 C   s   | j  |¡S ©N)r	   Ú__getitem__)r   Úkeyr   r   r   r      s    zDict.__getitem__c                 C   sB   | j d kr<d}t| j ¡ ƒD ]}|t|ƒN }qt | d|¡ | j S )Nr   r
   )r
   Úsortedr	   ÚkeysÚhashÚobjectÚ__setattr__)r   Úhr   r   r   r   Ú__hash__   s    
zDict.__hash__c                 C   s
   t | jƒS r   )Úlenr	   ©r   r   r   r   Ú__len__$   s    zDict.__len__c                 C   s
   t | jƒS r   )Úiterr	   r   r   r   r   Ú__iter__'   s    zDict.__iter__N)F)
Ú__name__Ú
__module__Ú__qualname__r   Úboolr   r   r   r   r   r   r   r   r   r   	   s
   	r   )ÚoÚreturnc                 C   sª   t | tƒrt| ƒS t | tƒrRzt| ƒ | W S  tk
rP   tdd„ | D ƒƒ Y S X t | tƒrntdd„ | D ƒƒS t | tƒr¦tƒ }|  ¡ D ]\}}t	|ƒ||< q†t
|dƒS | S )z3
    Convert mutable types to immutable types.
    c                 s   s   | ]}t |ƒV  qd S r   ©Úconstify©Ú.0Úeltr   r   r   Ú	<genexpr>6   s     zconstify.<locals>.<genexpr>c                 s   s   | ]}t |ƒV  qd S r   r$   r&   r   r   r   r)   8   s     T)r   Ú	bytearrayÚbytesÚtupler   Ú	ExceptionÚlistr   Úitemsr%   r   )r"   ZcdictÚkÚvr   r   r   r%   +   s     




r%   )
Úcollections.abcÚcollectionsÚtypingr   Zdns._immutable_ctxr   ÚabcÚMappingr   r%   r   r   r   r   Ú<module>   s
   !