summaryrefslogtreecommitdiff
path: root/src/mailman/config/config.py
diff options
context:
space:
mode:
authorBarry Warsaw2014-11-30 21:51:03 -0500
committerBarry Warsaw2014-11-30 21:51:03 -0500
commit44e43727be13e3554342c2b5b75b7dc42abdb18c (patch)
treea0b97771f5d0856709ac8ab48c1e8f9eeecef352 /src/mailman/config/config.py
parent065060e56ac2445b6749b60480e9c42573854c5e (diff)
downloadmailman-44e43727be13e3554342c2b5b75b7dc42abdb18c.tar.gz
mailman-44e43727be13e3554342c2b5b75b7dc42abdb18c.tar.zst
mailman-44e43727be13e3554342c2b5b75b7dc42abdb18c.zip
Diffstat (limited to 'src/mailman/config/config.py')
-rw-r--r--src/mailman/config/config.py49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/mailman/config/config.py b/src/mailman/config/config.py
index 649d6c5e1..c92485176 100644
--- a/src/mailman/config/config.py
+++ b/src/mailman/config/config.py
@@ -30,11 +30,12 @@ __all__ = [
import os
import sys
-from ConfigParser import SafeConfigParser
from flufl.lock import Lock
from lazr.config import ConfigSchema, as_boolean
-from pkg_resources import resource_stream, resource_string
+from pkg_resources import resource_filename, resource_string
+from six.moves.configparser import ConfigParser, RawConfigParser
from string import Template
+from unittest.mock import patch
from zope.component import getUtility
from zope.event import notify
from zope.interface import implementer
@@ -66,6 +67,11 @@ MAILMAN_CFG_TEMPLATE = """\
# enabled: yes
# recipient: your.address@your.domain"""
+class _NonStrictRawConfigParser(RawConfigParser):
+ def __init__(self, *args, **kws):
+ kws['strict'] = False
+ super().__init__(*args, **kws)
+
@implementer(IConfiguration)
@@ -99,30 +105,27 @@ class Configuration:
def load(self, filename=None):
"""Load the configuration from the schema and config files."""
- schema_file = config_file = None
- try:
- schema_file = resource_stream('mailman.config', 'schema.cfg')
- schema = ConfigSchema('schema.cfg', schema_file)
- # If a configuration file was given, load it now too. First, load
- # the absolute minimum default configuration, then if a
- # configuration filename was given by the user, push it.
- config_file = resource_stream('mailman.config', 'mailman.cfg')
- self._config = schema.loadFile(config_file, 'mailman.cfg')
- if filename is not None:
- self.filename = filename
- with open(filename) as user_config:
- self._config.push(filename, user_config.read())
- finally:
- if schema_file:
- schema_file.close()
- if config_file:
- config_file.close()
- self._post_process()
+ schema_file = resource_filename('mailman.config', 'schema.cfg')
+ schema = ConfigSchema(schema_file)
+ # If a configuration file was given, load it now too. First, load
+ # the absolute minimum default configuration, then if a
+ # configuration filename was given by the user, push it.
+ config_file = resource_filename('mailman.config', 'mailman.cfg')
+ self._config = schema.load(config_file)
+ if filename is not None:
+ self.filename = filename
+ with open(filename) as user_config:
+ self.push(filename, user_config.read())
def push(self, config_name, config_string):
"""Push a new configuration onto the stack."""
self._clear()
- self._config.push(config_name, config_string)
+ # In Python 3, the RawConfigParser() must be created with
+ # strict=False, otherwise we'll get a DuplicateSectionError.
+ # See https://bugs.launchpad.net/lazr.config/+bug/1397779
+ with patch('lazr.config._config.RawConfigParser',
+ _NonStrictRawConfigParser):
+ self._config.push(config_name, config_string)
self._post_process()
def pop(self, config_name):
@@ -305,7 +308,7 @@ def external_configuration(path):
"""
# Is the context coming from a file system or Python path?
cfg_path = expand_path(path)
- parser = SafeConfigParser()
+ parser = ConfigParser()
files = parser.read(cfg_path)
if files != [cfg_path]:
raise MissingConfigurationFileError(path)