o
    ?eP                     @   s   d Z ddlmZmZ ddlZddlmZ G dd dZG dd deZG d	d
 d
eZ	G dd dej
ZG dd deZG dd dejZG dd deZdS )z:Utilities for collecting objects based on "is" comparison.    )AnySetN)collections_abcc                   @   sd   e Zd ZdZddgZdd Ze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 )_ObjectIdentityWrappera  Wraps an object, mapping __eq__ on wrapper to "is" on wrapped.

  Since __eq__ is based on object identity, it's safe to also define __hash__
  based on object ids. This lets us add unhashable types like trackable
  _ListWrapper objects to object-identity collections.
  _wrapped__weakref__c                 C   s
   || _ d S Nr   selfwrapped r   g/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/util/object_identity.py__init__!      
z_ObjectIdentityWrapper.__init__c                 C      | j S r   r	   r   r   r   r   	unwrapped$   s   z _ObjectIdentityWrapper.unwrappedc                 C   s   t |ts	tdd S )Nz3Cannot compare wrapped object with unwrapped object)
isinstancer   	TypeErrorr   otherr   r   r   _assert_type(   s   
z#_ObjectIdentityWrapper._assert_typec                 C   s   |  | t| jt|jk S r   r   idr   r   r   r   r   __lt__,      
z_ObjectIdentityWrapper.__lt__c                 C   s   |  | t| jt|jkS r   r   r   r   r   r   __gt__0   r   z_ObjectIdentityWrapper.__gt__c                 C   s"   |d u rdS |  | | j|ju S )NF)r   r   r   r   r   r   __eq__4   s   
z_ObjectIdentityWrapper.__eq__c                 C   s   |  | S r   )r   r   r   r   r   __ne__:   s   z_ObjectIdentityWrapper.__ne__c                 C   
   t | jS r   )r   r   r   r   r   r   __hash__=   s   
z_ObjectIdentityWrapper.__hash__c                 C   s   d t| j| jS )Nz<{} wrapping {!r}>)formattype__name__r   r   r   r   r   __repr__C      z_ObjectIdentityWrapper.__repr__N)r$   
__module____qualname____doc__	__slots__r   propertyr   r   r   r   r   r   r!   r%   r   r   r   r   r      s    
r   c                       s,   e Zd ZdZ fddZedd Z  ZS )_WeakObjectIdentityWrapperr   c                    s   t t| t| d S r   )superr,   r   weakrefrefr
   	__class__r   r   r   K      z#_WeakObjectIdentityWrapper.__init__c                 C   s   |   S r   r	   r   r   r   r   r   N   s   z$_WeakObjectIdentityWrapper.unwrapped)r$   r'   r(   r*   r   r+   r   __classcell__r   r   r0   r   r,   G   s
    r,   c                   @   s"   e Zd ZdZdZe Zdd ZdS )	ReferencezReference that refers an object.

  ```python
  x = [1]
  y = [1]

  x_ref1 = Reference(x)
  x_ref2 = Reference(x)
  y_ref2 = Reference(y)

  print(x_ref1 == x_ref2)
  ==> True

  print(x_ref1 == y)
  ==> False
  ```
  r   c                 C   r   )z~Returns the referenced object.

    ```python
    x_ref = Reference(x)
    print(x is x_ref.deref())
    ==> True
    ```
    r	   r   r   r   r   derefk   s   	zReference.derefN)r$   r'   r(   r)   r*   r+   r   r5   r   r   r   r   r4   S   s
    r4   c                   @   sV   e Zd ZdZdg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 )ObjectIdentityDictionarya  A mutable mapping data structure which compares using "is".

  This is necessary because we have trackable objects (_ListWrapper) which
  have behavior identical to built-in Python lists (including being unhashable
  and comparing based on the equality of their contents by default).
  _storagec                 C   s
   i | _ d S r   )r7   r   r   r   r   r      r   z!ObjectIdentityDictionary.__init__c                 C      t |S r   r   r   keyr   r   r   	_wrap_key      z"ObjectIdentityDictionary._wrap_keyc                 C   s   | j | | S r   r7   r<   r:   r   r   r   __getitem__      z$ObjectIdentityDictionary.__getitem__c                 C   s   || j | |< d S r   r>   )r   r;   valuer   r   r   __setitem__   r&   z$ObjectIdentityDictionary.__setitem__c                 C   s   | j | |= d S r   r>   r:   r   r   r   __delitem__   s   z$ObjectIdentityDictionary.__delitem__c                 C   r    r   lenr7   r   r   r   r   __len__   r   z ObjectIdentityDictionary.__len__c                 c   s    | j D ]}|jV  qd S r   )r7   r   r:   r   r   r   __iter__   s   

