
    OhZ                     B    d Z ddlmZ ddlmZ ddlmZ  G d de      Zy)z
altgraph.ObjectGraph - Graph of objects with an identifier
==========================================================

A graph of objects that have a "graphident" attribute.
graphident is the key for the object in the graph
    )
GraphError)Graph)filter_stackc                       e Zd ZdZddZd ZddZd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zy)ObjectGraphzv
    A graph of objects that have a "graphident" attribute.
    graphident is the key for the object in the graph
    Nc                 x    |
t               }| | _        || _        || _        d| _        |j                  | d        y Nr   )r   
graphidentgraphdebugindentadd_node)selfr   r   s      f/mnt/c/Users/Administrator/Desktop/help_/test_env/lib/python3.12/site-packages/altgraph/ObjectGraph.py__init__zObjectGraph.__init__   s8    =GE

tT"    c                 4    dt        |       j                  dS )N<>)type__name__)r   s    r   __repr__zObjectGraph.__repr__   s    d,,..r   c                 f    || }| j                  |      }| j                  j                  ||      S )z
        Iterate over the subgraph that is entirely reachable by condition
        starting from the given start node or the ObjectGraph root
        )start	condition)getRawIdentr   iterdata)r   r   r   s      r   flattenzObjectGraph.flatten    s8    
 =E  'zz"")"DDr   c              #      K   | j                   D ]=  }| j                   j                  |      }|!| j                   j                  |       ? y wN)r   	node_data)r   identnodes      r   nodeszObjectGraph.nodes*   sH     ZZ 	2E::''.Djj**511	2s
   -A Ac                      | } j                  |      } j                  j                  |      \  }}}} fd} ||d       ||d      fS )Nc              3      K   t               }fd| D        D ]0  }||   }||vsj                  |       |j                  |       2 y w)Nc              3   T   K   | ]  }j                   j                  |       ! y wr    )r   describe_edge).0er   s     r   	<genexpr>z<ObjectGraph.get_edges.<locals>.iter_edges.<locals>.<genexpr>8   s      A

003As   %()setfindNodeadd)lstnseentplr"   r   s        r   
iter_edgesz)ObjectGraph.get_edges.<locals>.iter_edges6   sM     5DASA $A$--..HHUO	$s
   "A'A      )r   r   describe_node)r   r#   r   _outrawincrawr3   s   `      r   	get_edgeszObjectGraph.get_edges0   sZ    <D  &#zz77>1ff	$ &!$j&;;;r   c                     || }| j                  |      }| j                  |      }| j                  j                  ||      }| j                  j                  |      S r    )r   r   edge_by_node	edge_data)r   fromNodetoNoder   stopedges         r   edgeDatazObjectGraph.edgeData@   sX    H  *'zz&&ud3zz##D))r   c                     || }| j                  |      }| j                  |      }| j                  j                  ||      }| j                  j                  ||       y r    )r   r   r<   update_edge_data)r   r>   r?   rB   r   r@   rA   s          r   updateEdgeDatazObjectGraph.updateEdgeDataH   sW    H  *'zz&&ud3

##D(3r   c                    t        | j                  | |      \  }}}|D ]#  \  }}| j                  j                  ||d       % |D ]  }| j                  j                  |        t	        |      dz
  t	        |      t	        |      fS )z
        Filter the ObjectGraph in-place by removing all edges to nodes that
        do not match every filter in the given filter list

        Returns a tuple containing the number of:
            (nodes_visited, nodes_removed, nodes_orphaned)
        orphanr=      )r   r   add_edge	hide_nodelen)r   filtersvisitedremovesorphans	last_goodtailr#   s           r   filterStackzObjectGraph.filterStackP   s     %1T7$K!'& 	EOItJJ	48D	E  	'DJJ  &	' 7|aWs7|;;r   c                 b    | j                  |      }|| j                  j                  |       yy)zC
        Remove the given node from the graph if it exists
        N)getIdentr   rK   r   r#   r"   s      r   
removeNodezObjectGraph.removeNodeb   s/     d#JJ  ' r   c                     || }| j                  |      }| j                  |      }|?|<	 | j                  j                  ||      }|y| j                  j                  |       ;yy)z:
        Remove all edges from fromnode to tonode
        N)rU   r   r<   	hide_edge)r   fromnodetonode	fromidenttoidentrA   s         r   removeReferencezObjectGraph.removeReferencej   sv     HMM(+	--' W%8zz..y'B<

$$T*	  &9 r   c                 l    | j                  |      }||S | j                  |      }|y|j                  S )z5
        Get the graph identifier for a node
        N)r   r-   r
   rV   s      r   rU   zObjectGraph.getIdenty   s?       &L}}T"<r   c                 ,    || u r|S t        |dd      }|S )z6
        Get the identifier for a node object
        r
   N)getattrrV   s      r   r   zObjectGraph.getRawIdent   s#     4<KlD1r   c                 (    | j                  |      d uS r    )r-   r   r#   s     r   __contains__zObjectGraph.__contains__   s    }}T"$..r   c                     | j                  |      }||}	 | j                  j                  |      S # t        $ r Y yw xY w)z,
        Find the node on the graph
        N)r   r   r!   KeyErrorrV   s      r   r-   zObjectGraph.findNode   sJ       &=E	::''.. 		s   2 	>>c                     | j                  dd|       	 | j                  j                  |j                         y# t        $ r) | j                  j                  |j                  |       Y yw xY w)z@
        Add a node to the graph referenced by the root
           addNodeN)msgr   restore_noder
   r   r   rc   s     r   ri   zObjectGraph.addNode   sV     	It$	7JJ##DOO4 	7JJ6	7s   %; /A-,A-c                     || }| j                  |      | j                  |      }}||y| j                  dd|||       | j                  j                  |||       y)z<
        Create a reference from fromnode to tonode
        Nrh   createReferencerH   )rU   rj   r   rJ   )r   rZ   r[   r=   r\   r]   s         r   rm   zObjectGraph.createReference   se     H!]]84dmmF6K7	%xC

Iw)Dr   c                 f    | j                  |      }| ||g|i |}| j                  |       |S )zl
        Add a node of type cls to the graph if it does not already exist
        by the given name
        )r-   ri   )r   clsnameargskwms         r   
createNodezObjectGraph.createNode   s;    
 MM$9D&4&2&ALLOr   c                     |rM|| j                   k  r=t        d| j                  z  |ddj                  t	        t
        |                   yyy)z<
        Print a debug message with the given level
        z   N)r   printr   joinmapreprr   levelsrq   s       r   rj   zObjectGraph.msg   s@     $**$tdkk11chhs46OPQ %1r   c                 t    || j                   k  r) | j                  ||g|  | j                  dz   | _        yy)z2
        Print a debug message and indent
        rI   N)r   rj   r   r{   s       r   msginzObjectGraph.msgin   s9     DJJDHHUA%%++/DK r   c                 t    || j                   k  r)| j                  dz
  | _         | j                  ||g|  yy)z2
        Dedent and print a debug message
        rI   N)r   r   rj   r{   s       r   msgoutzObjectGraph.msgout   s9     DJJ++/DKDHHUA%% r   r	   )NNr    )r   
__module____qualname____doc__r   r   r   r$   r:   rB   rE   rS   rW   r^   rU   r   rd   r-   ri   rm   rt   rj   r   r    r   r   r   r      sn    
#/E2< *4<$(+
/
	7
E	R*&r   r   N)	r   altgraphr   altgraph.Graphr   altgraph.GraphUtilr   objectr   r   r   r   <module>r      s#        +F&& F&r   