# HG changeset patch # User Jeff Hammel # Date 1355190143 28800 # Node ID b710a2374c8d7d670a1b81a337331bfa5557bb95 # Parent 1053290ba067b778be586dab73c297379253c975 more stubbing, goddamn content_type diff -r 1053290ba067 -r b710a2374c8d wsgraph/web.py --- a/wsgraph/web.py Mon Dec 10 17:36:31 2012 -0800 +++ b/wsgraph/web.py Mon Dec 10 17:42:23 2012 -0800 @@ -13,19 +13,27 @@ NODE = 1 EDGE = 2 -# XXX stubbing hacks +# XXX stubbing hack class JSONformatter(object): - def __init__(self, sort_keys=True): + + def __init__(self, content_type='application/json', sort_keys=True): + self.content_type = content_type self.sort_keys = sort_keys def format(self, _object): return json.dumps(graph.node(node), sort_keys=self.sort_keys) def node(self, node, graph, request): - return Response(body=self.format(graph.node(node))) + return Response(content_type=self.content_type, + body=self.format(graph.node(node))) def edge(self, node1, node2, graph, request): - return Response(body=self.format(graph.edge(node))) + return Response(content_type=self.content_type, + body=self.format(graph.edge(node))) + + def graph(self, graph, request): + return Response(content_type=self.content_type, + body='hello? is it me you\'re looking for?') class Dispatcher(object): @@ -115,8 +123,9 @@ # formatter formatter = self.formatters[len(segments)] + return formatter(*segments, self.graph, request) return Response(content_type='text/plain', - body="WSGraph") + body=content) def POST(self, request): """ @@ -154,6 +163,9 @@ # example model graph = MemoryCache() + # example formatter(s) + # TODO + # WSGI app app = Dispatcher(graph=graph) server = simple_server.make_server(host='0.0.0.0', port=options.port, app=app)