cpython: 5ecf650ede7c (original) (raw)

Mercurial > cpython

changeset 74545:5ecf650ede7c 2.7

Fixes #13760: picklability of ConfigParser exceptions [#13760]

Ɓukasz Langa lukasz@langa.pl
date Fri, 20 Jan 2012 17:02:08 +0100
parents b60c789c4ccd
children f6008e936fbc
files Lib/ConfigParser.py Lib/test/test_cfgparser.py
diffstat 2 files changed, 150 insertions(+), 1 deletions(-)[+] [-] Lib/ConfigParser.py 34 Lib/test/test_cfgparser.py 117

line wrap: on

line diff

--- a/Lib/ConfigParser.py +++ b/Lib/ConfigParser.py @@ -134,6 +134,9 @@ class Error(Exception): def repr(self): return self.message

+ str = repr class NoSectionError(Error): @@ -143,6 +146,9 @@ class NoSectionError(Error): Error.init(self, 'No section: %r' % (section,)) self.section = section

+ class DuplicateSectionError(Error): """Raised when a section is multiply-created.""" @@ -150,6 +156,9 @@ class DuplicateSectionError(Error): Error.init(self, "Section %r already exists" % section) self.section = section

+ class NoOptionError(Error): """A requested option was not found.""" @@ -159,6 +168,9 @@ class NoOptionError(Error): self.option = option self.section = section

+ class InterpolationError(Error): """Base class for interpolation-related exceptions.""" @@ -167,6 +179,9 @@ class InterpolationError(Error): self.option = option self.section = section

+ class InterpolationMissingOptionError(InterpolationError): """A string substitution required a setting which was not available.""" @@ -179,6 +194,11 @@ class InterpolationMissingOptionError(In % (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 @@ -194,19 +214,28 @@ class InterpolationDepthError(Interpolat "\trawval : %s\n" % (section, option, rawval)) InterpolationError.init(self, option, section, msg)

+

class ParsingError(Error): """Raised when a configuration file does not follow legal syntax."""

def append(self, lineno, line): self.errors.append((lineno, line)) self.message += '\n\t[line %2d]: %s' % (lineno, line)

+ class MissingSectionHeaderError(ParsingError): """Raised when a key-value pair is found before any section header.""" @@ -219,6 +248,9 @@ class MissingSectionHeaderError(ParsingE self.lineno = lineno self.line = line

+ class RawConfigParser: def init(self, defaults=None, dict_type=_default_dict,

--- a/Lib/test/test_cfgparser.py +++ b/Lib/test/test_cfgparser.py @@ -604,6 +604,122 @@ class SortedTestCase(RawConfigParserTest "o4 = 1\n\n") +class ExceptionPicklingTestCase(unittest.TestCase):

+

+

+

+

+

+

+

+

+

+

+ + def test_main(): test_support.run_unittest( ConfigParserTestCase, @@ -614,6 +730,7 @@ def test_main(): SortedTestCase, Issue7005TestCase, TestChainMap,