X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd-wsgi;h=ae08137a1a80fb460dce85d47adbacad526e9e18;hb=4e7888f79c780b6d79420374f5ab3843d7784fad;hp=d3347658ff4898d07a76c939f80d18045aa2c201;hpb=c270f222b55e805cd42c223da1c1d8774d6bd4cf;p=ashd.git diff --git a/python/ashd-wsgi b/python/ashd-wsgi index d334765..ae08137 100755 --- a/python/ashd-wsgi +++ b/python/ashd-wsgi @@ -1,7 +1,7 @@ #!/usr/bin/python import sys, os, getopt, threading -import ashd.proto +import ashd.proto, ashd.util def usage(out): out.write("usage: ashd-wsgi [-hA] [-p MODPATH] HANDLER-MODULE [ARGS...]\n") @@ -29,13 +29,19 @@ if not modwsgi_compat: if not hasattr(handlermod, "wmain"): sys.stderr.write("ashd-wsgi: handler %s has no `wmain' function\n" % args[0]) sys.exit(1) - handler = handlermod.wmain(args[1:]) + handler = handlermod.wmain(*args[1:]) else: if not hasattr(handlermod, "application"): sys.stderr.write("ashd-wsgi: handler %s has no `application' object\n" % args[0]) sys.exit(1) handler = handlermod.application +cwd = os.getcwd() +def absolutify(path): + if path[0] != '/': + return os.path.join(cwd, path) + return path + def dowsgi(req): env = {} env["wsgi.version"] = 1, 0 @@ -50,8 +56,8 @@ def dowsgi(req): name = req.url p = name.find('?') if p >= 0: - name = name[:p] env["QUERY_STRING"] = name[p + 1:] + name = name[:p] else: env["QUERY_STRING"] = "" if name[-len(req.rest):] == req.rest: @@ -63,7 +69,7 @@ def dowsgi(req): if "X-Ash-Address" in req: env["REMOTE_ADDR"] = req["X-Ash-Address"] if "Content-Type" in req: env["CONTENT_TYPE"] = req["Content-Type"] if "Content-Length" in req: env["CONTENT_LENGTH"] = req["Content-Length"] - if "X-Ash-File" in req: env["SCRIPT_FILENAME"] = req["X-Ash-File"] + if "X-Ash-File" in req: env["SCRIPT_FILENAME"] = absolutify(req["X-Ash-File"]) if "X-Ash-Protocol" in req: env["wsgi.url_scheme"] = req["X-Ash-Protocol"] env["wsgi.input"] = req.sk env["wsgi.errors"] = sys.stderr @@ -74,9 +80,7 @@ def dowsgi(req): resp = [] respsent = [] - def write(data): - if not data: - return + def flushreq(): if not respsent: if not resp: raise Exception, "Trying to write data before starting response." @@ -86,6 +90,11 @@ def dowsgi(req): for nm, val in headers: req.sk.write("%s: %s\n" % (nm, val)) req.sk.write("\n") + + def write(data): + if not data: + return + flushreq() req.sk.write(data) req.sk.flush() @@ -106,7 +115,8 @@ def dowsgi(req): try: for data in respiter: write(data) - write("") + if resp: + flushreq() finally: if hasattr(respiter, "close"): respiter.close() @@ -125,4 +135,4 @@ class reqthread(threading.Thread): def handle(req): reqthread(req).start() -ashd.proto.serveloop(handle) +ashd.util.serveloop(handle)