X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd-wsgi;h=74624929c84ea74d4e3452c3467a85c767485b3f;hb=09c82f9c7bc563c081425141853e6ff8e402e358;hp=e8f843544b636ec21b489d26f4339ea206cc7ce0;hpb=adb11d5f566968a0a12fcd225b5748bce09e0014;p=ashd.git diff --git a/python/ashd-wsgi b/python/ashd-wsgi index e8f8435..7462492 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") @@ -36,6 +36,45 @@ else: sys.exit(1) handler = handlermod.application +cwd = os.getcwd() +def absolutify(path): + if path[0] != '/': + return os.path.join(cwd, path) + return path + +def unquoteurl(url): + buf = "" + i = 0 + while i < len(url): + c = url[i] + i += 1 + if c == '%': + if len(url) > i + 2: + c = 0 + if '0' <= url[i] <= '9': + c |= (ord(url[i]) - ord('0')) << 4 + elif 'a' <= url[i] <= 'f': + c |= (ord(url[i]) - ord('a')) << 4 + elif 'A' <= url[i] <= 'F': + c |= (ord(url[i]) - ord('A')) << 4 + else: + raise ValueError("Illegal URL escape character") + if '0' <= url[i + 1] <= '9': + c |= ord(url[i + 1]) - ord('0') + elif 'a' <= url[i + 1] <= 'f': + c |= ord(url[i + 1]) - ord('a') + elif 'A' <= url[i + 1] <= 'F': + c |= ord(url[i + 1]) - ord('A') + else: + raise ValueError("Illegal URL escape character") + buf += chr(c) + i += 2 + else: + raise ValueError("Incomplete URL escape character") + else: + buf += c + return buf + def dowsgi(req): env = {} env["wsgi.version"] = 1, 0 @@ -46,7 +85,10 @@ def dowsgi(req): env["SERVER_PROTOCOL"] = req.ver env["REQUEST_METHOD"] = req.method env["REQUEST_URI"] = req.url - env["PATH_INFO"] = req.rest + try: + env["PATH_INFO"] = unquoteurl(req.rest) + except: + env["PATH_INFO"] = req.rest name = req.url p = name.find('?') if p >= 0: @@ -63,7 +105,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 @@ -129,4 +171,4 @@ class reqthread(threading.Thread): def handle(req): reqthread(req).start() -ashd.proto.serveloop(handle) +ashd.util.serveloop(handle)