connstr = ""
+class Make404(Exception):
+ pass
+
+
def iddecode(idstr):
idval = 0
for c in idstr:
idval *= 64
+ if c not in _urlvalmap:
+ raise Make404()
idval += _urlvalmap.index(c)
return idval
conn.close()
if len(r) != 1:
- start_response('404 Not Found', [
- ('Content-type', 'text/plain'),
- ])
- return [b"Link not found\n"]
+ raise Make404()
# We have a link, return a redirect to it
start_response('301 Moved Permanently', [
b"<a href=\"%s\">moved here</a>\n" % r[0][0].encode('utf8'),
b"</body>\n</html>\n"
]
+ except Make404:
+ start_response('404 Not Found', [
+ ('Content-type', 'text/plain'),
+ ])
+ return [b"Link not found\n"]
except Exception as ex:
start_response('500 Internal Server Error', [
('Content-type', 'text/plain')