From 1a612baef1b716d669bc39ff992fae7976f06aff Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 27 Mar 2019 10:51:52 +0100 Subject: [PATCH] Some improvements --- main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index f6e2df3..ea471b2 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import cgi import datetime import pytz +import html import workers.conn import workers.val @@ -20,16 +21,18 @@ HTML = "text/html" JSON = "application/json" XML = "text/xml" +DOCSTR = ' Check out the documentation for usage instructions.' + def doConn(req): try: getfrm = req.cfrm if "cfrm" in dir(req) and req.cfrm else req.args["from"][0] if "from" in req.args else None getto = req.cto if "cto" in dir(req) and req.cto else req.args["to"][0] if "to" in req.args else None try: - frm = getfrm.encode("latin-1").decode("utf-8") - to = getto.encode("latin-1").decode("utf-8") + frm = html.unescape(getfrm.encode("latin-1").decode("utf-8")) + to = html.unescape(getto.encode("latin-1").decode("utf-8")) except UnicodeDecodeError: - frm = getfrm - to = getto + frm = html.unescape(getfrm) + to = html.unescape(getto) if not frm or not to: raise ValueError() @@ -218,9 +221,9 @@ def application(env, re): res = doNot(req) except IllegalMethodException as e: - res = Response(HTTP405, HTML, str(e)) + res = Response(HTTP405, HTML, str(e) + DOCSTR) except InvalidArgumentException as e: - res = Response(HTTP400, HTML, str(e)) + res = Response(HTTP400, HTML, str(e) + DOCSTR) re(res.status, [("Content-Type", res.ctype)]) yield res.content.encode()