From 1cbf206d322ad1fac12b4bb5a64d501ca021a61d Mon Sep 17 00:00:00 2001 From: David Goodger Date: Sun, 3 Oct 2004 15:55:09 +0000 Subject: SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work. --- Lib/ConfigParser.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Lib/ConfigParser.py') diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py index acbf3ea144..ade9614796 100644 --- a/Lib/ConfigParser.py +++ b/Lib/ConfigParser.py @@ -92,7 +92,8 @@ import re __all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError", "InterpolationError", "InterpolationDepthError", "InterpolationSyntaxError", "ParsingError", - "MissingSectionHeaderError", "ConfigParser", "SafeConfigParser", + "MissingSectionHeaderError", + "ConfigParser", "SafeConfigParser", "RawConfigParser", "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"] DEFAULTSECT = "DEFAULT" @@ -348,8 +349,6 @@ class RawConfigParser: def set(self, section, option, value): """Set an option.""" - if not isinstance(value, basestring): - raise TypeError("option values must be strings") if not section or section == DEFAULTSECT: sectdict = self._defaults else: @@ -633,3 +632,9 @@ class SafeConfigParser(ConfigParser): raise InterpolationSyntaxError( option, section, "'%%' must be followed by '%%' or '(', found: %r" % (rest,)) + + def set(self, section, option, value): + """Set an option. Extend ConfigParser.set: check for string values.""" + if not isinstance(value, basestring): + raise TypeError("option values must be strings") + ConfigParser.set(self, section, option, value) -- cgit v1.2.1