[Python-checkins] python/dist/src/Lib ConfigParser.py,1.56,1.57
fdrake@users.sourceforge.net
fdrake@users.sourceforge.net
Tue, 31 Dec 2002 09:23:30 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv31839/Lib
Modified Files:
ConfigParser.py
Log Message:
Further cleanup of exceptions. All interpolation-related exceptions
now derive from InterpolationError, which is not raised directly (only
subclasses get raised). This matches what the docs already said.
Index: ConfigParser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ConfigParser.py,v
retrieving revision 1.56
retrieving revision 1.57
diff -C2 -d -r1.56 -r1.57
*** ConfigParser.py 31 Dec 2002 06:55:41 -0000 1.56
--- ConfigParser.py 31 Dec 2002 17:23:27 -0000 1.57
***************
*** 107,115 ****
def __init__(self, msg=''):
! self._msg = msg
Exception.__init__(self, msg)
def __repr__(self):
! return self._msg
__str__ = __repr__
--- 107,115 ----
def __init__(self, msg=''):
! self.message = msg
Exception.__init__(self, msg)
def __repr__(self):
! return self.message
__str__ = __repr__
***************
*** 119,123 ****
def __init__(self, section):
! Error.__init__(self, 'No section: %s' % section)
self.section = section
--- 119,123 ----
def __init__(self, section):
! Error.__init__(self, 'No section: ' + `section`)
self.section = section
***************
*** 126,130 ****
def __init__(self, section):
! Error.__init__(self, "Section %s already exists" % section)
self.section = section
--- 126,130 ----
def __init__(self, section):
! Error.__init__(self, "Section %r already exists" % section)
self.section = section
***************
*** 133,137 ****
def __init__(self, option, section):
! Error.__init__(self, "No option `%s' in section: %s" %
(option, section))
self.option = option
--- 133,137 ----
def __init__(self, option, section):
! Error.__init__(self, "No option %r in section: %r" %
(option, section))
self.option = option
***************
*** 139,172 ****
class InterpolationError(Error):
! """A string substitution required a setting which was not available."""
! def __init__(self, reference, option, section, rawval):
! Error.__init__(self,
! "Bad value substitution:\n"
! "\tsection: [%s]\n"
! "\toption : %s\n"
! "\tkey : %s\n"
! "\trawval : %s\n"
! % (section, option, reference, rawval))
! self.reference = reference
self.option = option
self.section = section
! class InterpolationSyntaxError(Error):
"""Raised when the source text into which substitutions are made
does not conform to the required syntax."""
! class InterpolationDepthError(Error):
"""Raised when substitutions are nested too deeply."""
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):
--- 139,176 ----
class InterpolationError(Error):
! """Base class for interpolation-related exceptions."""
! def __init__(self, option, section, msg):
! Error.__init__(self, msg)
self.option = option
self.section = section
! class InterpolationMissingOptionError(InterpolationError):
! """A string substitution required a setting which was not available."""
!
! def __init__(self, option, section, rawval, reference):
! msg = ("Bad value substitution:\n"
! "\tsection: [%s]\n"
! "\toption : %s\n"
! "\tkey : %s\n"
! "\trawval : %s\n"
! % (section, option, reference, rawval))
! InterpolationError.__init__(self, option, section, msg)
! self.reference = reference
!
! class InterpolationSyntaxError(InterpolationError):
"""Raised when the source text into which substitutions are made
does not conform to the required syntax."""
! class InterpolationDepthError(InterpolationError):
"""Raised when substitutions are nested too deeply."""
def __init__(self, option, section, rawval):
! msg = ("Value interpolation too deeply recursive:\n"
! "\tsection: [%s]\n"
! "\toption : %s\n"
! "\trawval : %s\n"
! % (section, option, rawval))
! InterpolationError.__init__(self, option, section, msg)
class ParsingError(Error):
***************
*** 180,184 ****
def append(self, lineno, line):
self.errors.append((lineno, line))
! self._msg = self._msg + '\n\t[line %2d]: %s' % (lineno, line)
class MissingSectionHeaderError(ParsingError):
--- 184,188 ----
def append(self, lineno, line):
self.errors.append((lineno, line))
! self.message += '\n\t[line %2d]: %s' % (lineno, line)
class MissingSectionHeaderError(ParsingError):
***************
*** 556,560 ****
value = value % vars
except KeyError, e:
! raise InterpolationError(e[0], option, section, rawval)
else:
break
--- 560,565 ----
value = value % vars
except KeyError, e:
! raise InterpolationMissingOptionError(
! option, section, rawval, e[0])
else:
break
***************
*** 594,598 ****
if m is None:
raise InterpolationSyntaxError(
! "bad interpolation variable syntax at: %r" % rest)
var = m.group(1)
rest = rest[m.end():]
--- 599,603 ----
if m is None:
raise InterpolationSyntaxError(
! "bad interpolation variable reference", rest)
var = m.group(1)
rest = rest[m.end():]
***************
*** 600,604 ****
v = map[var]
except KeyError:
! raise InterpolationError(var, option, section, rest)
if "%" in v:
self._interpolate_some(option, accum, v,
--- 605,610 ----
v = map[var]
except KeyError:
! raise InterpolationMissingOptionError(
! option, section, rest, var)
if "%" in v:
self._interpolate_some(option, accum, v,
***************
*** 608,610 ****
else:
raise InterpolationSyntaxError(
! "'%' must be followed by '%' or '('")
--- 614,617 ----
else:
raise InterpolationSyntaxError(
! option, section, rest,
! "'%' must be followed by '%' or '(', found: " + `rest`)