← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3only-configparser into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3only-configparser into launchpad:master.

Commit message:
Use Python 3 configparser module directly

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/406657
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3only-configparser into launchpad:master.
diff --git a/database/schema/security.py b/database/schema/security.py
index 28219ee..ea62868 100755
--- a/database/schema/security.py
+++ b/database/schema/security.py
@@ -8,6 +8,7 @@ __metaclass__ = type
 import _pythonpath  # noqa: F401
 
 from collections import defaultdict
+from configparser import ConfigParser
 from optparse import OptionParser
 import os
 import re
@@ -16,7 +17,6 @@ import sys
 import six
 
 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,
@@ -252,7 +252,7 @@ CONFIG_DEFAULTS = {
 
 def main(options, master_con=None):
     # Load the config file
-    config = SafeConfigParser(CONFIG_DEFAULTS)
+    config = ConfigParser(CONFIG_DEFAULTS)
     configfile_name = os.path.join(os.path.dirname(__file__), 'security.cfg')
     config.read([configfile_name])
 
diff --git a/lib/lp/services/compat.py b/lib/lp/services/compat.py
index 9f6d16a..4a9e514 100644
--- a/lib/lp/services/compat.py
+++ b/lib/lp/services/compat.py
@@ -13,15 +13,9 @@ __all__ = [
     'message_as_bytes',
     'message_from_bytes',
     'mock',
-    'SafeConfigParser',
     ]
 
 try:
-    from configparser import ConfigParser as SafeConfigParser
-except ImportError:
-    from ConfigParser import SafeConfigParser
-
-try:
     from email import message_from_bytes
 except ImportError:
     from email import message_from_string as message_from_bytes
diff --git a/lib/lp/services/config/fixture.py b/lib/lp/services/config/fixture.py
index 10426e4..944f98a 100644
--- a/lib/lp/services/config/fixture.py
+++ b/lib/lp/services/config/fixture.py
@@ -11,6 +11,7 @@ __all__ = [
     'ConfigUseFixture',
     ]
 
+from configparser import RawConfigParser
 import os.path
 import shutil
 from textwrap import dedent
@@ -18,7 +19,6 @@ from textwrap import dedent
 from fixtures import Fixture
 import scandir
 import six
-from six.moves.configparser import RawConfigParser
 
 from lp.services.config import config
 
diff --git a/lib/lp/services/rabbit/tests/test_server.py b/lib/lp/services/rabbit/tests/test_server.py
index ea931d2..af19e04 100644
--- a/lib/lp/services/rabbit/tests/test_server.py
+++ b/lib/lp/services/rabbit/tests/test_server.py
@@ -5,12 +5,11 @@
 
 __metaclass__ = type
 
+from configparser import ConfigParser
 import io
-import sys
 
 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
@@ -28,12 +27,8 @@ class TestRabbitServer(TestCase):
 
         # RabbitServer pokes some .ini configuration into its config.
         fixture = self.useFixture(RabbitServer())
-        service_config = SafeConfigParser()
-        if sys.version_info[:2] >= (3, 2):
-            read_file = service_config.read_file
-        else:
-            read_file = service_config.readfp
-        read_file(io.StringIO(fixture.config.service_config))
+        service_config = ConfigParser()
+        service_config.read_file(io.StringIO(fixture.config.service_config))
         self.assertEqual(["rabbitmq"], service_config.sections())
         expected = {
             "host": "localhost:%d" % fixture.config.port,
diff --git a/lib/lp/services/scripts/base.py b/lib/lp/services/scripts/base.py
index 66ebdbf..cd3f19b 100644
--- a/lib/lp/services/scripts/base.py
+++ b/lib/lp/services/scripts/base.py
@@ -11,6 +11,7 @@ __all__ = [
     'SilentLaunchpadScriptFailure',
     ]
 
+from configparser import ConfigParser
 from contextlib import contextmanager
 from cProfile import Profile
 import datetime
@@ -34,7 +35,6 @@ 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,
@@ -462,7 +462,7 @@ def cronscript_enabled(control_url, name, log):
         log.exception("Error loading %s" % control_url)
         return True
 
-    cron_config = SafeConfigParser({'enabled': str(True)})
+    cron_config = ConfigParser({'enabled': str(True)})
 
     # Try reading the config file. If it fails, we log the
     # traceback and continue on using the defaults.
diff --git a/lib/lp/testing/fixture.py b/lib/lp/testing/fixture.py
index 42ea06f..a066ebc 100644
--- a/lib/lp/testing/fixture.py
+++ b/lib/lp/testing/fixture.py
@@ -16,6 +16,7 @@ __all__ = [
     'ZopeViewReplacementFixture',
     ]
 
+from configparser import ConfigParser
 import os.path
 import socket
 import time
@@ -42,7 +43,6 @@ 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
@@ -82,7 +82,7 @@ class PGBouncerFixture(pgbouncer.fixture.PGBouncerFixture):
         # Known users, pulled from security.cfg
         security_cfg_path = os.path.join(
             config.root, 'database', 'schema', 'security.cfg')
-        security_cfg_config = SafeConfigParser({})
+        security_cfg_config = ConfigParser({})
         security_cfg_config.read([security_cfg_path])
         for section_name in security_cfg_config.sections():
             self.users[section_name] = 'trusted'
diff --git a/utilities/make-requirements.py b/utilities/make-requirements.py
index b66d519..21b68da 100755
--- a/utilities/make-requirements.py
+++ b/utilities/make-requirements.py
@@ -7,12 +7,7 @@
 
 from argparse import ArgumentParser
 from collections import defaultdict
-try:
-    # Python 3
-    from configparser import ConfigParser
-except ImportError:
-    # Python 2
-    from ConfigParser import SafeConfigParser as ConfigParser
+from configparser import ConfigParser
 import logging
 
 from pkg_resources import parse_requirements