--- Lib/ConfigParser.py +++ Lib/ConfigParser.py @@ -94,6 +94,7 @@ _default_dict = dict import re +import string __all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError", "InterpolationError", "InterpolationDepthError", @@ -106,6 +107,14 @@ MAX_INTERPOLATION_DEPTH = 10 +_lower_map = string.maketrans(string.ascii_uppercase, string.ascii_lowercase) + +def _lower(value): + if isinstance(value, str): + return value.translate(_lower_map) + else: + return value.lower() + # exception classes @@ -257,7 +266,7 @@ already exists. Raise ValueError if name is DEFAULT or any of it's case-insensitive variants. """ - if section.lower() == "default": + if _lower(section) == "default": raise ValueError, 'Invalid section name: %s' % section if section in self._sections: @@ -366,12 +375,12 @@ def getboolean(self, section, option): v = self.get(section, option) - if v.lower() not in self._boolean_states: + if _lower(v) not in self._boolean_states: raise ValueError, 'Not a boolean: %s' % v - return self._boolean_states[v.lower()] + return self._boolean_states[_lower(v)] def optionxform(self, optionstr): - return optionstr.lower() + return _lower(optionstr) def has_option(self, section, option): """Check for the existence of a given option in a given section.""" @@ -483,7 +492,7 @@ # comment or blank line? if line.strip() == '' or line[0] in '#;': continue - if line.split(None, 1)[0].lower() == 'rem' and line[0] in "rR": + if _lower(line.split(None, 1)[0]) == 'rem' and line[0] in "rR": # no leading whitespace continue # continuation line?