
    iZ                     B    S r SSKJr  SSKJr  SSKJr   " S S\5      rg)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                       \ rS rSrSrSS jrS rSS jrS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rSS jrS rS rS rS rSrg)ObjectGraph   zj
A graph of objects that have a "graphident" attribute.
graphident is the key for the object in the graph
Nc                 t    Uc
  [        5       nX l        Xl        X l        SU l        UR                  U S 5        g Nr   )r   
graphidentgraphdebugindentadd_node)selfr   r   s      AC:\des-py\RoboSAPF\venv\Lib\site-packages\altgraph\ObjectGraph.py__init__ObjectGraph.__init__   s2    =GE

tT"    c                 6    S[        U 5      R                  < S3$ )N<>)type__name__)r   s    r   __repr__ObjectGraph.__repr__   s    d,,..r   c                 `    Uc  U nU R                  U5      nU R                  R                  X!S9$ )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   flattenObjectGraph.flatten    s6    
 =E  'zz"""DDr   c              #      #    U R                    H@  nU R                   R                  U5      nUc  M#  U R                   R                  U5      v   MB     g 7fN)r   	node_data)r   identnodes      r   nodesObjectGraph.nodes*   sB     ZZE::''.Djj**511  s
   ,A"Ac                    ^  Uc  T nT R                  U5      nT R                  R                  U5      u    p4nU 4S jnU" US5      U" US5      4$ )Nc              3      >#    [        5       nU4S jU  5        H2  nX1   nXB;  d  M  TR                  U5      v   UR                  U5        M4     g 7f)Nc              3   Z   >#    U  H   nTR                   R                  U5      v   M"     g 7fr$   )r   describe_edge).0er   s     r   	<genexpr><ObjectGraph.get_edges.<locals>.iter_edges.<locals>.<genexpr>8   s#     AS

0033Ss   (+)setfindNodeadd)lstnseentplr&   r   s        r   
iter_edges)ObjectGraph.get_edges.<locals>.iter_edges6   sD     5DASA$--..HHUO	 Bs
   !A)A      )r   r   describe_node)r   r'   r   _outrawincrawr9   s   `      r   	get_edgesObjectGraph.get_edges0   sX    <D  &#zz77>1f	$ &!$j&;;;r   c                     Uc  U nU R                  U5      nU R                  U5      nU R                  R                  X45      nU R                  R                  U5      $ r$   )r   r   edge_by_node	edge_data)r   fromNodetoNoder   stopedges         r   edgeDataObjectGraph.edgeData@   sV    H  *'zz&&u3zz##D))r   c                     Uc  U nU R                  U5      nU R                  U5      nU R                  R                  XE5      nU R                  R                  Xc5        g r$   )r   r   rD   update_edge_data)r   rF   rG   rJ   r   rH   rI   s          r   updateEdgeDataObjectGraph.updateEdgeDataH   sS    H  *'zz&&u3

##D3r   c                    [        U R                  X5      u  p#nU H  u  pVU R                  R                  XVSS9  M!     U H  nU R                  R                  U5        M      [	        U5      S-
  [	        U5      [	        U5      4$ )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rE      )r   r   add_edge	hide_nodelen)r   filtersvisitedremovesorphans	last_goodtailr'   s           r   filterStackObjectGraph.filterStackP   sz     %1T$K!'&OIJJ	8D  ' DJJ  &  7|aWs7|;;r   c                 d    U R                  U5      nUb  U R                  R                  U5        gg)z3
Remove the given node from the graph if it exists
N)getIdentr   rU   r   r'   r&   s      r   
removeNodeObjectGraph.removeNodeb   s/     d#JJ  ' r   c                     Uc  U nU R                  U5      nU R                  U5      nUbA  Ub=   U R                  R                  X45      nUc  gU R                  R                  U5        M<  gg)z*
Remove all edges from fromnode to tonode
N)r`   r   rD   	hide_edge)r   fromnodetonode	fromidenttoidentrI   s         r   removeReferenceObjectGraph.removeReferencej   st     HMM(+	--' W%8zz..yB<

$$T*	  &9 r   c                 p    U R                  U5      nUb  U$ U R                  U5      nUc  gUR                  $ )z%
Get the graph identifier for a node
N)r   r3   r   ra   s      r   r`   ObjectGraph.getIdenty   s?       &L}}T"<r   c                 ,    XL a  U$ [        USS5      nU$ )z&
Get the identifier for a node object
r   N)getattrra   s      r   r   ObjectGraph.getRawIdent   s!     <KlD1r   c                 (    U R                  U5      S L$ r$   )r3   r   r'   s     r   __contains__ObjectGraph.__contains__   s    }}T"$..r   c                     U R                  U5      nUc  Un U R                  R                  U5      $ ! [         a     gf = f)z
Find the node on the graph
N)r   r   r%   KeyErrorra   s      r   r3   ObjectGraph.findNode   sJ       &=E	::''.. 		s   3 
A A c                     U R                  SSU5         U R                  R                  UR                  5        g! [         a)    U R                  R                  UR                  U5         gf = f)z0
Add a node to the graph referenced by the root
   addNodeN)msgr   restore_noder   r   r   rr   s     r   rz   ObjectGraph.addNode   sV     	It$	7JJ##DOO4 	7JJ6	7s   %; 0A.-A.c                     Uc  U nU R                  U5      U R                  U5      pTUb  Uc  gU R                  SSXU5        U R                  R                  XEUS9  g)z,
Create a reference from fromnode to tonode
Nry   createReferencerR   )r`   r{   r   rT   )r   rf   rg   rE   rh   ri   s         r   r   ObjectGraph.createReference   s_     H!]]84dmmF6K7%xC

I)Dr   c                 h    U R                  U5      nUc  U" U/UQ70 UD6nU R                  U5        U$ )zT
Add a node of type cls to the graph if it does not already exist
by the given name
)r3   rz   )r   clsnameargskwms         r   
createNodeObjectGraph.createNode   s;    
 MM$9D&4&2&ALLOr   c                     U(       aP  XR                   ::  a@  [        SU R                  -  < U< SSR                  [	        [
        U5      5      < 35        ggg)z,
Print a debug message with the given level
z   N)r   printr   joinmapreprr   levelsr   s       r   r{   ObjectGraph.msg   s>     **$tdkk11chhs46OPQ %1r   c                 r    XR                   ::  a(  U R                  " X/UQ76   U R                  S-   U l        gg)z"
Print a debug message and indent
rS   N)r   r{   r   r   s       r   msginObjectGraph.msgin   s3     JJHHU%%++/DK r   c                 r    XR                   ::  a(  U R                  S-
  U l        U R                  " X/UQ76   gg)z"
Dedent and print a debug message
rS   N)r   r   r{   r   s       r   msgoutObjectGraph.msgout   s3     JJ++/DKHHU%% r   )r   r   r   r   r
   )NNr$   )r   
__module____qualname____firstlineno____doc__r   r   r!   r(   rA   rJ   rN   r]   rb   rj   r`   r   rs   r3   rz   r   r   r{   r   r   __static_attributes__ 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   