z!ObjectIdentityDictionary.__iter__c                 C   s   dt | j S )NzObjectIdentityDictionary(%s))reprr7   r   r   r   r   r%         z!ObjectIdentityDictionary.__repr__N)r$   r'   r(   r)   r*   r   r<   r?   rB   rC   rF   rG   r%   r   r   r   r   r6   w   s    r6   c                   @   s.   e Zd ZdZdgZdd Zdd Zdd Zd	S )
ObjectIdentityWeakKeyDictionaryz?Like weakref.WeakKeyDictionary, but compares objects with "is".r   c                 C   r8   r   r,   r:   r   r   r   r<      r=   z)ObjectIdentityWeakKeyDictionary._wrap_keyc                 C   s   t t| jS r   )rE   listr7   r   r   r   r   rF      s   z'ObjectIdentityWeakKeyDictionary.__len__c                 c   s6    | j  }|D ]}|j}|d u r| |= q|V  qd S r   )r7   keysr   r   rM   r;   r   r   r   r   rG      s   
z(ObjectIdentityWeakKeyDictionary.__iter__Nr$   r'   r(   r)   r*   r<   rF   rG   r   r   r   r   rJ      s    rJ   c                   @   s   e Zd ZdZddgZdd Zdee defdd	Z	dee defd
dZ
e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 )#ObjectIdentitySetz6Like the built-in set, but compares objects with "is".r7   r   c                    s    t  fddt| D  _d S )Nc                 3   s    | ]}  |V  qd S r   r<   ).0objr   r   r   	<genexpr>   s    z-ObjectIdentitySet.__init__.<locals>.<genexpr>)setrL   r7   )r   argsr   r   r   r      s    zObjectIdentitySet.__init__r   returnc                 C   s@   t |tstS t| t|krdS | jD ]	}||vr dS qdS NFT)r   r   NotImplementedrE   r7   r   r   itemr   r   r   __le__   s   

zObjectIdentitySet.__le__c                 C   s>   t |tstS t| t|k rdS |D ]	}|| vr dS qdS rX   )r   r   rY   rE   rZ   r   r   r   __ge__   s   
zObjectIdentitySet.__ge__c                 C   s   t  }| |_|S r   )rP   r7   )Zstorageresultr   r   r   _from_storage   s   zObjectIdentitySet._from_storagec                 C   r8   r   r9   r:   r   r   r   r<      r=   zObjectIdentitySet._wrap_keyc                 C   s   |  || jv S r   )r<   r7   r:   r   r   r   __contains__   r@   zObjectIdentitySet.__contains__c                 C      | j | | d S r   )r7   discardr<   r:   r   r   r   rb         zObjectIdentitySet.discardc                 C   ra   r   )r7   addr<   r:   r   r   r   rd      rc   zObjectIdentitySet.addc                    s    j  fdd|D  d S )Nc                       g | ]}  |qS r   rQ   rR   r[   r   r   r   
<listcomp>       z,ObjectIdentitySet.update.<locals>.<listcomp>)r7   updater   itemsr   r   r   ri      s   zObjectIdentitySet.updatec                 C   s   | j   d S r   )r7   clearr   r   r   r   rl      rI   zObjectIdentitySet.clearc                    s    j  fdd|D S )Nc                    re   r   rQ   rf   r   r   r   rg      rh   z2ObjectIdentitySet.intersection.<locals>.<listcomp>)r7   intersectionrj   r   r   r   rm      r2   zObjectIdentitySet.intersectionc                    s    t  j fdd|D S )Nc                    re   r   rQ   rf   r   r   r   rg      rh   z0ObjectIdentitySet.difference.<locals>.<listcomp>)rP   r_   r7   
differencerj   r   r   r   rn      s   zObjectIdentitySet.differencec                 C   r    r   rD   r   r   r   r   rF      r   zObjectIdentitySet.__len__c                 c   s"    t | j}|D ]}|jV  qd S r   )rL   r7   r   )r   rM   r;   r   r   r   rG      s
   

zObjectIdentitySet.__iter__N)r$   r'   r(   r)   r*   r   r   r   boolr\   r]   staticmethodr_   r<   r`   rb   rd   ri   rl   rm   rn   rF   rG   r   r   r   r   rP      s$    


rP   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
ObjectIdentityWeakSetz5Like weakref.WeakSet, but compares objects with "is".r   c                 C   r8   r   rK   r:   r   r   r   r<      r=   zObjectIdentityWeakSet._wrap_keyc                 C   s   t dd | D S )Nc                 S   s   g | ]}|qS r   r   )rR   _r   r   r   rg      s    z1ObjectIdentityWeakSet.__len__.<locals>.<listcomp>)rE   r   r   r   r   rF      s   zObjectIdentityWeakSet.__len__c                 c   s:    t | j}|D ]}|j}|d u r| | q|V  qd S r   )rL   r7   r   rb   rN   r   r   r   rG     s   
zObjectIdentityWeakSet.__iter__NrO   r   r   r   r   rq      s    rq   )r)   typingr   r   r.   Ztensorflow.python.util.compatr   r   r,   r4   MutableMappingr6   rJ   
MutableSetrP   rq   r   r   r   r   <module>   s    0$$D