""" server.py [options] Description: Starts up a simple HTTP/JSON database server """ # import simplejson, even though it uses the deprecated sre module import warnings warnings.filterwarnings('ignore', category=DeprecationWarning) import simplejson warnings.filterwarnings('default', category=DeprecationWarning) import basura from optparse import OptionParser from wsgiref.simple_server import WSGIServer, WSGIRequestHandler if __name__ == "__main__": # parse for --port and --host options parser = OptionParser(usage=__doc__.strip()) parser.add_option('--port', type="int", default=8080, action="store", dest="port", help="server listen port") parser.add_option('--host', type="string", default='', action="store", dest="host", help="server host name") opts,args = parser.parse_args() # start the server httpd = WSGIServer((opts.host, opts.port), WSGIRequestHandler) httpd.set_app(basura.dispatch) print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname() try: httpd.serve_forever() except KeyboardInterrupt: print "Shutting down" basura.shutdown()