diff --git a/src/allmydata/test/test_node.py b/src/allmydata/test/test_node.py index b771f1cc6..73f7baca2 100644 --- a/src/allmydata/test/test_node.py +++ b/src/allmydata/test/test_node.py @@ -1,3 +1,4 @@ +from future.utils import PY2 from past.builtins import unicode import base64 @@ -153,8 +154,12 @@ class TestCase(testutil.SignalMixin, unittest.TestCase): f.close() config = read_config(basedir, "") - self.failUnlessEqual(config.get_config("node", "nickname").decode('utf-8'), - u"\u2621") + # Config returns native strings: + expected_nick = u"\u2621" + if PY2: + expected_nick = expected_nick.encode("utf-8") + self.failUnlessEqual(config.get_config("node", "nickname"), + expected_nick) def test_tahoe_cfg_hash_in_name(self): basedir = "test_node/test_cfg_hash_in_name" diff --git a/src/allmydata/util/configutil.py b/src/allmydata/util/configutil.py index 1a1a93f18..f85972d8d 100644 --- a/src/allmydata/util/configutil.py +++ b/src/allmydata/util/configutil.py @@ -10,7 +10,7 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -from future.utils import PY2 +from future.utils import PY2, PY3 if PY2: # We don't do open(), because we want files to read/write native strs when # we do "r" or "w". @@ -42,11 +42,12 @@ def get_config(tahoe_cfg): """ config = SafeConfigParser() with open(tahoe_cfg, "r") as f: - # On Python 2, where we read in bytes, skip any initial Byte Order - # Mark. Since this is an ordinary file, we don't need to handle - # incomplete reads, and can assume seekability. + # Skip any initial Byte Order Mark. Since this is an ordinary file, we + # don't need to handle incomplete reads, and can assume seekability. if PY2 and f.read(3) != b'\xEF\xBB\xBF': f.seek(0) + if PY3 and f.read(1) != u"\uFEFF": + f.seek(0) config.readfp(f) return config