From 905ea9cafd7e2fbf403aeebd54d9befff4022c12 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 10 May 2021 10:30:15 -0400 Subject: [PATCH 1/7] Make stdio emulation more realistic, to trigger problem that was previously missed by tests. --- src/allmydata/test/common_util.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py index caafbb81d..c4ebd7384 100644 --- a/src/allmydata/test/common_util.py +++ b/src/allmydata/test/common_util.py @@ -11,6 +11,7 @@ from future.builtins import str as future_str if PY2: from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, str, max, min # noqa: F401 +import sys import os import time import signal @@ -105,9 +106,15 @@ def run_cli_native(verb, *args, **kwargs): # necessary. This works okay for ASCII and if LANG is set # appropriately. These aren't great constraints so we should move # away from this behavior. + # + # The encoding attribute doesn't change StringIO behavior on Python 2, + # but it's there for realism of the emulation. stdin = StringIO(stdin) + stdin.encoding = sys.stdin.encoding stdout = StringIO() + stdout.encoding = sys.stdout.encoding stderr = StringIO() + stderr.encoding = sys.stderr.encoding else: # The new behavior, the Python 3 behavior, is to accept unicode and # encode it using a specific encoding. For older versions of Python 3, From 150b0fd3a356f6646b84c9a33b09d972c5eb0db6 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 10 May 2021 10:31:12 -0400 Subject: [PATCH 2/7] This code should only run on Python 3. --- src/allmydata/scripts/tahoe_get.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/allmydata/scripts/tahoe_get.py b/src/allmydata/scripts/tahoe_get.py index 769a366a5..150b0457b 100644 --- a/src/allmydata/scripts/tahoe_get.py +++ b/src/allmydata/scripts/tahoe_get.py @@ -1,5 +1,7 @@ from __future__ import print_function +from future.utils import PY3 + from urllib.parse import quote as url_quote from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \ UnknownAliasError @@ -32,7 +34,7 @@ def get(options): outf = stdout # Make sure we can write bytes; on Python 3 stdout is Unicode by # default. - if getattr(outf, "encoding", None) is not None: + if PY3 and getattr(outf, "encoding", None) is not None: outf = outf.buffer while True: data = resp.read(4096) From 9ca404151e563bc7728b73ef5470152d2e21cce4 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 10 May 2021 10:31:45 -0400 Subject: [PATCH 3/7] News file. Empty since this was never released. --- newsfragments/3704.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3704.minor diff --git a/newsfragments/3704.minor b/newsfragments/3704.minor new file mode 100644 index 000000000..e69de29bb From 03c1376a3084f0ea462a8fa571a89f41b88f3996 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 10 May 2021 13:04:44 -0400 Subject: [PATCH 4/7] Try to fix the test. --- src/allmydata/test/cli/test_create_alias.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/allmydata/test/cli/test_create_alias.py b/src/allmydata/test/cli/test_create_alias.py index 4a252f372..6f6881860 100644 --- a/src/allmydata/test/cli/test_create_alias.py +++ b/src/allmydata/test/cli/test_create_alias.py @@ -10,7 +10,7 @@ from future.utils import PY2 if PY2: from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 -from six import ensure_str +from six import ensure_text from six.moves import StringIO import os.path from twisted.trial import unittest @@ -182,7 +182,7 @@ class CreateAlias(GridTestMixin, CLITestMixin, unittest.TestCase): (rc, out, err) = args self.failUnlessReallyEqual(rc, 0) self.assertEqual(len(err), 0, err) - self.failUnlessIn(ensure_str("Alias %s created") % quote_output(etudes_arg), out) + self.failUnlessIn(u"Alias %s created" % ensure_text(quote_output(etudes_arg)), out) aliases = get_aliases(self.get_clientdir()) self.failUnless(aliases[u"\u00E9tudes"].startswith(b"URI:DIR2:")) From fd5bda67db0c85ada274c7fb93e0560b65878391 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 11 May 2021 11:02:15 -0400 Subject: [PATCH 5/7] Note package. --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 09f0d9f99..c53bd2a44 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,8 @@ # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. -# Map Python versions in GitHub Actions to tox environments to run. +# Map Python versions in GitHub Actions to tox environments to run, for use by +# the tox-gh-actions package. [gh-actions] python = 2.7: py27-coverage,codechecks From 7aa3c9c3baa80287175dfacd5cff2852e02ddfbc Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 12 May 2021 11:06:26 -0400 Subject: [PATCH 6/7] Use passed-in encoding. --- src/allmydata/test/common_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py index c4ebd7384..952e9ce05 100644 --- a/src/allmydata/test/common_util.py +++ b/src/allmydata/test/common_util.py @@ -110,11 +110,11 @@ def run_cli_native(verb, *args, **kwargs): # The encoding attribute doesn't change StringIO behavior on Python 2, # but it's there for realism of the emulation. stdin = StringIO(stdin) - stdin.encoding = sys.stdin.encoding + stdin.encoding = encoding stdout = StringIO() - stdout.encoding = sys.stdout.encoding + stdout.encoding = encoding stderr = StringIO() - stderr.encoding = sys.stderr.encoding + stderr.encoding = encoding else: # The new behavior, the Python 3 behavior, is to accept unicode and # encode it using a specific encoding. For older versions of Python 3, From a0bdc57a5e169a85b71e6d525c4aa4b3f47eb069 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 12 May 2021 11:10:42 -0400 Subject: [PATCH 7/7] Flake fix. --- src/allmydata/test/common_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py index 952e9ce05..9e7f0618c 100644 --- a/src/allmydata/test/common_util.py +++ b/src/allmydata/test/common_util.py @@ -11,7 +11,6 @@ from future.builtins import str as future_str if PY2: from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, str, max, min # noqa: F401 -import sys import os import time import signal