comparison wsgraph/web.py @ 3:42f484880808

wire this up
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 09 Dec 2012 14:51:23 -0800
parents 7a3b21cafc00
children c7170cab1184
comparison
equal deleted inserted replaced
2:7a3b21cafc00 3:42f484880808
26 self.require_auth = require_auth 26 self.require_auth = require_auth
27 self.formatters = {0: JSONGraphFormatter, 27 self.formatters = {0: JSONGraphFormatter,
28 1: JSONFormatter, 28 1: JSONFormatter,
29 2: JSONFormatter} 29 2: JSONFormatter}
30 30
31 self.methods = dict([(i, getattr(self, i))
32 for i in dir(self)
33 if i.isupper()])
34
31 def __call__(self, environ, start_response): 35 def __call__(self, environ, start_response):
32 request = Request(environ) 36 request = Request(environ)
33 import pdb; pdb.set_trace() 37 method = self.methods.get(request.method)
38 if method is None:
39 return exc.HTTPMethodNotAllowed()(environ, start_response)
40 response = method(request)
34 return response(environ, start_response) 41 return response(environ, start_response)
35 42
36 @staticmethod 43 @staticmethod
37 def path_segments(request): 44 def path_segments(request):
38 import pdb; pdb.set_trace() 45 import pdb; pdb.set_trace()
74 81
75 def HEAD(self, request): 82 def HEAD(self, request):
76 """respond to a HEAD request""" 83 """respond to a HEAD request"""
77 raise NotImplementedError 84 raise NotImplementedError
78 85
86 def OPTIONS(self, request):
87 raise NotImplementedError
88
79 if __name__ == '__main__': 89 if __name__ == '__main__':
90
91 ### example web server
80 92
81 # imports 93 # imports
82 from wsgiref import simple_server 94 from wsgiref import simple_server
83 from .model import MemoryCache 95 from model import MemoryCache
96 from optparse import OptionParser
84 97
98 # parse command line options
99 parser = OptionParser()
100 parser.add_option('-p', '--port', type='int', default=8080,
101 help="port to serve on")
102 options, args = parser.parse_args()
103
104 # example model
85 graph = MemoryCache() 105 graph = MemoryCache()
86 106
107 # WSGI app
87 app = Dispatcher(graph=graph) 108 app = Dispatcher(graph=graph)
88 server = simple_server.make_server(host='0.0.0.0', port=8080, app=app) 109 server = simple_server.make_server(host='0.0.0.0', port=options.port, app=app)
110 print 'http://localhost:%s/' % options.port
89 server.serve_forever() 111 server.serve_forever()
90 112