From 9c97101793fc6cf665eedde67dc888c4e25ccba7 Mon Sep 17 00:00:00 2001 From: Drew Winstel Date: Thu, 24 Jan 2019 13:19:54 -0600 Subject: [PATCH] Avoid DeprecationWarning when importing config parser in Python 3.2+ This is because the class was renamed in Python 3.2 from `SafeConfigParser` to `ConfigParser` and a deprecation warning was put in its place. See https://github.com/python/cpython/commit/7f64c8a5121576fd8f92010b7a936b89581c4051 for more. --- conflagration/wrap.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/conflagration/wrap.py b/conflagration/wrap.py index 9c345af..8f8e27f 100644 --- a/conflagration/wrap.py +++ b/conflagration/wrap.py @@ -1,7 +1,11 @@ import os import six -from six.moves.configparser import SafeConfigParser + +if six.PY3: + from six.moves.configparser import ConfigParser +else: + from six.moves.configparser import SafeConfigParser as ConfigParser class ConfigFile(object): @@ -11,7 +15,7 @@ def read(cfgfile): if not os.path.exists(cfgfile): ex = IOError if six.PY2 else FileNotFoundError raise ex('File {name} does not exist.'.format(name=cfgfile)) - data = SafeConfigParser() + data = ConfigParser() data.read(cfgfile) return data @@ -54,7 +58,7 @@ def write(cfg_obj, output_file_path): Only supports writing out a conflagration object with namespaces that follow the section.key=value pattern that ConfigFile.parse generates """ - parser = SafeConfigParser() + parser = ConfigParser() for k in cfg_obj.__dict__.keys(): parser.add_section(k) try: