summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <pochu@debian.org>2020-07-16 14:46:27 +0200
committerEmilio Pozuelo Monfort <pochu@debian.org>2020-07-29 10:20:41 +0200
commit95f779f1f878ddf7b4bcb7125802761f82530725 (patch)
treed510e6e83a22b017b8838a89da8c398961ef0e2c /lib
parent3d659f138684902ffd074cb0de1a0cbde79ef5b9 (diff)
web_support.py: decode data when necessary
We can't pass bytes under python3
Diffstat (limited to 'lib')
-rw-r--r--lib/python/web_support.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/python/web_support.py b/lib/python/web_support.py
index 334b36efe5..807edf2fdf 100644
--- a/lib/python/web_support.py
+++ b/lib/python/web_support.py
@@ -643,6 +643,12 @@ class RedirectResult(Result):
self.status = 302
self.headers['Location'] = str(url)
+def maybe_encode(obj):
+ try:
+ return obj.encode()
+ except:
+ return obj
+
class HTMLResult(Result):
"""An object of this class combines a status code with HTML contents."""
def __init__(self, contents, doctype='', status=200):
@@ -674,6 +680,7 @@ class HTMLResult(Result):
buf.write(s)
self.contents.flatten(write_both)
buf = buf.getvalue()
+ buf = maybe_encode(buf)
self.headers['Content-Length'] = str(len(buf))
def later(req):
headers_later(req)
@@ -701,7 +708,7 @@ class BinaryResult(Result):
def later(req):
headers_later(req)
if req.command != 'HEAD':
- req.wfile.write(self.contents)
+ req.wfile.write(maybe_encode(self.contents))
return later
class WebServiceBase:

© 2014-2024 Faster IT GmbH | imprint | privacy policy