diff wsgraph/web.py @ 18:b710a2374c8d

more stubbing, goddamn content_type
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Dec 2012 17:42:23 -0800
parents 1053290ba067
children 8162dc8dd93a
line wrap: on
line diff
--- 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)