Mercurial > hg > wsgintegrate
changeset 23:01b0ad159fe3
add tornado server
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 27 Jul 2014 13:17:47 -0700 |
parents | 37b47aedcc3d |
children | b43cb919b1e4 |
files | wsgintegrate/server.py |
diffstat | 1 files changed, 39 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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