B
    ADb                 @   s4   d dl Z ddlmZ ddlmZ G dd deZdS )    N   )NodePropertyError)AbsTreec               @   s   e Zd ZdZeed\ZZZZ	d'ddZ
dd	 Zd
d Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zdd Zdd Zedd Zejdd Zdd  Zedfd!d"Zd#d$ Zd%d& ZdS )(Nodez
    Nodes are elementary objects which are stored a `_nodes` dictionary of a Tree.
    Use `data` attribute to store node-specific data.
       NTFc             C   sL   d| _ | | |dkr"| j | _n|| _|| _|| _d| _t | _|| _dS )z:Create a new Node object to be placed inside a Tree objectN)		_identity_set_identity_tagexpanded_checked	_bpointerlist	_fpointerdata)selftagidentityr
   checkedr    r   9G:\easytimepro\master/mysite/admin\tree_structure\node.py__init__%   s    

zNode.__init__c             C   s   | j |j k S )N)r   )r   otherr   r   r   __lt__?   s    zNode.__lt__c             C   s,   |  |}|dkr"tt | _n|| _dS )zInitialize self._set_identityN)_node_2_nidstruuidZuuid1r   )r   nodenidr   r   r   r   B   s    
zNode._set_identityc             C   s   | j S )z Return the value of `_bpointer`.)r   )r   r   r   r   bpointerJ   s    zNode.bpointerc             C   s$   |  |}|dk	r|| _nd| _dS )zSet the value of `_bpointer`.N)r   r   )r   r   r   r   r   r   r   O   s    
c             C   s   | j S )z Return the value of `_fpointer`.)r   )r   r   r   r   fpointerZ   s    zNode.fpointerc             C   sX   |dkrt  | _nBt|t r$|| _n0t|tr>t | | _nt|trTt || _n dS )zSet the value of `_fpointer`.N)r   r   
isinstancedictkeysset)r   valuer   r   r   r   _   s    



c             C   s   | j S )z Return the value of `_identity`.)r   )r   r   r   r   r   m   s    zNode.identityc             C   s    |dkrt d n
| | dS )zSet the value of `_identity`.Nz WARNING: node ID can not be None)printr   )r   r$   r   r   r   r   r   s    
c             C   s   | j S )zWhether node is checked or not)r   )r   r   r   r   r   z   s    zNode.checkedc             C   s   t |tsd}|| _dS )zSet new checked statusFN)r    boolr   )r   r$   r   r   r   r      s    
c             C   s   t | jdkrdS dS dS )z,Return true if current node has no children.r   TFN)lenr   )r   r   r   r   is_leaf   s    zNode.is_leafc             C   s
   | j dkS )z0Return true if self has no parent, i.e. as root.N)r   )r   r   r   r   is_root   s    zNode.is_rootc             C   s   | j S )zReturn the value of `_tag`.)r	   )r   r   r   r   r      s    zNode.tagc             C   s   |dk	r|nd| _ dS )zSet the value of `_tag`.N)r	   )r   r$   r   r   r   r      s    c             C   s   |  || _dS )zUpdate parent node.N)r   r   )r   r   r   r   r   update_bpointer   s    zNode.update_bpointerc             C   s   |  |}|dkrdS || jkr.| j| nv|| jkrP|| jkr| j| nT|| jkrntd | | n6|| j	kr|dkrt
d|| j|}|| j|< dS )zUpdate all children nodes.Nz)WARNING: INSERT is deprecated to ADD modez5Argument "repalce" should be provided when mode is {})r   ADDr   appendDELETEremoveINSERTr%   update_fpointerREPLACEr   formatindex)r   r   modereplacer   Zindr   r   r   r0      s"    





zNode.update_fpointerc             C   s   d | jS )Nz{0})r2   r   )r   r   r   r   __str__   s    zNode.__str__c             C   sF   | j j}d| jd| jd| jd| jg}d|d|f S )Nztag={0}zidentity={0}zchecked={0}zdata={0}z%s(%s)z, )	__class____name__r2   r   r   r   r   join)r   namekwargsr   r   r   __repr__   s    


zNode.__repr__)NNTFN)r8   
__module____qualname____doc__r   ranger+   r-   r/   r1   r   r   r   propertyr   setterr   r   r   r(   r)   r   r*   r0   r6   r<   r   r   r   r   r      s*   
r   )r   
exceptionsr   baser   r   r   r   r   r   <module>   s   