a
    Sic                     @   s   d Z ddlZddlZG dd dZG dd deZG dd deZG d	d
 d
ejjZG dd deZ	G dd dejj
ZG dd deZdS )z:Utilities for collecting objects based on "is" comparison.    Nc                   @   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
   W/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/utils/object_identity.py__init__    s    z_ObjectIdentityWrapper.__init__c                 C   s   | j S r   r   r   r
   r
   r   	unwrapped#   s    z _ObjectIdentityWrapper.unwrappedc                 C   s   t |tstd| d S )NzlCannot compare wrapped object with unwrapped object. Expect the object to be `_ObjectIdentityWrapper`. Got: )
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__/   s    
z_ObjectIdentityWrapper.__lt__c                 C   s   |  | t| jt|jkS r   r   r   r
   r
   r   __gt__3   s    
z_ObjectIdentityWrapper.__gt__c                 C   s"   |d u rdS |  | | j|ju S )NF)r   r   r   r
   r
   r   __eq__7   s    
z_ObjectIdentityWrapper.__eq__c                 C   s   |  | S r   )r   r   r
   r
   r   __ne__=   s    z_ObjectIdentityWrapper.__ne__c                 C   s
   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__F   s    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| d S r   )superr   weakrefrefr   	__class__r
   r   r   N   s    z#_WeakObjectIdentityWrapper.__init__c                 C   s   |   S r   r   r   r
   r
   r   r   Q   s    z$_WeakObjectIdentityWrapper.unwrapped)r   r   r    r"   r   r#   r   __classcell__r
   r
   r(   r   r$   J   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   s   | j S )zReturns the referenced object.

        ```python
        x_ref = Reference(x)
        print(x is x_ref.deref())
        ==> True
        ```
        r   r   r
   r
   r   derefn   s    	zReference.derefN)r   r   r    r!   r"   r#   r   r,   r
   r
   r
   r   r+   V   s   r+   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   )r.   r   r
   r
   r   r      s    z!ObjectIdentityDictionary.__init__c                 C   s   t |S r   r   r   keyr
   r
   r   	_wrap_key   s    z"ObjectIdentityDictionary._wrap_keyc                 C   s   | j | | S r   r.   r2   r0   r
   r
   r   __getitem__   s    z$ObjectIdentityDictionary.__getitem__c                 C   s   || j | |< d S r   r3   )r   r1   valuer
   r
   r   __setitem__   s    z$ObjectIdentityDictionary.__setitem__c                 C   s   | j | |= d S r   r3   r0   r
   r
   r   __delitem__   s    z$ObjectIdentityDictionary.__delitem__c                 C   s
   t | jS r   lenr.   r   r
   r
   r   __len__   s    z ObjectIdentityDictionary.__len__c                 c   s   | j D ]}|jV  qd S r   )r.   r   r0   r
   r
   r   __iter__   s    
z!ObjectIdentityDictionary.__iter__c                 C   s   dt | j S )NzObjectIdentityDictionary(%s))reprr.   r   r
   r
   r   r      s    z!ObjectIdentityDictionary.__repr__N)r   r   r    r!   r"   r   r2   r4   r6   r7   r:   r;   r   r
   r
   r
   r   r-   z   s   r-   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   s   t |S r   r$   r0   r
   r
   r   r2      s    z)ObjectIdentityWeakKeyDictionary._wrap_keyc                 C   s   t t| jS r   )r9   listr.   r   r
   r
   r   r:      s    z'ObjectIdentityWeakKeyDictionary.__len__c                 c   s4   | j  }|D ] }|j}|d u r(| |= q|V  qd S r   )r.   keysr   r   r@   r1   r   r
   r
   r   r;      s    
z(ObjectIdentityWeakKeyDictionary.__iter__Nr   r   r    r!   r"   r2   r:   r;   r
   r
   r
   r   r=      s
   r=   c                   @   s|   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d Zdd Zdd ZdS )ObjectIdentitySetz6Like the built-in set, but compares objects with "is".r.   r   c                    s    t  fddt| D  _d S )Nc                 3   s   | ]}  |V  qd S r   r2   ).0objr   r
   r   	<genexpr>       z-ObjectIdentitySet.__init__.<locals>.<genexpr>)setr?   r.   )r   argsr
   r   r   r      s    zObjectIdentitySet.__init__c                 C   s   t  }| |_|S r   )rC   r.   )storageresultr
   r
   r   _from_storage   s    zObjectIdentitySet._from_storagec                 C   s   t |S r   r/   r0   r
   r
   r   r2      s    zObjectIdentitySet._wrap_keyc                 C   s   |  || jv S r   )r2   r.   r0   r
   r
   r   __contains__   s    zObjectIdentitySet.__contains__c                 C   s   | j | | d S r   )r.   discardr2   r0   r
   r
   r   rO      s    zObjectIdentitySet.discardc                 C   s   | j | | d S r   )r.   addr2   r0   r
   r
   r   rP      s    zObjectIdentitySet.addc                    s    j  fdd|D  d S )Nc                    s   g | ]}  |qS r
   rD   rE   itemr   r
   r   
<listcomp>   rH   z,ObjectIdentitySet.update.<locals>.<listcomp>)r.   updater   itemsr
   r   r   rT      s    zObjectIdentitySet.updatec                 C   s   | j   d S r   )r.   clearr   r
   r
   r   rW      s    zObjectIdentitySet.clearc                    s    j  fdd|D S )Nc                    s   g | ]}  |qS r
   rD   rQ   r   r
   r   rS      rH   z2ObjectIdentitySet.intersection.<locals>.<listcomp>)r.   intersectionrU   r
   r   r   rX      s    zObjectIdentitySet.intersectionc                    s    t  j fdd|D S )Nc                    s   g | ]}  |qS r
   rD   rQ   r   r
   r   rS      rH   z0ObjectIdentitySet.difference.<locals>.<listcomp>)rC   rM   r.   
differencerU   r
   r   r   rY      s    zObjectIdentitySet.differencec                 C   s
   t | jS r   r8   r   r
   r
   r   r:      s    zObjectIdentitySet.__len__c                 c   s    t | j}|D ]}|jV  qd S r   )r?   r.   r   )r   r@   r1   r
   r
   r   r;      s    
zObjectIdentitySet.__iter__N)r   r   r    r!   r"   r   staticmethodrM   r2   rN   rO   rP   rT   rW   rX   rY   r:   r;   r
   r
   r
   r   rC      s   
rC   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   s   t |S r   r>   r0   r
   r
   r   r2      s    zObjectIdentityWeakSet._wrap_keyc                 C   s   t dd | D S )Nc                 S   s   g | ]}|qS r
   r
   )rE   _r
   r
   r   rS      rH   z1ObjectIdentityWeakSet.__len__.<locals>.<listcomp>)r9   r   r
   r
   r   r:      s    zObjectIdentityWeakSet.__len__c                 c   s8   t | j}|D ]$}|j}|d u r,| | q|V  qd S r   )r?   r.   r   rO   rA   r
   r
   r   r;      s    
zObjectIdentityWeakSet.__iter__NrB   r
   r
   r
   r   r[      s
   r[   )r!   collectionsr&   r   r$   r+   abcMutableMappingr-   r=   
MutableSetrC   r[   r
   r
   r
   r   <module>   s   4$$3