diff options
Diffstat (limited to 'reconfigure/parsers/iniparse/compat.py')
-rw-r--r-- | reconfigure/parsers/iniparse/compat.py | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/reconfigure/parsers/iniparse/compat.py b/reconfigure/parsers/iniparse/compat.py index 17c4f67..01df27c 100644 --- a/reconfigure/parsers/iniparse/compat.py +++ b/reconfigure/parsers/iniparse/compat.py @@ -12,19 +12,33 @@ The underlying INIConfig object can be accessed as cfg.data """ import re -from ConfigParser import DuplicateSectionError, \ - NoSectionError, NoOptionError, \ - InterpolationMissingOptionError, \ - InterpolationDepthError, \ - InterpolationSyntaxError, \ - DEFAULTSECT, MAX_INTERPOLATION_DEPTH +try: + from ConfigParser import DuplicateSectionError, \ + NoSectionError, NoOptionError, \ + InterpolationMissingOptionError, \ + InterpolationDepthError, \ + InterpolationSyntaxError, \ + DEFAULTSECT, MAX_INTERPOLATION_DEPTH + + # These are imported only for compatiability. + # The code below does not reference them directly. + from ConfigParser import Error, InterpolationError, \ + MissingSectionHeaderError, ParsingError +except ImportError: + from configparser import DuplicateSectionError, \ + NoSectionError, NoOptionError, \ + InterpolationMissingOptionError, \ + InterpolationDepthError, \ + InterpolationSyntaxError, \ + DEFAULTSECT, MAX_INTERPOLATION_DEPTH + + # These are imported only for compatiability. + # The code below does not reference them directly. + from configparser import Error, InterpolationError, \ + MissingSectionHeaderError, ParsingError + +import reconfigure.parsers.iniparse.ini -# These are imported only for compatiability. -# The code below does not reference them directly. -from ConfigParser import Error, InterpolationError, \ - MissingSectionHeaderError, ParsingError - -import ini class RawConfigParser(object): def __init__(self, defaults=None, dict_type=dict): @@ -56,7 +70,7 @@ class RawConfigParser(object): # The default section is the only one that gets the case-insensitive # treatment - so it is special-cased here. if section.lower() == "default": - raise ValueError, 'Invalid section name: %s' % section + raise ValueError('Invalid section name: %s' % section) if self.has_section(section): raise DuplicateSectionError(section) @@ -143,7 +157,7 @@ class RawConfigParser(object): def getboolean(self, section, option): v = self.get(section, option) if v.lower() not in self._boolean_states: - raise ValueError, 'Not a boolean: %s' % v + raise ValueError('Not a boolean: %s' % v) return self._boolean_states[v.lower()] def has_option(self, section, option): @@ -234,7 +248,7 @@ class ConfigParser(RawConfigParser): if "%(" in value: try: value = value % vars - except KeyError, e: + except KeyError as e: raise InterpolationMissingOptionError( option, section, rawval, e.args[0]) else: |