X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd-wsgi;h=bfc4b420d7d12f7354a6f8e8370f6203e9aed173;hb=1b16086880096c31abd31fa2dae40e5b36789162;hp=ae08137a1a80fb460dce85d47adbacad526e9e18;hpb=4e7888f79c780b6d79420374f5ab3843d7784fad;p=ashd.git diff --git a/python/ashd-wsgi b/python/ashd-wsgi index ae08137..bfc4b42 100755 --- a/python/ashd-wsgi +++ b/python/ashd-wsgi @@ -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: @@ -94,9 +134,12 @@ def dowsgi(req): def write(data): if not data: return - flushreq() - req.sk.write(data) - req.sk.flush() + try: + flushreq() + req.sk.write(data) + req.sk.flush() + except IOError: + raise closed() def startreq(status, headers, exc_info = None): if resp: