From 84acf4e50fc0233ac070e07dbcfde9fb3c98e7f8 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sun, 18 Oct 2020 10:58:09 -0400 Subject: [PATCH] Accept unicode return values and encode them to UTF-8 Nevow accepts unicode in most places it accepts bytes and does the usual sloppy Python 2 thing, lets one or the other get implicitly re-coded, typically using the ascii codec. We'll go with UTF-8 because that fails less often than ASCII. We may want to clean up the code at some point so we're not accidentally slinging both bytes and text around as if they were the same thing. --- src/allmydata/web/common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index 4fb2372a5..a3f1688d1 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -571,6 +571,12 @@ def _finish(result, render, request): resource=fullyQualifiedName(type(result)), ) result.render(request) + elif isinstance(result, unicode): + Message.log( + message_type=u"allmydata:web:common-render:unicode", + ) + request.write(result.encode("utf-8")) + request.finish() elif isinstance(result, bytes): Message.log( message_type=u"allmydata:web:common-render:bytes",