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.
This commit is contained in:
Jean-Paul Calderone 2020-10-18 10:58:09 -04:00
parent 9e26599a76
commit 84acf4e50f

View File

@ -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",