3
:Ad]¨  ã               @   sF   d Z ddlZddlmZ dd„ ZG dd„ dejƒZG dd	„ d	eƒZdS )
a=   Variants of weak-key dictionaries that are based on object identity.

They will ignore the ``__hash__`` and ``__eq__`` implementations on the
objects. These are intended for various kinds of caches that map instances of
classes to other things without keeping those instances alive. Note that
iteration is not guarded, so if one were iterating over these dictionaries and
one of the weakrefs got cleaned up, this might modify the structure and break
the iteration. As this is not a common use for such caches, we have not
bothered to make these dicts robust to that case.
é    N)Úrefc                s   |f‡ fdd„	}|S )Nc                s    |ƒ }|d k	r|j jˆ d ƒ d S )N)ÚdataÚpop)ÚwrÚid_dict_refZid_dict)Úkey_id© ú}/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traits-5.1.2-py3.6-linux-x86_64.egg/traits/util/weakiddict.pyÚcallback   s    z_remover.<locals>.callbackr   )r   r   r
   r   )r   r	   Ú_remover   s    r   c               @   sR   e Zd ZdZd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 )Ú
WeakIDDictzT A weak-key-value dictionary that uses the id() of the key for
    comparisons.
    Nc             C   s   i | _ |d k	r| j|ƒ d S )N)r   Úupdate)ÚselfÚdictr   r   r	   Ú__init__   s    zWeakIDDict.__init__c             C   s   dj t| ƒƒS )Nz<WeakIDDict at 0x{0:x}>)ÚformatÚid)r   r   r   r	   Ú__repr__#   s    zWeakIDDict.__repr__c             C   s   | j t|ƒ= d S )N)r   r   )r   Úkeyr   r   r	   Ú__delitem__&   s    zWeakIDDict.__delitem__c             C   s   | j t|ƒ d ƒ S )Né   )r   r   )r   r   r   r   r	   Ú__getitem__)   s    zWeakIDDict.__getitem__c             C   s>   t |tt|ƒt | ƒƒƒt |tt|ƒt | ƒƒƒf| jt|ƒ< d S )N)r   r   r   r   )r   r   Úvaluer   r   r	   Ú__setitem__,   s    zWeakIDDict.__setitem__c             C   s
   t | jƒS )N)Úlenr   )r   r   r   r	   Ú__len__2   s    zWeakIDDict.__len__c             C   s   t |ƒ| jkS )N)r   r   )r   r   r   r   r	   Ú__contains__5   s    zWeakIDDict.__contains__c             c   s6   x0| j D ]&}| j | d }|ƒ }|d k	r|V  qW d S )Nr   )r   )r   Zid_keyZwr_keyr   r   r   r	   Ú__iter__8   s
    zWeakIDDict.__iter__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r	   r      s   
r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚWeakIDKeyDictz« A weak-key dictionary that uses the id() of the key for comparisons.

    This differs from `WeakIDDict` in that it does not try to make a weakref to
    the values.
    c             C   s   | j t|ƒ d S )Nr   )r   r   )r   r   r   r   r	   r   G   s    zWeakIDKeyDict.__getitem__c             C   s*   t |tt|ƒt | ƒƒƒ|f| jt|ƒ< d S )N)r   r   r   r   )r   r   r   r   r   r	   r   J   s    zWeakIDKeyDict.__setitem__N)r   r   r    r!   r   r   r   r   r   r	   r"   @   s   r"   )r!   ÚcollectionsÚweakrefr   r   ÚMutableMappingr   r"   r   r   r   r	   Ú<module>
   s
   	'