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
commit01eec07fa5dafac4fcc6f248517003996dfc5bfa (patch)
tree504b8867bc9e6d1cd516b3bc5eb2939b22d238a1 /lib
parent75b2a557a7eb282dcea4b090062fc572f2bc9634 (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