comparison wsgraph/model.py @ 23:24d57daaca21

well, now the request dispatches
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Dec 2012 21:15:24 -0800
parents ee45f44394a0
children d1a8c1436ded
comparison
equal deleted inserted replaced
22:a401bf63c938 23:24d57daaca21
27 """ 27 """
28 28
29 @abstractmethod 29 @abstractmethod
30 def edges(self): 30 def edges(self):
31 """returns a list of all edges""" 31 """returns a list of all edges"""
32
33 def __call__(self):
34 """
35 returns JSGN format of graph:
36 {'nodes': {'node1': {},
37 'node2': {}, ...},
38 'edges': {'node1': {'node2': {},
39 'node3': {}, ...},
40 'node2': {'node1': {}, ...}}
41 }
42 """
43 retval = {'nodes': {}, 'edges': {}}
44 for node in self.nodes():
45 retval['nodes'][node] = self.node(node)
46 for node1, node2 in self.edges():
47 retval['edges'].setdefault(node1, {})[node2] = self.edge(node1, node2)
48 return retval
32 49
33 def __getitem__(self, key): 50 def __getitem__(self, key):
34 """ 51 """
35 if key is a basestring, return the node of that name; 52 if key is a basestring, return the node of that name;
36 if key is a 2-tuple/list, return the edge of that name 53 if key is a 2-tuple/list, return the edge of that name