From 4e6ff4c7c715e918db8b0b720ee17bb8eba2302e Mon Sep 17 00:00:00 2001 From: hab <_@habnab.it> Date: Fri, 16 Aug 2019 16:51:57 +0100 Subject: [PATCH] Style fixups; be explicit about literals. --- src/allmydata/test/web/common.py | 6 ++++-- src/allmydata/test/web/test_introducer.py | 7 ++++--- src/allmydata/web/common.py | 6 +----- src/allmydata/web/introweb.py | 18 +++++++++--------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/allmydata/test/web/common.py b/src/allmydata/test/web/common.py index 8d5721520..0c17292bd 100644 --- a/src/allmydata/test/web/common.py +++ b/src/allmydata/test/web/common.py @@ -7,10 +7,12 @@ unknown_immcap = u"imm.lafs://immutable_from_the_future_imm_\u263A".encode('utf- FAVICON_MARKUP = '' + def assert_soup_has_favicon(testcase, soup): - links = soup.find_all('link', rel='shortcut icon') + links = soup.find_all(u'link', rel=u'shortcut icon') testcase.assert_( - any(t['href'] == '/icon.png' for t in links), soup) + any(t[u'href'] == u'/icon.png' for t in links), soup) + def assert_soup_has_text(testcase, soup, text): testcase.assert_( diff --git a/src/allmydata/test/web/test_introducer.py b/src/allmydata/test/web/test_introducer.py index 4411a6dda..55db61a13 100644 --- a/src/allmydata/test/web/test_introducer.py +++ b/src/allmydata/test/web/test_introducer.py @@ -15,6 +15,7 @@ from ..common import ( ) from ..common_web import do_http + class IntroducerWeb(unittest.TestCase): def setUp(self): self.node = None @@ -50,7 +51,7 @@ class IntroducerWeb(unittest.TestCase): url = "http://localhost:%d/" % self.ws.getPortnum() res = yield do_http("get", url) soup = BeautifulSoup(res, 'html5lib') - assert_soup_has_text(self, soup, 'Welcome to the Tahoe-LAFS Introducer') + assert_soup_has_text(self, soup, u'Welcome to the Tahoe-LAFS Introducer') assert_soup_has_favicon(self, soup) - assert_soup_has_text(self, soup, 'Page rendered at') - assert_soup_has_text(self, soup, 'Tahoe-LAFS code imported from:') + assert_soup_has_text(self, soup, u'Page rendered at') + assert_soup_has_text(self, soup, u'Tahoe-LAFS code imported from:') diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index c98f1d115..b8adb291b 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -460,7 +460,6 @@ class MultiFormatPage(Page): return lambda ctx: renderer(IRequest(ctx)) - class MultiFormatResource(resource.Resource, object): """ ``MultiFormatResource`` is a ``resource.Resource`` that can be rendered in @@ -490,7 +489,6 @@ class MultiFormatResource(resource.Resource, object): renderer = self._get_renderer(t) return renderer(req) - def _get_renderer(self, fmt): """ Get the renderer for the indicated format. @@ -518,7 +516,6 @@ class MultiFormatResource(resource.Resource, object): return renderer - class SlotsSequenceElement(template.Element): """ ``SlotsSequenceElement` is a minimal port of nevow's sequence renderer @@ -548,12 +545,11 @@ class SlotsSequenceElement(template.Element): @template.renderer def empty(self, request, tag): if len(self.seq) > 0: - return '' + return u'' else: return tag - class TokenOnlyWebApi(resource.Resource, object): """ I provide a rend.Page implementation that only accepts POST calls, diff --git a/src/allmydata/web/introweb.py b/src/allmydata/web/introweb.py index 04d019be3..7b5a3e2bf 100644 --- a/src/allmydata/web/introweb.py +++ b/src/allmydata/web/introweb.py @@ -39,7 +39,7 @@ class IntroducerRoot(MultiFormatResource): if s.service_name not in counts: counts[s.service_name] = 0 counts[s.service_name] += 1 - res["subscription_summary"] = counts + res[u"subscription_summary"] = counts announcement_summary = {} for ad in self.introducer_service.get_announcements(): @@ -47,9 +47,9 @@ class IntroducerRoot(MultiFormatResource): if service_name not in announcement_summary: announcement_summary[service_name] = 0 announcement_summary[service_name] += 1 - res["announcement_summary"] = announcement_summary + res[u"announcement_summary"] = announcement_summary - return json.dumps(res, indent=1) + "\n" + return json.dumps(res, indent=1) + b"\n" class IntroducerRootElement(Element): @@ -80,8 +80,8 @@ class IntroducerRootElement(Element): services[ad.service_name] += 1 service_names = services.keys() service_names.sort() - return ", ".join(["%s: %d" % (service_name, services[service_name]) - for service_name in service_names]) + return u", ".join(u"{}: {}".format(service_name, services[service_name]) + for service_name in service_names) @renderer def client_summary(self, req, tag): @@ -90,8 +90,8 @@ class IntroducerRootElement(Element): if s.service_name not in counts: counts[s.service_name] = 0 counts[s.service_name] += 1 - return ", ".join([ "%s: %d" % (name, counts[name]) - for name in sorted(counts.keys()) ] ) + return u", ".join(u"{}: {}".format(name, counts[name]) + for name in sorted(counts.keys())) @renderer def services(self, req, tag): @@ -101,8 +101,8 @@ class IntroducerRootElement(Element): "serverid": ad.serverid, "nickname": ad.nickname, "connection-hints": - "connection hints: " + " ".join(ad.connection_hints), - "connected": "?", + u"connection hints: " + u" ".join(ad.connection_hints), + "connected": u"?", "announced": render_time(ad.when), "version": ad.version, "service_name": ad.service_name,