From 36bf9224e68c8391098c958bf66aa5c6383f03e9 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 10 Dec 2020 10:52:07 -0500 Subject: [PATCH] More progress on Python 3, unbreak Python 2. --- src/allmydata/client.py | 4 ---- src/allmydata/immutable/upload.py | 2 +- src/allmydata/test/common_web.py | 9 +++++++-- src/allmydata/test/test_system.py | 14 +++++++------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 4c7a29d8d..c60c7d4c9 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -904,10 +904,6 @@ class _Client(node.Node, pollmixin.PollMixin): if helper_furl in ("None", ""): helper_furl = None - # FURLs need to be bytes: - if helper_furl is not None: - helper_furl = helper_furl.encode("utf-8") - DEP = self.encoding_params DEP["k"] = int(self.config.get_config("client", "shares.needed", DEP["k"])) DEP["n"] = int(self.config.get_config("client", "shares.total", DEP["n"])) diff --git a/src/allmydata/immutable/upload.py b/src/allmydata/immutable/upload.py index e77cbb30b..855f38919 100644 --- a/src/allmydata/immutable/upload.py +++ b/src/allmydata/immutable/upload.py @@ -1825,7 +1825,7 @@ class Uploader(service.MultiService, log.PrefixingLogMixin): def startService(self): service.MultiService.startService(self) if self._helper_furl: - self.parent.tub.connectTo(self._helper_furl, + self.parent.tub.connectTo(self._helper_furl.encode("utf-8"), self._got_helper) def _got_helper(self, helper): diff --git a/src/allmydata/test/common_web.py b/src/allmydata/test/common_web.py index a6278810b..faf546f7c 100644 --- a/src/allmydata/test/common_web.py +++ b/src/allmydata/test/common_web.py @@ -47,12 +47,17 @@ class VerboseError(Error): @inlineCallbacks def do_http(method, url, **kwargs): + """ + Run HTTP query, return Deferred of body as Unicode. + """ response = yield treq.request(method, url, persistent=False, **kwargs) - body = yield treq.content(response) + body = yield treq.text_content(response, "utf-8") # TODO: replace this with response.fail_for_status when # https://github.com/twisted/treq/pull/159 has landed if 400 <= response.code < 600: - raise VerboseError(response.code, response=body) + raise VerboseError( + response.code, response="For request {} to {}, got: {}".format( + method, url, body)) returnValue(body) diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index c521e1e2f..5bdcd6df9 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -632,7 +632,7 @@ def _render_config(config): """ Convert a ``dict`` of ``dict`` of ``bytes`` to an ini-format string. """ - return "\n\n".join(list( + return u"\n\n".join(list( _render_config_section(k, v) for (k, v) in config.items() @@ -643,7 +643,7 @@ def _render_config_section(heading, values): Convert a ``bytes`` heading and a ``dict`` of ``bytes`` to an ini-format section as ``bytes``. """ - return "[{}]\n{}\n".format( + return u"[{}]\n{}\n".format( heading, _render_section_values(values) ) @@ -652,8 +652,8 @@ def _render_section_values(values): Convert a ``dict`` of ``bytes`` to the body of an ini-format section as ``bytes``. """ - return "\n".join(list( - "{} = {}".format(k, v) + return u"\n".join(list( + u"{} = {}".format(k, v) for (k, v) in sorted(values.items()) )) @@ -1856,7 +1856,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): "largest-directory-children": 3, "largest-immutable-file": 112, } - for k,v in expected.iteritems(): + for k,v in expected.items(): self.failUnlessEqual(stats[k], v, "stats[%s] was %s, not %s" % (k, stats[k], v)) @@ -1939,7 +1939,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): return do_http("post", url, data=body, headers=headers) def _test_web(self, res): - public = "uri/" + self._root_directory_uri + public = "uri/" + unicode(self._root_directory_uri, "ascii") d = self.GET("") def _got_welcome(page): html = page.replace('\n', ' ') @@ -1948,7 +1948,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): "I didn't see the right '%s' message in:\n%s" % (connected_re, page)) # nodeids/tubids don't have any regexp-special characters nodeid_re = r'Node ID:\s*%s' % ( - self.clients[0].get_long_tubid(), self.clients[0].get_long_nodeid()) + self.clients[0].get_long_tubid(), unicode(self.clients[0].get_long_nodeid(), "ascii")) self.failUnless(re.search(nodeid_re, html), "I didn't see the right '%s' message in:\n%s" % (nodeid_re, page)) self.failUnless("Helper: 0 active uploads" in page)