Style fixups; be explicit about literals.

This commit is contained in:
hab 2019-08-16 16:51:57 +01:00
parent 46cc5ab8ed
commit 4e6ff4c7c7
4 changed files with 18 additions and 19 deletions

View File

@ -7,10 +7,12 @@ unknown_immcap = u"imm.lafs://immutable_from_the_future_imm_\u263A".encode('utf-
FAVICON_MARKUP = '<link href="/icon.png" rel="shortcut icon" />'
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_(

View File

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

View File

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

View File

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