[Python-checkins] CVS: python/dist/src/Lib ConfigParser.py,1.22,1.23
Fred L. Drake
python-dev@python.org
Wed, 27 Sep 2000 15:43:58 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv4930/Lib
Modified Files:
ConfigParser.py
Log Message:
Allow spaces in section names.
Do not expose the __name__ when reporting the list of options available
for a section since that is for internal use.
This closes SourceForge bug #115357.
Additionally, define InterpolationDepthError and MAX_INTERPOLATION_DEPTH.
The exception is raised by get*() when value interpolation cannot be
completed within the defined recursion limit. The constant is only
informative; changing it will not affect the allowed depth.
Fix the exit from get() so that None is not returned if the depth is met
or exceeded; either return the value of raise InterpolationDepthError.
Index: ConfigParser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ConfigParser.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** ConfigParser.py 2000/09/25 14:42:33 1.22
--- ConfigParser.py 2000/09/27 22:43:54 1.23
***************
*** 92,96 ****
--- 92,98 ----
DEFAULTSECT = "DEFAULT"
+ MAX_INTERPOLATION_DEPTH = 10
+
# exception classes
***************
*** 131,143 ****
self.section = section
! class MissingSectionHeaderError(Error):
! def __init__(self, filename, lineno, line):
! Error.__init__(
! self,
! 'File contains no section headers.\nfile: %s, line: %d\n%s' %
! (filename, lineno, line))
! self.filename = filename
! self.lineno = lineno
! self.line = line
class ParsingError(Error):
--- 133,146 ----
self.section = section
! class InterpolationDepthError(Error):
! def __init__(self, option, section, rawval):
! Error.__init__(self,
! "Value interpolation too deeply recursive:\n"
! "\tsection: [%s]\n"
! "\toption : %s\n"
! "\trawval : %s\n"
! % (section, option, rawval))
! self.option = option
! self.section = section
class ParsingError(Error):
***************
*** 151,155 ****
--- 154,168 ----
self._msg = self._msg + '\n\t[line %2d]: %s' % (lineno, line)
+ class MissingSectionHeaderError(ParsingError):
+ def __init__(self, filename, lineno, line):
+ Error.__init__(
+ self,
+ 'File contains no section headers.\nfile: %s, line: %d\n%s' %
+ (filename, lineno, line))
+ self.filename = filename
+ self.lineno = lineno
+ self.line = line
+
class ConfigParser:
***************
*** 184,188 ****
The DEFAULT section is not acknowledged.
"""
! return self.__sections.has_key(section)
def options(self, section):
--- 197,201 ----
The DEFAULT section is not acknowledged.
"""
! return section in self.sections()
def options(self, section):
***************
*** 193,205 ****
raise NoSectionError(section)
opts.update(self.__defaults)
return opts.keys()
def has_option(self, section, option):
"""Return whether the given section has the given option."""
! try:
! opts = self.__sections[section]
! except KeyError:
! raise NoSectionError(section)
! return opts.has_key(option)
def read(self, filenames):
--- 206,216 ----
raise NoSectionError(section)
opts.update(self.__defaults)
+ if opts.has_key('__name__'):
+ del opts['__name__']
return opts.keys()
def has_option(self, section, option):
"""Return whether the given section has the given option."""
! return option in self.options(section)
def read(self, filenames):
***************
*** 267,274 ****
except KeyError:
raise NoOptionError(option, section)
! # do the string interpolation
if raw:
return rawval
value = rawval # Make it a pretty variable name
depth = 0
--- 278,286 ----
except KeyError:
raise NoOptionError(option, section)
!
if raw:
return rawval
+ # do the string interpolation
value = rawval # Make it a pretty variable name
depth = 0
***************
*** 281,285 ****
raise InterpolationError(key, option, section, rawval)
else:
! return value
def __get(self, section, conv, option):
--- 293,300 ----
raise InterpolationError(key, option, section, rawval)
else:
! break
! if value.find("%(") >= 0:
! raise InterpolationDepthError(option, section, rawval)
! return value
def __get(self, section, conv, option):
***************
*** 366,370 ****
SECTCRE = re.compile(
r'\[' # [
! r'(?P<header>[-\w_.*,(){}]+)' # a lot of stuff found by IvL
r'\]' # ]
)
--- 381,385 ----
SECTCRE = re.compile(
r'\[' # [
! r'(?P<header>[-\w_.*,(){} ]+)' # a lot of stuff found by IvL
r'\]' # ]
)