From eebeca31f5248494c294dbe4e74e6cea2d132ba4 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 11 Feb 2021 13:11:34 -0500 Subject: [PATCH] Fix some more unicode()-of-bytestring bugs. --- src/allmydata/test/web/test_web.py | 8 ++++---- src/allmydata/web/directory.py | 8 ++++---- src/allmydata/web/info.py | 3 ++- src/allmydata/web/root.py | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/allmydata/test/web/test_web.py b/src/allmydata/test/web/test_web.py index cebe709c1..c2af61fd8 100644 --- a/src/allmydata/test/web/test_web.py +++ b/src/allmydata/test/web/test_web.py @@ -628,7 +628,7 @@ class WebMixin(TimezoneMixin): if response_substring: self.failUnlessIn(response_substring, res.value.response, which) else: - self.fail("%s was supposed to raise %s, not get '%s'" % + self.fail("%r was supposed to raise %s, not get %r" % (which, expected_failure, res)) def shouldFail2(self, expected_failure, which, substring, @@ -642,7 +642,7 @@ class WebMixin(TimezoneMixin): res.trap(expected_failure) if substring: self.failUnlessIn(substring, str(res), - "'%s' not in '%s' (response is '%s') for test '%s'" % \ + "%r not in %r (response is %r) for test %r" % \ (substring, str(res), getattr(res.value, "response", ""), which)) @@ -651,11 +651,11 @@ class WebMixin(TimezoneMixin): if isinstance(response, bytes): response = str(response, "utf-8") self.failUnlessIn(response_substring, response, - "'%s' not in '%s' for test '%s'" % \ + "%r not in %r for test %r" % \ (response_substring, res.value.response, which)) else: - self.fail("%s was supposed to raise %s, not get '%s'" % + self.fail("%r was supposed to raise %s, not get %r" % (which, expected_failure, res)) d.addBoth(done) return d diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 03194b2a3..6d24e7ddc 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -705,7 +705,7 @@ class DirectoryAsHTML(Element): @renderer def title(self, req, tag): - si_s = abbreviated_dirnode(self.node) + si_s = unicode(abbreviated_dirnode(self.node), "utf-8") header = ["Tahoe-LAFS - Directory SI=%s" % si_s] if self.node.is_unknown(): header.append(" (unknown)") @@ -719,7 +719,7 @@ class DirectoryAsHTML(Element): @renderer def header(self, req, tag): - si_s = abbreviated_dirnode(self.node) + si_s = unicode(abbreviated_dirnode(self.node), "utf-8") header = ["Tahoe-LAFS Directory SI=", tags.span(si_s, class_="data-chars")] if self.node.is_unknown(): header.append(" (unknown)") @@ -1077,13 +1077,13 @@ class RenameForm(Element, object): @renderer def title(self, req, tag): - return tag("Directory SI={}".format(abbreviated_dirnode(self.original))) + return tag("Directory SI={}".format(unicode(abbreviated_dirnode(self.original), "ascii"))) @renderer def header(self, req, tag): header = [ "Rename " - "in directory SI=%s" % abbreviated_dirnode(self.original), + "in directory SI=%s" % unicode(abbreviated_dirnode(self.original), "ascii"), ] if self.original.is_readonly(): diff --git a/src/allmydata/web/info.py b/src/allmydata/web/info.py index e6bca0e04..21ac0fd7e 100644 --- a/src/allmydata/web/info.py +++ b/src/allmydata/web/info.py @@ -1,3 +1,4 @@ +from past.builtins import unicode import os from urllib.parse import quote as urlquote @@ -46,7 +47,7 @@ class MoreInfoElement(Element): def abbrev(self, storage_index_or_none): if storage_index_or_none: - return base32.b2a(storage_index_or_none)[:6] + return unicode(base32.b2a(storage_index_or_none)[:6], "ascii") return "LIT file" def get_type(self): diff --git a/src/allmydata/web/root.py b/src/allmydata/web/root.py index 49ad222d8..068751a61 100644 --- a/src/allmydata/web/root.py +++ b/src/allmydata/web/root.py @@ -185,10 +185,10 @@ class FileHandler(resource.Resource, object): node = self.client.create_node_from_uri(name) except (TypeError, AssertionError): # I think this can no longer be reached - raise WebError("'%s' is not a valid file- or directory- cap" + raise WebError("%r is not a valid file- or directory- cap" % name) if not IFileNode.providedBy(node): - raise WebError("'%s' is not a file-cap" % name) + raise WebError("%r is not a file-cap" % name) return filenode.FileNodeDownloadHandler(self.client, node) @render_exception