Mercurial > hg > WSGraph
comparison wsgraph/web.py @ 7:9016b126aa87
WIP
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 Dec 2012 13:55:58 -0800 |
parents | 259210f2e029 |
children | 421d5119e324 |
comparison
equal
deleted
inserted
replaced
6:259210f2e029 | 7:9016b126aa87 |
---|---|
11 GRAPH = 0 | 11 GRAPH = 0 |
12 NODE = 1 | 12 NODE = 1 |
13 EDGE = 2 | 13 EDGE = 2 |
14 | 14 |
15 # XXX stubbing hacks | 15 # XXX stubbing hacks |
16 class JSONformatter(object): | |
17 def __init__(self, sort_keys=True): | |
18 self.sort_keys = sort_keys | |
19 | |
20 def format(self, _object): | |
21 return json.dumps(graph.node(node), sort_keys=self.sort_keys) | |
22 | |
23 def node(self, node, graph, request): | |
24 return Response(body=self.format(graph.node(node))) | |
25 | |
16 def JSONFormatter(node, graph, request): | 26 def JSONFormatter(node, graph, request): |
17 return json.dumps(graph.node(node), sort_keys=True) | 27 return json.dumps(graph.node(node), sort_keys=True) |
18 def JSONGraphFormatter(graph, request): | 28 def JSONGraphFormatter(graph, request): |
19 return json.dumps({'nodes': graph.nodes(), | 29 return json.dumps({'nodes': graph.nodes(), |
20 'edges': graph.edges()}, | 30 'edges': graph.edges()}, |
92 | 102 |
93 ?format=<format> | 103 ?format=<format> |
94 | 104 |
95 """ | 105 """ |
96 | 106 |
107 # get resource requestor | |
97 segments = self.path_segments(request.path_info) | 108 segments = self.path_segments(request.path_info) |
98 if len(segments) not in (0,1,2): | 109 if len(segments) not in (0,1,2): |
99 return exc.HTTPNotFound() | 110 return exc.HTTPNotFound() |
111 | |
112 | |
113 # is resource in the graph? [TODO] | |
100 | 114 |
101 # formatter | 115 # formatter |
102 formatter = self.formatters[len(segments)] | 116 formatter = self.formatters[len(segments)] |
103 return Response(content_type='text/plain', | 117 return Response(content_type='text/plain', |
104 body="WSGraph") | 118 body="WSGraph") |