mirror of
https://github.com/python/cpython.git
synced 2025-08-28 12:45:07 +00:00
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.
This commit is contained in:
parent
68a1abdade
commit
1cbf206d32
4 changed files with 78 additions and 21 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue