From b5d84e68cb1aa654c3cb242cef416ccd1253fb13 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Mon, 26 Oct 2015 19:34:45 +0100 Subject: Modifying ConfigParser.py --- MgaRepo/ConfigParser.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/MgaRepo/ConfigParser.py b/MgaRepo/ConfigParser.py index bac6d36..50a4cfe 100644 --- a/MgaRepo/ConfigParser.py +++ b/MgaRepo/ConfigParser.py @@ -3,7 +3,7 @@ This is a heavily hacked version of ConfigParser to keep the order in which options and sections are read, and allow multiple options with the same key. """ -from __future__ import generators + import string, types import re @@ -101,21 +101,21 @@ class ConfigParser: return self.__defaults def sections(self): - return self.__sections_dict.keys() + return list(self.__sections_dict.keys()) def has_section(self, section): - return self.__sections_dict.has_key(section) + return section in self.__sections_dict def options(self, section): self.__sections_dict[section] try: - opts = self.__sections_dict[section].keys() + opts = list(self.__sections_dict[section].keys()) except KeyError: raise NoSectionError(section) - return self.__defaults.keys()+opts + return list(self.__defaults.keys())+opts def read(self, filenames): - if type(filenames) in types.StringTypes: + if type(filenames) in str: filenames = [filenames] for filename in filenames: try: @@ -134,7 +134,7 @@ class ConfigParser: self.__read(fp, filename) def set(self, section, option, value): - if self.__sections_dict.has_key(section): + if section in self.__sections_dict: sectdict = self.__sections_dict[section] sectlist = [] self.__sections_list.append((section, sectlist)) @@ -221,7 +221,7 @@ class ConfigParser: if value.find("%(") >= 0: try: value = value % vars - except KeyError, key: + except KeyError as key: raise InterpolationError(key, option, section, rawval) else: break @@ -242,8 +242,8 @@ class ConfigParser: states = {'1': 1, 'yes': 1, 'true': 1, 'on': 1, '0': 0, 'no': 0, 'false': 0, 'off': 0} v = self.get(section, option) - if not states.has_key(v.lower()): - raise ValueError, 'Not a boolean: %s' % v + if v.lower() not in states: + raise ValueError('Not a boolean: %s' % v) return states[v.lower()] def optionxform(self, optionstr): @@ -253,12 +253,12 @@ class ConfigParser: def has_option(self, section, option): """Check for the existence of a given option in a given section.""" if not section or section == "DEFAULT": - return self.__defaults.has_key(option) + return option in self.__defaults elif not self.has_section(section): return 0 else: option = self.optionxform(option) - return self.__sections_dict[section].has_key(option) + return option in self.__sections_dict[section] SECTCRE = re.compile(r'\[(?P
[^]]+)\]') OPTCRE = re.compile(r'(?P