Commit 9fefd2e3 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Use UTF-8 in the HTML code.

parent 5535ce7b
......@@ -11,7 +11,7 @@ sys.path.insert(0, os.path.dirname(__file__))
import mp3wavcfg
def quote(s):
return urllib.parse.quote(s)
return urllib.parse.quote(s.encode("utf-8"))
# Taken from
# http://stackoverflow.com/questions/4579908/cross-platform-splitting-of-path-in-python
......@@ -62,7 +62,8 @@ def process_request(environ, start_response):
if environ["REQUEST_METHOD"] not in ["GET", "POST"]:
raise MethodNotAllowed('GET, POST')
path = environ['PATH_INFO']
# Hack: Undo some duplicate utf-8 encoding we somehow end up with.
path = environ['PATH_INFO'].encode("latin-1").decode("utf-8")
# We want a trailing slash at the root.
if path == "" and environ.get("SCRIPT_NAME", "") != "":
......@@ -91,10 +92,12 @@ def convert(environ, start_response, ph):
if environ["REQUEST_METHOD"] == "GET":
start_response("200 OK",
[('Content-Type', 'text/html')])
return ["<html><head><title>Request conversion</title></head>"
"<body><form method=\"POST\" action=\"convert\">"
"<button>Confirm conversion to mp3</button>"
[('Content-Type', 'text/html;charset=utf-8')])
return ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n"
" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
"<html><head><title>Request conversion</title></head>\n"
"<body><form method=\"POST\" action=\"convert\">\n"
"<button>Confirm conversion to mp3</button>\n"
"</form></body></html>"]
if environ["REQUEST_METHOD"] != "POST":
......@@ -240,6 +243,8 @@ def handle_directory(environ, start_response, ph, real_dir):
dirs.add(fn)
res = io.StringIO()
res.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n")
res.write(" \"http://www.w3.org/TR/html4/strict.dtd\">\n")
res.write("<html>")
res.write("<head>")
res.write("</head>")
......@@ -283,9 +288,9 @@ def handle_directory(environ, start_response, ph, real_dir):
page = res.getvalue()
res.close()
start_response("200 OK", [("Content-Type", "text/html"),
start_response("200 OK", [("Content-Type", "text/html;charset=utf-8"),
("Content-Length", str(len(page)))])
return [page]
return [page.encode("utf-8")]
def handle_file(environ, start_response, ph, real_file):
content_type = {".wav": "audio/vnd.wave",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment