# HG changeset patch # User Jeff Hammel # Date 1406492267 25200 # Node ID 01b0ad159fe3ce37f45a948281517b58fbe575f1 # Parent 37b47aedcc3d448969f0ef23984826b962395636 add tornado server diff -r 37b47aedcc3d -r 01b0ad159fe3 wsgintegrate/server.py --- a/wsgintegrate/server.py Thu Mar 06 23:14:37 2014 -0800 +++ b/wsgintegrate/server.py Sun Jul 27 13:17:47 2014 -0700 @@ -6,22 +6,51 @@ __all__ = ['wsgiref', 'servers', 'paster'] + +### wsgiref + def wsgiref(app, host='0.0.0.0', port=80): - from wsgiref import simple_server - server = simple_server.make_server(host=host, port=int(port), app=app) - server.serve_forever() + from wsgiref import simple_server + server = simple_server.make_server(host=host, port=int(port), app=app) + server.serve_forever() servers = {'wsgiref': wsgiref} + +### paste + try: - from paste import httpserver - def paste_server(app, host='0.0.0.0', port=80): - httpserver.serve(app, host=host, port=port) - servers['paste'] = paste_server + from paste import httpserver + def paste_server(app, host='0.0.0.0', port=80): + httpserver.serve(app, host=host, port=port) + servers['paste'] = paste_server except ImportError: - print ("Not adding paste.httpserver; not installed") + print ("Not adding paste.httpserver; not installed") def paster(global_conf, **kw): - """factory for paster""" - return WSGIfactory(**kw) + """factory for paster""" + return WSGIfactory(**kw) + + +### tornado +### http://www.tornadoweb.org/en/stable/httpserver.html +### http://www.tornadoweb.org/en/stable/httputil.html#tornado.httputil.HTTPServerRequest +### unfinished + +try: + import tornado.httpserver + import tornado.ioloop + + def handle_request(request): + message = "You requested %s\n" % request.uri + request.connection.write_headers( + httputil.ResponseStartLine('HTTP/1.1', 200, 'OK'), + {"Content-Length": str(len(message))}) + request.connection.write(message) + request.connection.finish() +#http_server = tornado.httpserver.HTTPServer(handle_request) +#http_server.listen(8888) +#tornado.ioloop.IOLoop.instance().start() +except ImportError: + pass