Some progress towards passing Python 2 tests.

This commit is contained in:
Itamar Turner-Trauring 2020-10-26 16:37:00 -04:00
parent 957afa356c
commit 4dc1adc817
4 changed files with 21 additions and 1 deletions

View File

@ -717,6 +717,9 @@ class _Client(node.Node, pollmixin.PollMixin):
def init_stats_provider(self):
gatherer_furl = self.config.get_config("client", "stats_gatherer.furl", None)
if gatherer_furl:
# FURLs should be bytes:
gatherer_furl = gatherer_furl.encode("utf-8")
self.stats_provider = StatsProvider(self, gatherer_furl)
self.stats_provider.setServiceParent(self)
self.stats_provider.register_producer(self)

View File

@ -3,6 +3,7 @@ This module contains classes and functions to implement and manage
a node for Tahoe-LAFS.
"""
from past.builtins import unicode
from six import ensure_str
import datetime
import os.path
@ -640,6 +641,10 @@ def _tub_portlocation(config):
new_locations.append(loc)
location = ",".join(new_locations)
# Lacking this, Python 2 blows up in PB when it is confused by a Unicode
# FURL.
location = location.encode("utf-8")
return tubport, location
@ -687,6 +692,9 @@ def create_main_tub(config, tub_options,
port_or_endpoint = tor_provider.get_listener()
else:
port_or_endpoint = port
# Foolscap requires native strings:
if isinstance(port_or_endpoint, (bytes, unicode)):
port_or_endpoint = ensure_str(port_or_endpoint)
tub.listenOn(port_or_endpoint)
tub.setLocation(location)
log.msg("Tub location set to %s" % (location,))

View File

@ -154,3 +154,12 @@ enabled = false
self.dynamic_valid_config,
)
self.assertIn("section [node] contains unknown option 'invalid'", str(e))
def test_duplicate_sections(self):
"""
Duplicate section names are merged.
"""
fname = self.create_tahoe_cfg('[node]\na = foo\n[node]\n b = bar\n')
config = configutil.get_config(fname)
self.assertEqual(config.get("node", "a"), "foo")
self.assertEqual(config.get("node", "b"), "bar")

View File

@ -34,7 +34,7 @@ def get_config(tahoe_cfg):
Configuration is returned as native strings.
"""
config = SafeConfigParser()
config = SafeConfigParser(strict=False)
with open(tahoe_cfg, "r") as f:
# Who put the BOM in the BOM SHOO BOP SHOO BOP.
#