;iZJdZddlmZddlmZddlmZGddeZdS)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_stackceZdZdZddZdZddZdZdZd Z d Z d Z d Z d Z dZdZdZdZdZddZdZdZdZdZdS) ObjectGraphzv A graph of objects that have a "graphident" attribute. graphident is the key for the object in the graph Nrc|t}||_||_||_d|_||ddSNr)r graphidentgraphdebugindentadd_node)selfr r s HC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\altgraph/ObjectGraph.py__init__zObjectGraph.__init__sF =GGE    tT"""""c2dt|jdS)N<>)type__name__)rs r__repr__zObjectGraph.__repr__sd,,,..rcl||}||}|j||S)z Iterate over the subgraph that is entirely reachable by condition starting from the given start node or the ObjectGraph root N)start condition) getRawIdentr iterdata)rrrs rflattenzObjectGraph.flatten s< =E  ''z"")"DDDrc#K|jD]:}|j|}||j|V;dSN)r node_data)ridentnodes rnodeszObjectGraph.nodes*sYZ 2 2E:''..Dj**511111 2 2rc|}|}j|\}}}}fd}||d||dfS)Nc3Kt}fd|DD]:}||}||vr,|V||;dS)Nc3LK|]}j|VdSr )r describe_edge).0ers r z.iter_edges..8s3AA 0033AAAAAAr)setfindNodeadd)lstnseentplr"rs r iter_edgesz)ObjectGraph.get_edges..iter_edges6sy55DAAAASAAA $ $A$$--.....HHUOOO  $ $r)rr describe_node)rr#r_outrawincrawr3s` r get_edgeszObjectGraph.get_edges0s| <D  &&#z77>>1ff $ $ $ $ $z&!$$jj&;&;;;rc||}||}||}|j||}|j|Sr )rr edge_by_node edge_data)rfromNodetoNoderstopedges redgeDatazObjectGraph.edgeData@s`  H  **''z&&ud33z##D)))rc||}||}||}|j||}|j||dSr )rr r<update_edge_data)rr>r?rBrr@rAs rupdateEdgeDatazObjectGraph.updateEdgeDataHsh  H  **''z&&ud33 ##D(33333rct|j||\}}}|D]"\}}|j||d#|D]}|j|t |dz t |t |fS)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) orphanr=)rr add_edge hide_nodelen)rfiltersvisitedremovesorphans last_goodtailr#s r filterStackzObjectGraph.filterStackPs%1T7$K$K!'& E EOIt J   48  D D D D ' 'D J  & & & &7||aWs7||;;rcl||}||j|dSdS)zC Remove the given node from the graph if it exists N)getIdentr rKrr#r"s r removeNodezObjectGraph.removeNodebs? d##   J  ' ' ' ' '  rc||}||}||}|=|= |j||}|dS|j|:dSdS)z: Remove all edges from fromnode to tonode N)rUr r< hide_edge)rfromnodetonode fromidenttoidentrAs rremoveReferencezObjectGraph.removeReferencejs  HMM(++ --''  W%8 +z..y'BB<E $$T***  + ! %8%8rct||}||S||}|dS|jS)z5 Get the graph identifier for a node N)rr-r rVs rrUzObjectGraph.getIdentysE  &&  L}}T"" <4rc4||ur|St|dd}|S)z6 Get the identifier for a node object r N)getattrrVs rrzObjectGraph.getRawIdents( 4<<KlD11 rc0||duSr )r-rr#s r __contains__zObjectGraph.__contains__s}}T""$..rc||}||} |j|S#t$rYdSwxYw)z, Find the node on the graph N)rr r!KeyErrorrVs rr-zObjectGraph.findNodes^  && =E :''.. .   44 s5 AAc|dd| |j|jdS#t$r$|j|j|YdSwxYw)z@ Add a node to the graph referenced by the root addNodeN)msgr restore_noder rrrcs rrizObjectGraph.addNodes{ It$$$ 7 J # #DO 4 4 4 4 4 7 7 7 J   6 6 6 6 6 6 7s:*A('A(c||}||||}}||dS|dd||||j|||dS)z< Create a reference from fromnode to tonode NrhcreateReferencerH)rUrjr rJ)rrZr[r=r\r]s rrmzObjectGraph.createReferences}  H!]]844dmmF6K6K7   F %xCCC Iw)DDDDDrcv||}|!||g|Ri|}|||S)zl Add a node of type cls to the graph if it does not already exist by the given name )r-ri)rclsnameargskwms r createNodezObjectGraph.createNodesM MM$   9D&4&&&2&&A LLOOOrc |rQ||jkrHtd|jz|ddt t |dSdSdS)z< Print a debug message with the given level z  N)r printr joinmapreprrlevelsrqs rrjzObjectGraph.msgsk  R$*$$ tdk11111chhs46O6O6OP Q Q Q Q Q R R$$rc\||jkr |j||g|R|jdz|_dSdS)z2 Print a debug message and indent rIN)r rjr r{s rmsginzObjectGraph.msginsF DJ   DHUA % % % % %+/DKKK  rc\||jkr |jdz |_|j||g|RdSdS)z2 Dedent and print a debug message rIN)r r rjr{s rmsgoutzObjectGraph.msgoutsH DJ  +/DK DHUA % % % % % % %  rr )NNr )r __module__ __qualname____doc__rrrr$r:rBrErSrWr^rUrrdr-rirmrtrjrrrrrrsd ####///EEEE222 <<< ***444<<<$((( + + +   ///    7 7 7 E E E E   RRR***&&&&&rrN) raltgraphraltgraph.Graphraltgraph.GraphUtilrobjectrrrrrs  ++++++F&F&F&F&F&&F&F&F&F&F&r