Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1d524608
Commit
1d524608
authored
Jan 20, 2012
by
Łukasz Langa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #13760: picklability of ConfigParser exceptions
parent
45c97aba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
1 deletion
+150
-1
Lib/ConfigParser.py
Lib/ConfigParser.py
+33
-1
Lib/test/test_cfgparser.py
Lib/test/test_cfgparser.py
+117
-0
No files found.
Lib/ConfigParser.py
View file @
1d524608
...
@@ -134,6 +134,9 @@ class Error(Exception):
...
@@ -134,6 +134,9 @@ class Error(Exception):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
self
.
message
return
self
.
message
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
message
,)
__str__
=
__repr__
__str__
=
__repr__
class
NoSectionError
(
Error
):
class
NoSectionError
(
Error
):
...
@@ -143,6 +146,9 @@ class NoSectionError(Error):
...
@@ -143,6 +146,9 @@ class NoSectionError(Error):
Error
.
__init__
(
self
,
'No section: %r'
%
(
section
,))
Error
.
__init__
(
self
,
'No section: %r'
%
(
section
,))
self
.
section
=
section
self
.
section
=
section
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
section
,)
class
DuplicateSectionError
(
Error
):
class
DuplicateSectionError
(
Error
):
"""Raised when a section is multiply-created."""
"""Raised when a section is multiply-created."""
...
@@ -150,6 +156,9 @@ class DuplicateSectionError(Error):
...
@@ -150,6 +156,9 @@ class DuplicateSectionError(Error):
Error
.
__init__
(
self
,
"Section %r already exists"
%
section
)
Error
.
__init__
(
self
,
"Section %r already exists"
%
section
)
self
.
section
=
section
self
.
section
=
section
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
section
,)
class
NoOptionError
(
Error
):
class
NoOptionError
(
Error
):
"""A requested option was not found."""
"""A requested option was not found."""
...
@@ -159,6 +168,9 @@ class NoOptionError(Error):
...
@@ -159,6 +168,9 @@ class NoOptionError(Error):
self
.
option
=
option
self
.
option
=
option
self
.
section
=
section
self
.
section
=
section
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
option
,
self
.
section
)
class
InterpolationError
(
Error
):
class
InterpolationError
(
Error
):
"""Base class for interpolation-related exceptions."""
"""Base class for interpolation-related exceptions."""
...
@@ -167,6 +179,9 @@ class InterpolationError(Error):
...
@@ -167,6 +179,9 @@ class InterpolationError(Error):
self
.
option
=
option
self
.
option
=
option
self
.
section
=
section
self
.
section
=
section
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
option
,
self
.
section
,
self
.
message
)
class
InterpolationMissingOptionError
(
InterpolationError
):
class
InterpolationMissingOptionError
(
InterpolationError
):
"""A string substitution required a setting which was not available."""
"""A string substitution required a setting which was not available."""
...
@@ -179,6 +194,11 @@ class InterpolationMissingOptionError(InterpolationError):
...
@@ -179,6 +194,11 @@ class InterpolationMissingOptionError(InterpolationError):
%
(
section
,
option
,
reference
,
rawval
))
%
(
section
,
option
,
reference
,
rawval
))
InterpolationError
.
__init__
(
self
,
option
,
section
,
msg
)
InterpolationError
.
__init__
(
self
,
option
,
section
,
msg
)
self
.
reference
=
reference
self
.
reference
=
reference
self
.
_rawval
=
rawval
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
option
,
self
.
section
,
self
.
_rawval
,
self
.
reference
)
class
InterpolationSyntaxError
(
InterpolationError
):
class
InterpolationSyntaxError
(
InterpolationError
):
"""Raised when the source text into which substitutions are made
"""Raised when the source text into which substitutions are made
...
@@ -194,19 +214,28 @@ class InterpolationDepthError(InterpolationError):
...
@@ -194,19 +214,28 @@ class InterpolationDepthError(InterpolationError):
"
\
t
rawval : %s
\
n
"
"
\
t
rawval : %s
\
n
"
%
(
section
,
option
,
rawval
))
%
(
section
,
option
,
rawval
))
InterpolationError
.
__init__
(
self
,
option
,
section
,
msg
)
InterpolationError
.
__init__
(
self
,
option
,
section
,
msg
)
self
.
_rawval
=
rawval
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
option
,
self
.
section
,
self
.
_rawval
)
class
ParsingError
(
Error
):
class
ParsingError
(
Error
):
"""Raised when a configuration file does not follow legal syntax."""
"""Raised when a configuration file does not follow legal syntax."""
def
__init__
(
self
,
filename
):
def
__init__
(
self
,
filename
,
_errors
=
[]
):
Error
.
__init__
(
self
,
'File contains parsing errors: %s'
%
filename
)
Error
.
__init__
(
self
,
'File contains parsing errors: %s'
%
filename
)
self
.
filename
=
filename
self
.
filename
=
filename
self
.
errors
=
[]
self
.
errors
=
[]
for
lineno
,
line
in
_errors
:
self
.
append
(
lineno
,
line
)
def
append
(
self
,
lineno
,
line
):
def
append
(
self
,
lineno
,
line
):
self
.
errors
.
append
((
lineno
,
line
))
self
.
errors
.
append
((
lineno
,
line
))
self
.
message
+=
'
\
n
\
t
[line %2d]: %s'
%
(
lineno
,
line
)
self
.
message
+=
'
\
n
\
t
[line %2d]: %s'
%
(
lineno
,
line
)
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
filename
,
self
.
errors
)
class
MissingSectionHeaderError
(
ParsingError
):
class
MissingSectionHeaderError
(
ParsingError
):
"""Raised when a key-value pair is found before any section header."""
"""Raised when a key-value pair is found before any section header."""
...
@@ -219,6 +248,9 @@ class MissingSectionHeaderError(ParsingError):
...
@@ -219,6 +248,9 @@ class MissingSectionHeaderError(ParsingError):
self
.
lineno
=
lineno
self
.
lineno
=
lineno
self
.
line
=
line
self
.
line
=
line
def
__reduce__
(
self
):
return
self
.
__class__
,
(
self
.
filename
,
self
.
lineno
,
self
.
line
)
class
RawConfigParser
:
class
RawConfigParser
:
def
__init__
(
self
,
defaults
=
None
,
dict_type
=
_default_dict
,
def
__init__
(
self
,
defaults
=
None
,
dict_type
=
_default_dict
,
...
...
Lib/test/test_cfgparser.py
View file @
1d524608
...
@@ -604,6 +604,122 @@ class SortedTestCase(RawConfigParserTestCase):
...
@@ -604,6 +604,122 @@ class SortedTestCase(RawConfigParserTestCase):
"o4 = 1
\
n
\
n
"
)
"o4 = 1
\
n
\
n
"
)
class
ExceptionPicklingTestCase
(
unittest
.
TestCase
):
"""Tests for issue #13760: ConfigParser exceptions are not picklable."""
def
test_error
(
self
):
import
pickle
e1
=
ConfigParser
.
Error
(
'value'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_nosectionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
NoSectionError
(
'section'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_nooptionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
NoOptionError
(
'option'
,
'section'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_duplicatesectionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
DuplicateSectionError
(
'section'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationerror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationError
(
'option'
,
'section'
,
'msg'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationmissingoptionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationMissingOptionError
(
'option'
,
'section'
,
'rawval'
,
'reference'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
e1
.
reference
,
e2
.
reference
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationsyntaxerror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationSyntaxError
(
'option'
,
'section'
,
'msg'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationdeptherror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationDepthError
(
'option'
,
'section'
,
'rawval'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_parsingerror
(
self
):
import
pickle
e1
=
ConfigParser
.
ParsingError
(
'source'
)
e1
.
append
(
1
,
'line1'
)
e1
.
append
(
2
,
'line2'
)
e1
.
append
(
3
,
'line3'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
filename
,
e2
.
filename
)
self
.
assertEqual
(
e1
.
errors
,
e2
.
errors
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_missingsectionheadererror
(
self
):
import
pickle
e1
=
ConfigParser
.
MissingSectionHeaderError
(
'filename'
,
123
,
'line'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
line
,
e2
.
line
)
self
.
assertEqual
(
e1
.
filename
,
e2
.
filename
)
self
.
assertEqual
(
e1
.
lineno
,
e2
.
lineno
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_main
():
def
test_main
():
test_support
.
run_unittest
(
test_support
.
run_unittest
(
ConfigParserTestCase
,
ConfigParserTestCase
,
...
@@ -614,6 +730,7 @@ def test_main():
...
@@ -614,6 +730,7 @@ def test_main():
SortedTestCase
,
SortedTestCase
,
Issue7005TestCase
,
Issue7005TestCase
,
TestChainMap
,
TestChainMap
,
ExceptionPicklingTestCase
,
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment