launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24464
[Merge] ~cjwatson/launchpad:py3-safeconfigparser into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-safeconfigparser into launchpad:master.
Commit message:
Add Python 3 compatibility for SafeConfigParser
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/380593
SafeConfigParser was renamed to ConfigParser in 3.2, but we need to continue using the Safe variant on older Python versions. I've established lp.services.compat to help with this; I expect this module to be useful for other things as our Python 3 port progresses.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-safeconfigparser into launchpad:master.
diff --git a/database/schema/security.py b/database/schema/security.py
index 967790d..2837bdf 100755
--- a/database/schema/security.py
+++ b/database/schema/security.py
@@ -8,13 +8,13 @@ __metaclass__ = type
import _pythonpath
from collections import defaultdict
-from ConfigParser import SafeConfigParser
from optparse import OptionParser
import os
import re
import sys
from fti import quote_identifier
+from lp.services.compat import SafeConfigParser
from lp.services.database.sqlbase import connect
from lp.services.scripts import (
db_options,
diff --git a/lib/lp/services/compat.py b/lib/lp/services/compat.py
new file mode 100644
index 0000000..942e690
--- /dev/null
+++ b/lib/lp/services/compat.py
@@ -0,0 +1,19 @@
+# Copyright 2020 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Python 2/3 compatibility layer.
+
+Use this for things that six doesn't provide.
+"""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'SafeConfigParser',
+ ]
+
+try:
+ from configparser import ConfigParser as SafeConfigParser
+except ImportError:
+ from ConfigParser import SafeConfigParser
diff --git a/lib/lp/services/rabbit/tests/test_server.py b/lib/lp/services/rabbit/tests/test_server.py
index fe82920..6ffc87f 100644
--- a/lib/lp/services/rabbit/tests/test_server.py
+++ b/lib/lp/services/rabbit/tests/test_server.py
@@ -5,11 +5,11 @@
__metaclass__ = type
-from ConfigParser import SafeConfigParser
from StringIO import StringIO
from fixtures import EnvironmentVariableFixture
+from lp.services.compat import SafeConfigParser
from lp.services.rabbit.server import RabbitServer
from lp.testing import TestCase
from lp.testing.layers import BaseLayer
diff --git a/lib/lp/services/scripts/base.py b/lib/lp/services/scripts/base.py
index 509df60..d4b07f0 100644
--- a/lib/lp/services/scripts/base.py
+++ b/lib/lp/services/scripts/base.py
@@ -11,7 +11,6 @@ __all__ = [
'SilentLaunchpadScriptFailure',
]
-from ConfigParser import SafeConfigParser
from contextlib import contextmanager
from cProfile import Profile
import datetime
@@ -34,6 +33,7 @@ import transaction
from zope.component import getUtility
from lp.services import scripts
+from lp.services.compat import SafeConfigParser
from lp.services.config import (
config,
dbconfig,
diff --git a/lib/lp/testing/fixture.py b/lib/lp/testing/fixture.py
index 34bfed2..374c1a6 100644
--- a/lib/lp/testing/fixture.py
+++ b/lib/lp/testing/fixture.py
@@ -16,7 +16,6 @@ __all__ = [
'ZopeViewReplacementFixture',
]
-from ConfigParser import SafeConfigParser
import os.path
import socket
import time
@@ -43,6 +42,7 @@ from zope.security.checker import (
)
from lp.services import webapp
+from lp.services.compat import SafeConfigParser
from lp.services.config import config
from lp.services.database.interfaces import IStore
from lp.services.librarian.model import LibraryFileAlias