More progress on Python 3, unbreak Python 2.

This commit is contained in:
Itamar Turner-Trauring 2020-12-10 10:52:07 -05:00
parent fb621f4388
commit 36bf9224e6
4 changed files with 15 additions and 14 deletions

View File

@ -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"]))

View File

@ -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):

View File

@ -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)

View File

@ -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'<th>Node ID:</th>\s*<td title="TubID: %s">%s</td>' % (
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)