diff --git a/setup.py b/setup.py index 874cc1258..14d249c51 100644 --- a/setup.py +++ b/setup.py @@ -131,6 +131,9 @@ install_requires = [ # Linux distribution detection: "distro >= 1.4.0", + + # Backported configparser for Python 2: + "configparser >= 5.0.1 ; python_version < '3.0'", ] setup_requires = [ diff --git a/src/allmydata/client.py b/src/allmydata/client.py index af3a17d48..a2ba80961 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -2,10 +2,9 @@ import os, stat, time, weakref from base64 import urlsafe_b64encode from functools import partial from errno import ENOENT, EPERM -try: - from ConfigParser import NoSectionError -except ImportError: - from configparser import NoSectionError + +# On Python 2 this will be the backported package: +from configparser import NoSectionError from foolscap.furl import ( decode_furl, diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 26fc6fc97..d3e84f213 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -13,8 +13,9 @@ from io import StringIO import tempfile from base64 import b32decode, b32encode -# Python 2 compatibility -from six.moves import configparser +# On Python 2 this will be the backported package. +import configparser + from future.utils import PY2 if PY2: from io import BytesIO as StringIO # noqa: F811 diff --git a/src/allmydata/scripts/common.py b/src/allmydata/scripts/common.py index b2bb8a1e6..34266ee72 100644 --- a/src/allmydata/scripts/common.py +++ b/src/allmydata/scripts/common.py @@ -8,7 +8,9 @@ from os.path import join from future.utils import PY2 if PY2: from future.builtins import str # noqa: F401 -from six.moves.configparser import NoSectionError + +# On Python 2 this will be the backported package: +from configparser import NoSectionError from twisted.python import usage diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index 193f6d0f9..1e4497d68 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -31,12 +31,10 @@ the foolscap-based server implemented in src/allmydata/storage/*.py . from past.builtins import unicode import re, time, hashlib -try: - from ConfigParser import ( - NoSectionError, - ) -except ImportError: - from configparser import NoSectionError + +# On Python 2 this will be the backport. +from configparser import NoSectionError + import attr from zope.interface import ( Attribute, diff --git a/src/allmydata/util/configutil.py b/src/allmydata/util/configutil.py index 1a1a93f18..97516d279 100644 --- a/src/allmydata/util/configutil.py +++ b/src/allmydata/util/configutil.py @@ -16,13 +16,9 @@ if PY2: # we do "r" or "w". from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 -if PY2: - # In theory on Python 2 configparser also works, but then code gets the - # wrong exceptions and they don't get handled. So just use native parser - # for now. - from ConfigParser import SafeConfigParser -else: - from configparser import SafeConfigParser +# On Python 2 we use the backport package; that means we always get unicode +# out. +from configparser import SafeConfigParser import attr