Mercurial > hg > WSGraph
diff 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 |
line wrap: on
line diff
--- a/wsgraph/web.py Sun Dec 09 10:40:17 2012 -0800 +++ b/wsgraph/web.py Sun Dec 09 14:51:23 2012 -0800 @@ -28,9 +28,16 @@ 1: JSONFormatter, 2: JSONFormatter} + self.methods = dict([(i, getattr(self, i)) + for i in dir(self) + if i.isupper()]) + def __call__(self, environ, start_response): request = Request(environ) - import pdb; pdb.set_trace() + method = self.methods.get(request.method) + if method is None: + return exc.HTTPMethodNotAllowed()(environ, start_response) + response = method(request) return response(environ, start_response) @staticmethod @@ -76,15 +83,30 @@ """respond to a HEAD request""" raise NotImplementedError + def OPTIONS(self, request): + raise NotImplementedError + if __name__ == '__main__': + ### example web server + # imports from wsgiref import simple_server - from .model import MemoryCache + from model import MemoryCache + from optparse import OptionParser + # parse command line options + parser = OptionParser() + parser.add_option('-p', '--port', type='int', default=8080, + help="port to serve on") + options, args = parser.parse_args() + + # example model graph = MemoryCache() + # WSGI app app = Dispatcher(graph=graph) - server = simple_server.make_server(host='0.0.0.0', port=8080, app=app) + server = simple_server.make_server(host='0.0.0.0', port=options.port, app=app) + print 'http://localhost:%s/' % options.port server.serve_forever()