U
    Dvfq	  ã                   @   s   d Z dgZG dd„ deƒZdS )zMisc dict tools.Úhashdictc                   @   sh   e Zd Z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dd„ Zdd„ Zdd„ ZdS )r   a<  
    hashable dict implementation, suitable for use as a key into
    other dicts.

        >>> h1 = hashdict({"apples": 1, "bananas":2})
        >>> h2 = hashdict({"bananas": 3, "mangoes": 5})
        >>> h1+h2
        hashdict(apples=1, bananas=3, mangoes=5)
        >>> d1 = {}
        >>> d1[h1] = "salad"
        >>> d1[h1]
        'salad'
        >>> d1[h2]
        Traceback (most recent call last):
        ...
        KeyError: hashdict(bananas=3, mangoes=5)

    based on answers from
       http://stackoverflow.com/questions/1151658/python-hashable-dicts

    c                 C   s   t t|  ¡ ƒƒS ©N)ÚtupleÚsortedÚitems©Úself© r   ú</tmp/pip-unpacked-wheel-qlge9rch/fontTools/misc/dictTools.pyZ__key   s    zhashdict.__keyc                 C   s$   d  | jjd dd„ |  ¡ D ƒ¡¡S )Nz{0}({1})z, c                 s   s*   | ]"}d   t|d ƒt|d ƒ¡V  qdS )z{0}={1}é    é   N)ÚformatÚstrÚrepr)Ú.0Úir   r   r	   Ú	<genexpr>$   s     z$hashdict.__repr__.<locals>.<genexpr>)r   Ú	__class__Ú__name__ÚjoinÚ_hashdict__keyr   r   r   r	   Ú__repr__!   s    þzhashdict.__repr__c                 C   s   t |  ¡ ƒS r   )Úhashr   r   r   r   r	   Ú__hash__'   s    zhashdict.__hash__c                 C   s   t d | jj¡ƒ‚d S ©Nz${0} does not support item assignment©Ú	TypeErrorr   r   r   )r   ÚkeyÚvaluer   r   r	   Ú__setitem__*   s    ÿzhashdict.__setitem__c                 C   s   t d | jj¡ƒ‚d S r   r   )r   r   r   r   r	   Ú__delitem__/   s    ÿzhashdict.__delitem__c                 C   s   t d | jj¡ƒ‚d S r   r   r   r   r   r	   Úclear4   s    ÿzhashdict.clearc                 O   s   t d | jj¡ƒ‚d S r   r   ©r   ÚargsÚkwargsr   r   r	   Úpop9   s    ÿzhashdict.popc                 O   s   t d | jj¡ƒ‚d S r   r   r!   r   r   r	   Úpopitem>   s    ÿzhashdict.popitemc                 O   s   t d | jj¡ƒ‚d S r   r   r!   r   r   r	   Ú
setdefaultC   s    ÿzhashdict.setdefaultc                 O   s   t d | jj¡ƒ‚d S r   r   r!   r   r   r	   ÚupdateH   s    ÿzhashdict.updatec                 C   s   t | ƒ}t ||¡ |S r   )r   Údictr'   )r   ÚrightÚresultr   r   r	   Ú__add__P   s    zhashdict.__add__N)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r    r$   r%   r&   r'   r+   r   r   r   r	   r      s   N)r.   Ú__all__r(   r   r   r   r   r	   Ú<module>   s   