diff options
-rw-r--r-- | libpathod/app.py | 12 | ||||
-rw-r--r-- | libpathod/pathod.py | 19 | ||||
-rw-r--r-- | libpathod/test.py | 8 | ||||
-rwxr-xr-x | pathod | 2 |
4 files changed, 32 insertions, 9 deletions
diff --git a/libpathod/app.py b/libpathod/app.py index 8ea19f4c..95e7d169 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -1,4 +1,15 @@ +from flask import Flask, jsonify +import version +app = Flask(__name__) +@app.route('/api/info') +def api_info(): + return jsonify( + version = version.IVERSION + ) + + +""" class APILog(tornado.web.RequestHandler): def get(self): self.write( @@ -95,3 +106,4 @@ class ClearLog(_Page): def post(self): self.application.clear_logs() self.redirect("/log") +""" diff --git a/libpathod/pathod.py b/libpathod/pathod.py index c700b550..c8608bd6 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -1,4 +1,6 @@ -from netlib import tcp, protocol, odict +from netlib import tcp, protocol, odict, wsgi +import version, app + class PathodHandler(tcp.BaseHandler): def handle(self): @@ -13,13 +15,24 @@ class PathodHandler(tcp.BaseHandler): content = protocol.read_http_body_request( self.rfile, self.wfile, headers, httpversion, None ) - print method, path, httpversion - #return flow.Request(client_conn, httpversion, host, port, "http", method, path, headers, content) + cc = wsgi.ClientConn(self.client_address) + req = wsgi.Request(cc, "http", method, path, headers, content) + sn = self.connection.getsockname() + app = wsgi.WSGIAdaptor( + self.server.app, + sn[0], + self.server.port, + version.NAMEVERSION + ) + app.serve(req, self.wfile) + class Pathod(tcp.TCPServer): def __init__(self, addr): tcp.TCPServer.__init__(self, addr) + self.app = app.app + self.app.config["pathod"] = self def handle_connection(self, request, client_address): PathodHandler(request, client_address, self) diff --git a/libpathod/test.py b/libpathod/test.py index 28fcd664..f33e922f 100644 --- a/libpathod/test.py +++ b/libpathod/test.py @@ -7,10 +7,8 @@ IFACE = "127.0.0.1" class Daemon: def __init__(self, staticdir=None, anchors=(), ssl=None): - #self.app = pathod.make_app(staticdir=staticdir, anchors=anchors) - self.app = None self.q = Queue.Queue() - self.thread = PaThread(self.q, self.app, ssl) + self.thread = PaThread(self.q, ssl) self.thread.start() self.port = self.q.get(True, 5) self.urlbase = "%s://%s:%s"%("https" if ssl else "http", IFACE, self.port) @@ -25,9 +23,9 @@ class Daemon: class PaThread(threading.Thread): - def __init__(self, q, app, ssl): + def __init__(self, q, ssl): threading.Thread.__init__(self) - self.q, self.app, self.ssl = q, app, ssl + self.q, self.ssl = q, ssl self.port = None def run(self): @@ -1,5 +1,5 @@ #!/usr/bin/env python from libpathod import pathod -s = pathod.PathodServer(("127.0.0.1", 8888)) +s = pathod.Pathod(("127.0.0.1", 8888)) s.serve_forever() |