X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd-wsgi;h=74624929c84ea74d4e3452c3467a85c767485b3f;hb=09c82f9c7bc563c081425141853e6ff8e402e358;hp=422fc9f666048305ad9d00c4d4835f74adbaecae;hpb=70d942a7e2c1e7abb4fbddcea5b9c47cf5105590;p=ashd.git diff --git a/python/ashd-wsgi b/python/ashd-wsgi index 422fc9f..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") @@ -42,6 +42,39 @@ def absolutify(path): 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 @@ -52,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: @@ -135,4 +171,4 @@ class reqthread(threading.Thread): def handle(req): reqthread(req).start() -ashd.proto.serveloop(handle) +ashd.util.serveloop(handle)