X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd-wsgi;h=042bf3feb8f1437bf0c898b6f0a1cdcd1c7b5cc6;hb=81a0ca30bf866751d7a389ea322ddff2de64db1b;hp=422fc9f666048305ad9d00c4d4835f74adbaecae;hpb=70d942a7e2c1e7abb4fbddcea5b9c47cf5105590;p=ashd.git diff --git a/python/ashd-wsgi b/python/ashd-wsgi index 422fc9f..042bf3f 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,12 +36,49 @@ else: sys.exit(1) handler = handlermod.application +class closed(IOError): + def __init__(self): + super(closed, self).__init__("The client has closed the connection.") + 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') + 10) << 4 + elif 'A' <= url[i] <= 'F': + c |= (ord(url[i]) - ord('A') + 10) << 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') + 10 + elif 'A' <= url[i + 1] <= 'F': + c |= ord(url[i + 1]) - ord('A') + 10 + 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 +89,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: @@ -95,8 +135,11 @@ def dowsgi(req): if not data: return flushreq() - req.sk.write(data) - req.sk.flush() + try: + req.sk.write(data) + req.sk.flush() + except IOError: + raise closed() def startreq(status, headers, exc_info = None): if resp: @@ -135,4 +178,4 @@ class reqthread(threading.Thread): def handle(req): reqthread(req).start() -ashd.proto.serveloop(handle) +ashd.util.serveloop(handle)