U
    d                     @  sj   d dl mZ d dlZddlmZ ddlmZ e	 Z
G dd dZe	 ZG dd	 d	ZG d
d deeZdS )    )annotationsN   )exc)WriteOnlyCollectionc                   @  s   e Zd Zdd Zdd ZdS )BasicEntityc                 K  s"   |  D ]\}}t| || qd S N)itemssetattr)selfkwkeyvalue r   ?/tmp/pip-unpacked-wheel-wbr0uges/sqlalchemy/testing/entities.py__init__   s    zBasicEntity.__init__c              
     sl   t  tkrt S tt   z2d jjd fddt	 j
 D f W S tt   X d S )Nz%s(%s)z, c                   s(   g | ] }| d sd|t |f qS )_z%s=%r)
startswithgetattr).0r   r
   r   r   
<listcomp>    s   
z(BasicEntity.__repr__.<locals>.<listcomp>)id_repr_stackobject__repr__addremove	__class____name__joinsorted__dict__keysr   r   r   r   r      s    


zBasicEntity.__repr__N)r   
__module____qualname__r   r   r   r   r   r   r      s   r   c                   @  s   e Zd Zdd Zdd ZdS )ComparableMixinc                 C  s   |  | S r   )__eq__)r
   otherr   r   r   __ne__/   s    zComparableMixin.__ne__c              
   C  s  || krdS | j |j ksdS t| tkr,dS tt|  zTztjj| j	}W n tjj
jk
rp   d}Y nX |dkr| }|}n|dk	r|}| }n| }|}t|jD ]}|drqt||}t|trqzt||}W n$ ttjfk
r    Y  W dS X t|drnt|tsnt|drPt|dsPt|t|krl W HdS nt|t|kr W *dS q|dk	r||kr W dS qW dS tt|  X dS )z'Deep, sparse compare.

        Deeply compare two entities, following the non-None attributes of the
        non-persisted object, if possible.

        TFNr   __iter____getitem__r"   )r   r   _recursion_stackr   r   saZorm
attributesZinstance_stater   r   ZNO_STATElistr!   r   r   
isinstancer   AttributeErrorsa_excZUnboundExecutionErrorhasattrstrset)r
   r'   Zself_keyabattrr   Zbattrr   r   r   r&   2   sV    



 zComparableMixin.__eq__N)r   r#   r$   r(   r&   r   r   r   r   r%   .   s   r%   c                   @  s   e Zd Zdd ZdS )ComparableEntityc                 C  s
   t | jS r   )hashr   r   r   r   r   __hash__t   s    zComparableEntity.__hash__N)r   r#   r$   r:   r   r   r   r   r8   s   s   r8   )
__future__r   Z
sqlalchemyr,    r   r1   Zorm.writeonlyr   r4   r   r   r+   r%   r8   r   r   r   r   <module>
   s   E