comparison wsgraph/model.py @ 38:df2a719a9b6e

stubbing deletion of nodes + edges
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 24 Dec 2012 22:57:02 -0800
parents f17a6577cc0d
children d1e9602145fa
comparison
equal deleted inserted replaced
37:f17a6577cc0d 38:df2a719a9b6e
36 36
37 @abstractmethod 37 @abstractmethod
38 def edges(self): 38 def edges(self):
39 """returns a list of all edges""" 39 """returns a list of all edges"""
40 40
41 @abstractmethod
42 def delete(self, node1, node2=None):
43 """
44 delete a node or edge if node2 is given
45 If a node is deleted, all edges to it should be deleted
46 """
47
41 def __call__(self): 48 def __call__(self):
42 """ 49 """
43 returns JSGN format of graph: 50 returns JSGN format of graph:
44 {'nodes': {'node1': {}, 51 {'nodes': {'node1': {},
45 'node2': {}, ...}, 52 'node2': {}, ...},
70 if isinstance(key, basestring) or (not isiterable(key)): 77 if isinstance(key, basestring) or (not isiterable(key)):
71 self.node(key, value) 78 self.node(key, value)
72 else: 79 else:
73 key1, key2 = key 80 key1, key2 = key
74 self.edge(key1, key2, value) 81 self.edge(key1, key2, value)
82
83 def __delitem__(self, key):
84 if isinstance(key, basestring) or (not isiterable(key)):
85 self.delete(key)
86 else:
87 key1, key2 = key
88 self.delete(key1, key2)
75 89
76 def __contains__(self, key): 90 def __contains__(self, key):
77 """ 91 """
78 if key is ..., returns if that node is in the graph 92 if key is ..., returns if that node is in the graph
79 if key is a 2-tuple/list, returns if the edge is in the graph 93 if key is a 2-tuple/list, returns if the edge is in the graph