# HG changeset patch # User Franz Glasner # Date 1523703135 -7200 # Node ID 614a0a648f487c230d974fdb1bd77dc9a896f3e4 # Parent be352645871ce9c73464ad95580b8ab8bdd67cc3 Work around the deprecation of SafeConfigParser in Python 3.2+ diff -r be352645871c -r 614a0a648f48 configmix/ini.py --- a/configmix/ini.py Sat Apr 14 12:44:42 2018 +0200 +++ b/configmix/ini.py Sat Apr 14 12:52:15 2018 +0200 @@ -14,9 +14,16 @@ import io import locale try: - from configparser import SafeConfigParser, NoSectionError, NoOptionError + from configparser import ConfigParser, NoSectionError, NoOptionError + # SafeConfigParser is deprecated in Python 3.2+ (together with "readfp()") + if hasattr(ConfigParser, "read_file"): + _ConfigParserBase = ConfigParser + else: + from configparser import SafeConfigParser + _ConfigParserBase = SafeConfigParser except ImportError: from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError + _ConfigParserBase = SafeConfigParser try: from collections import OrderedDict as DictImpl except ImportError: @@ -32,7 +39,7 @@ "load"] -class INIConfigParser(SafeConfigParser): +class INIConfigParser(_ConfigParserBase): """A case sensitive config parser that returns all-unicode string values. @@ -40,7 +47,7 @@ """ def __init__(self, filename, executable=None, encoding=None): - SafeConfigParser.__init__(self) + _ConfigParserBase.__init__(self) if executable is None: executable = sys.argv[0] if PY2: @@ -81,10 +88,10 @@ self.set(None, u("self"), filename) self.set(None, u("here"), os.path.dirname(filename)) self.set(None, u("root"), os.path.dirname(self.executable)) - if hasattr(SafeConfigParser, "read_file"): - SafeConfigParser.read_file(self, fp, source=filename) + if hasattr(_ConfigParserBase, "read_file"): + _ConfigParserBase.read_file(self, fp, source=filename) else: - SafeConfigParser.readfp(self, fp, filename=filename) + _ConfigParserBase.readfp(self, fp, filename=filename) self.filename = filename self.root = os.path.dirname(self.executable)