Remove compatibility with Python 2
Python 2 reached its EOL in 2020. Change-Id: I137bcba3c6cc4efe83fbc34aded269585b94a6d5
This commit is contained in:
parent
ca25191181
commit
58d046a236
|
@ -15,19 +15,11 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
import datetime
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
|
||||
import base64
|
||||
import configparser
|
||||
import datetime
|
||||
import json
|
||||
from io import StringIO
|
||||
import os
|
||||
import pwd
|
||||
import re
|
||||
|
@ -136,7 +128,7 @@ class MultiKeyDict(OrderedDict):
|
|||
return super(MultiKeyDict, self).__setitem__(key, value)
|
||||
|
||||
|
||||
class ConfigTemplateParser(ConfigParser.RawConfigParser):
|
||||
class ConfigTemplateParser(configparser.RawConfigParser):
|
||||
"""ConfigParser which supports multi key value.
|
||||
The parser will use keys with multiple variables in a set as a multiple
|
||||
key value within a configuration file.
|
||||
|
@ -192,7 +184,7 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
|
|||
self._empty_lines_in_values = kwargs.get('allow_no_value', True)
|
||||
self._strict = kwargs.get('strict', False)
|
||||
self._allow_no_value = self._empty_lines_in_values
|
||||
ConfigParser.RawConfigParser.__init__(self, *args, **kwargs)
|
||||
super(ConfigTemplateParser, self).__init__(self, *args, **kwargs)
|
||||
|
||||
def set(self, section, option, value=None):
|
||||
if not section or section == 'DEFAULT':
|
||||
|
@ -439,7 +431,7 @@ class ActionModule(ActionBase):
|
|||
# already existing.
|
||||
try:
|
||||
config.add_section(section_name)
|
||||
except (ConfigParser.DuplicateSectionError, ValueError):
|
||||
except (configparser.DuplicateSectionError, ValueError):
|
||||
pass
|
||||
|
||||
# If there is an exception loading the RawConfigParser The config obj
|
||||
|
@ -463,10 +455,7 @@ class ActionModule(ActionBase):
|
|||
)
|
||||
|
||||
config_object = StringIO(resultant)
|
||||
try:
|
||||
config.read_file(config_object)
|
||||
except AttributeError:
|
||||
config.readfp(config_object)
|
||||
config.read_file(config_object)
|
||||
|
||||
if default_section != 'DEFAULT':
|
||||
_add_section(section_name=default_section)
|
||||
|
@ -489,7 +478,7 @@ class ActionModule(ActionBase):
|
|||
for key, value in items.items():
|
||||
try:
|
||||
self._option_write(config, section, key, value)
|
||||
except ConfigParser.NoSectionError as exp:
|
||||
except configparser.NoSectionError as exp:
|
||||
error_msg = str(exp)
|
||||
error_msg += (
|
||||
' Try being more explicit with your override'
|
||||
|
|
Loading…
Reference in New Issue