comparison wsgraph/web.py @ 21:f56d27f03e4a

pretend we are slick but we can be so much slicker
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Dec 2012 17:50:45 -0800
parents 542232f858a9
children a401bf63c938
comparison
equal deleted inserted replaced
20:542232f858a9 21:f56d27f03e4a
38 38
39 39
40 class Dispatcher(object): 40 class Dispatcher(object):
41 41
42 def __init__(self, graph, 42 def __init__(self, graph,
43 graph_formatters=None, 43 graph_formatters,
44 node_formatters=None, 44 node_formatters,
45 edge_formatters=None, 45 edge_formatters,
46 require_auth=False): 46 require_auth=False):
47 self.graph = graph 47 self.graph = graph
48 self.require_auth = require_auth 48 self.require_auth = require_auth
49
50 # use JSON formatter by default
51 if graph_formatters is None:
52 graph_formatters = {None: JSONGraphFormatter}
53 if node_formatters is None:
54 node_formatters = {None: JSONFormatter}
55 if edge_formatters is None:
56 edge_formatters = {None: JSONFormatter}
57 49
58 # view formatters 50 # view formatters
59 self.formatters = {GRAPH: graph_formatters, 51 self.formatters = {GRAPH: graph_formatters,
60 NODE: node_formatters, 52 NODE: node_formatters,
61 EDGE: edge_formatters} 53 EDGE: edge_formatters}
164 156
165 # example model 157 # example model
166 graph = MemoryCache() 158 graph = MemoryCache()
167 159
168 # example formatter(s) 160 # example formatter(s)
169 # TODO 161 formatter = JSONformatter(content_type='text/plain')
162 _formatters = {}
163 _formatters = dict([('%s_formatters' % i, {None: getattr(formatter, i)})
164 for i in 'graph', 'node', 'edge'])
170 165
171 # WSGI app 166 # WSGI app
172 app = Dispatcher(graph=graph) 167 app = Dispatcher(graph=graph, **_formatters)
173 server = simple_server.make_server(host='0.0.0.0', port=options.port, app=app) 168 server = simple_server.make_server(host='0.0.0.0', port=options.port, app=app)
174 print 'http://localhost:%s/' % options.port 169 print 'http://localhost:%s/' % options.port
175 server.serve_forever() 170 server.serve_forever()
176 171
177 if __name__ == '__main__': 172 if __name__ == '__main__':