- added InterpolationSyntaxError to __all__

- added docstring to exceptions
This commit is contained in:
Fred Drake 2002-12-30 23:51:45 +00:00
parent 81e4aa7054
commit 8d5dd98a2e
1 changed files with 25 additions and 4 deletions

View File

@ -89,9 +89,10 @@ ConfigParser -- responsible for for parsing a list of
import re import re
__all__ = ["NoSectionError","DuplicateSectionError","NoOptionError", __all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError",
"InterpolationError","InterpolationDepthError","ParsingError", "InterpolationError", "InterpolationDepthError",
"MissingSectionHeaderError","ConfigParser", "InterpolationSyntaxError", "ParsingError",
"MissingSectionHeaderError", "ConfigParser",
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"] "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
DEFAULTSECT = "DEFAULT" DEFAULTSECT = "DEFAULT"
@ -102,24 +103,34 @@ MAX_INTERPOLATION_DEPTH = 10
# exception classes # exception classes
class Error(Exception): class Error(Exception):
"""Base class for ConfigParser exceptions."""
def __init__(self, msg=''): def __init__(self, msg=''):
self._msg = msg self._msg = msg
Exception.__init__(self, msg) Exception.__init__(self, msg)
def __repr__(self): def __repr__(self):
return self._msg return self._msg
__str__ = __repr__ __str__ = __repr__
class NoSectionError(Error): class NoSectionError(Error):
"""Raised when no section matches a requested option."""
def __init__(self, section): def __init__(self, section):
Error.__init__(self, 'No section: %s' % section) Error.__init__(self, 'No section: %s' % section)
self.section = section self.section = section
class DuplicateSectionError(Error): class DuplicateSectionError(Error):
"""Raised when a section is multiply-created."""
def __init__(self, section): def __init__(self, section):
Error.__init__(self, "Section %s already exists" % section) Error.__init__(self, "Section %s already exists" % section)
self.section = section self.section = section
class NoOptionError(Error): class NoOptionError(Error):
"""A requested option was not found."""
def __init__(self, option, section): def __init__(self, option, section):
Error.__init__(self, "No option `%s' in section: %s" % Error.__init__(self, "No option `%s' in section: %s" %
(option, section)) (option, section))
@ -127,6 +138,8 @@ class NoOptionError(Error):
self.section = section self.section = section
class InterpolationError(Error): class InterpolationError(Error):
"""A string substitution required a setting which was not available."""
def __init__(self, reference, option, section, rawval): def __init__(self, reference, option, section, rawval):
Error.__init__(self, Error.__init__(self,
"Bad value substitution:\n" "Bad value substitution:\n"
@ -139,9 +152,13 @@ class InterpolationError(Error):
self.option = option self.option = option
self.section = section self.section = section
class InterpolationSyntaxError(Error): pass class InterpolationSyntaxError(Error):
"""Raised when the source text into which substitutions are made
does not conform to the required syntax."""
class InterpolationDepthError(Error): class InterpolationDepthError(Error):
"""Raised when substitutions are nested too deeply."""
def __init__(self, option, section, rawval): def __init__(self, option, section, rawval):
Error.__init__(self, Error.__init__(self,
"Value interpolation too deeply recursive:\n" "Value interpolation too deeply recursive:\n"
@ -153,6 +170,8 @@ class InterpolationDepthError(Error):
self.section = section self.section = section
class ParsingError(Error): class ParsingError(Error):
"""Raised when a configuration file does not follow legal syntax."""
def __init__(self, filename): def __init__(self, filename):
Error.__init__(self, 'File contains parsing errors: %s' % filename) Error.__init__(self, 'File contains parsing errors: %s' % filename)
self.filename = filename self.filename = filename
@ -163,6 +182,8 @@ class ParsingError(Error):
self._msg = self._msg + '\n\t[line %2d]: %s' % (lineno, line) self._msg = self._msg + '\n\t[line %2d]: %s' % (lineno, line)
class MissingSectionHeaderError(ParsingError): class MissingSectionHeaderError(ParsingError):
"""Raised when a key-value pair is found before any section header."""
def __init__(self, filename, lineno, line): def __init__(self, filename, lineno, line):
Error.__init__( Error.__init__(
self, self,