B
    3Rc                 @   s<   d dl Z G dd deZeje_dddZedkr8e  dS )    Nc               @   sr   e Zd ZdZdd Zdd Zdd Zdd	 ZdddZdddZ	dd Z
dddZdddZdd Zd ddZdS )!VLibNodezW base class for all virtual library nodes,
    defines minimal required interface

    c             O   s   g | _ g | _d S )N)	_children_parents)selfargskwargs r   .lib/python3.7/site-packages/rdkit/VLib/Node.py__init__   s    zVLibNode.__init__c             C   s   |    | S )z  part of the iterator interface )reset)r   r   r   r	   __iter__   s    zVLibNode.__iter__c             C   s   dS )zS part of the iterator interface

          raises StopIteration on failure
        Nr   )r   r   r   r	   next   s    zVLibNode.nextc             C   s   x|   D ]}|  q
W dS )z% resets our iteration state

        N)
GetParentsr   )r   parentr   r   r	   r   #   s    zVLibNode.reset   c             C   s"   | j | |r|j| dd dS )a  

        >>> p1 = VLibNode()
        >>> p2 = VLibNode()
        >>> c1 = VLibNode()
        >>> p1.AddChild(c1)
        >>> len(c1.GetParents())
        1
        >>> len(p1.GetChildren())
        1
        >>> p2.AddChild(c1,notify=0)
        >>> len(c1.GetParents())
        1
        >>> len(p2.GetChildren())
        1
        >>> c1.AddParent(p2,notify=0)
        >>> len(c1.GetParents())
        2
        >>> len(p2.GetChildren())
        1

        r   )notifyN)r   append	AddParent)r   childr   r   r   r	   AddChild0   s    zVLibNode.AddChildc             C   s"   | j | |r|j| dd dS )a*  
        >>> p1 = VLibNode()
        >>> c1 = VLibNode()
        >>> p1.AddChild(c1)
        >>> len(c1.GetParents())
        1
        >>> len(p1.GetChildren())
        1
        >>> p1.RemoveChild(c1)
        >>> len(c1.GetParents())
        0
        >>> len(p1.GetChildren())
        0
        r   )r   N)r   removeRemoveParent)r   r   r   r   r   r	   RemoveChildK   s    zVLibNode.RemoveChildc             C   s
   t | jS )N)tupler   )r   r   r   r	   GetChildren^   s    zVLibNode.GetChildrenTc             C   s"   | j | |r|j| dd dS )a  
        >>> p1 = VLibNode()
        >>> p2 = VLibNode()
        >>> c1 = VLibNode()
        >>> c1.AddParent(p1)
        >>> len(c1.GetParents())
        1
        >>> len(p1.GetChildren())
        1
        >>> c1.AddParent(p2,notify=0)
        >>> len(c1.GetParents())
        2
        >>> len(p2.GetChildren())
        0
        >>> p2.AddChild(c1,notify=0)
        >>> len(c1.GetParents())
        2
        >>> len(p2.GetChildren())
        1
        F)r   N)r   r   r   )r   r   r   r   r   r	   r   a   s    zVLibNode.AddParentc             C   s"   | j | |r|j| dd dS )a+  
        >>> p1 = VLibNode()
        >>> c1 = VLibNode()
        >>> p1.AddChild(c1)
        >>> len(c1.GetParents())
        1
        >>> len(p1.GetChildren())
        1
        >>> c1.RemoveParent(p1)
        >>> len(c1.GetParents())
        0
        >>> len(p1.GetChildren())
        0
        F)r   N)r   r   r   )r   r   r   r   r   r	   r   z   s    zVLibNode.RemoveParentc             C   s
   t | jS )N)r   r   )r   r   r   r	   r      s    zVLibNode.GetParentsFc             C   s   t | drdS d| _|rx2|  D ]&}|j| dd |r"|jdd|d q"W x2|  D ]&}|j| dd |rV|jd|dd qVW g | _g | _dS )a'  
        >>> p1 = VLibNode()
        >>> p2 = VLibNode()
        >>> c1 = VLibNode()
        >>> c2 = VLibNode()
        >>> p1.AddChild(c1)
        >>> p2.AddChild(c1)
        >>> p2.AddChild(c2)
        >>> len(c1.GetParents())
        2
        >>> len(c2.GetParents())
        1
        >>> len(p1.GetChildren())
        1
        >>> len(p2.GetChildren())
        2
        >>> c1.Destroy(propagateUp=True)
        >>> len(p2.GetChildren())
        0
        >>> len(c1.GetParents())
        0
        >>> len(c2.GetParents())
        0

        
_destroyedNTF)r   )r   propagateDownpropagateUp)	hasattrr   r   r   Destroyr   r   r   r   )r   r   r   r   or   r   r	   r      s    
zVLibNode.DestroyN)r   )r   )T)T)TFF)__name__
__module____qualname____doc__r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   	   s   



r   c             C   s*   dd l }|j|j| d\}}t| d S )Nr   )Zoptionflagsverbose)doctestZtestmodELLIPSISsysexit)r%   r&   Zfailed_r   r   r	   _runDoctests   s    r+   __main__)N)r(   objectr   r   __next__r+   r!   r   r   r   r	   <module>   s    3
