Mercurial > hg > WSGraph
comparison wsgraph/web.py @ 17:1053290ba067
finish up this throwaway thing
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Mon, 10 Dec 2012 17:36:31 -0800 |
| parents | 569a5d93b8e3 |
| children | b710a2374c8d |
comparison
equal
deleted
inserted
replaced
| 16:569a5d93b8e3 | 17:1053290ba067 |
|---|---|
| 22 return json.dumps(graph.node(node), sort_keys=self.sort_keys) | 22 return json.dumps(graph.node(node), sort_keys=self.sort_keys) |
| 23 | 23 |
| 24 def node(self, node, graph, request): | 24 def node(self, node, graph, request): |
| 25 return Response(body=self.format(graph.node(node))) | 25 return Response(body=self.format(graph.node(node))) |
| 26 | 26 |
| 27 def JSONFormatter(node, graph, request): | 27 def edge(self, node1, node2, graph, request): |
| 28 return json.dumps(graph.node(node), sort_keys=True) | 28 return Response(body=self.format(graph.edge(node))) |
| 29 def JSONGraphFormatter(graph, request): | |
| 30 return json.dumps({'nodes': graph.nodes(), | |
| 31 'edges': graph.edges()}, | |
| 32 sort_keys=True) | |
| 33 | 29 |
| 34 class Dispatcher(object): | 30 class Dispatcher(object): |
| 35 | 31 |
| 36 def __init__(self, graph, | 32 def __init__(self, graph, |
| 37 graph_formatters=None, | 33 graph_formatters=None, |
| 110 segments = self.path_segments(request.path_info) | 106 segments = self.path_segments(request.path_info) |
| 111 rank = len(segments) | 107 rank = len(segments) |
| 112 if rank not in (0,1,2): | 108 if rank not in (0,1,2): |
| 113 return exc.HTTPNotFound() | 109 return exc.HTTPNotFound() |
| 114 | 110 |
| 115 | 111 # is resource in the graph? |
| 116 # is resource in the graph? [TODO] | |
| 117 if (rank == EDGE) or (rank == NODE): | 112 if (rank == EDGE) or (rank == NODE): |
| 118 if tuple(segments) not in self.graph: | 113 if tuple(segments) not in self.graph: |
| 119 return exc.HTTPNotFound() | 114 return exc.HTTPNotFound() |
| 120 | 115 |
| 121 # formatter | 116 # formatter |
