Skip to content

Commit defc3ac

Browse files
committed
Update configparser.py from CPython v3.12.0
1 parent 97a0705 commit defc3ac

File tree

1 file changed

+6
-57
lines changed

1 file changed

+6
-57
lines changed

Lib/configparser.py

+6-57
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
instance. It will be used as the handler for option value
6060
pre-processing when using getters. RawConfigParser objects don't do
6161
any sort of interpolation, whereas ConfigParser uses an instance of
62-
BasicInterpolation. The library also provides a ``zc.buildbot``
62+
BasicInterpolation. The library also provides a ``zc.buildout``
6363
inspired ExtendedInterpolation implementation.
6464
6565
When `converters` is given, it should be a dictionary where each key
@@ -149,14 +149,14 @@
149149
import sys
150150
import warnings
151151

152-
__all__ = ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
152+
__all__ = ("NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
153153
"NoOptionError", "InterpolationError", "InterpolationDepthError",
154154
"InterpolationMissingOptionError", "InterpolationSyntaxError",
155155
"ParsingError", "MissingSectionHeaderError",
156-
"ConfigParser", "SafeConfigParser", "RawConfigParser",
156+
"ConfigParser", "RawConfigParser",
157157
"Interpolation", "BasicInterpolation", "ExtendedInterpolation",
158158
"LegacyInterpolation", "SectionProxy", "ConverterMapping",
159-
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
159+
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH")
160160

161161
_default_dict = dict
162162
DEFAULTSECT = "DEFAULT"
@@ -298,41 +298,12 @@ def __init__(self, option, section, rawval):
298298
class ParsingError(Error):
299299
"""Raised when a configuration file does not follow legal syntax."""
300300

301-
def __init__(self, source=None, filename=None):
302-
# Exactly one of `source'/`filename' arguments has to be given.
303-
# `filename' kept for compatibility.
304-
if filename and source:
305-
raise ValueError("Cannot specify both `filename' and `source'. "
306-
"Use `source'.")
307-
elif not filename and not source:
308-
raise ValueError("Required argument `source' not given.")
309-
elif filename:
310-
source = filename
311-
Error.__init__(self, 'Source contains parsing errors: %r' % source)
301+
def __init__(self, source):
302+
super().__init__(f'Source contains parsing errors: {source!r}')
312303
self.source = source
313304
self.errors = []
314305
self.args = (source, )
315306

316-
@property
317-
def filename(self):
318-
"""Deprecated, use `source'."""
319-
warnings.warn(
320-
"The 'filename' attribute will be removed in Python 3.12. "
321-
"Use 'source' instead.",
322-
DeprecationWarning, stacklevel=2
323-
)
324-
return self.source
325-
326-
@filename.setter
327-
def filename(self, value):
328-
"""Deprecated, user `source'."""
329-
warnings.warn(
330-
"The 'filename' attribute will be removed in Python 3.12. "
331-
"Use 'source' instead.",
332-
DeprecationWarning, stacklevel=2
333-
)
334-
self.source = value
335-
336307
def append(self, lineno, line):
337308
self.errors.append((lineno, line))
338309
self.message += '\n\t[line %2d]: %s' % (lineno, line)
@@ -769,15 +740,6 @@ def read_dict(self, dictionary, source='<dict>'):
769740
elements_added.add((section, key))
770741
self.set(section, key, value)
771742

772-
def readfp(self, fp, filename=None):
773-
"""Deprecated, use read_file instead."""
774-
warnings.warn(
775-
"This method will be removed in Python 3.12. "
776-
"Use 'parser.read_file()' instead.",
777-
DeprecationWarning, stacklevel=2
778-
)
779-
self.read_file(fp, source=filename)
780-
781743
def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
782744
"""Get an option value for a given section.
783745
@@ -1240,19 +1202,6 @@ def _read_defaults(self, defaults):
12401202
self._interpolation = hold_interpolation
12411203

12421204

1243-
class SafeConfigParser(ConfigParser):
1244-
"""ConfigParser alias for backwards compatibility purposes."""
1245-
1246-
def __init__(self, *args, **kwargs):
1247-
super().__init__(*args, **kwargs)
1248-
warnings.warn(
1249-
"The SafeConfigParser class has been renamed to ConfigParser "
1250-
"in Python 3.2. This alias will be removed in Python 3.12."
1251-
" Use ConfigParser directly instead.",
1252-
DeprecationWarning, stacklevel=2
1253-
)
1254-
1255-
12561205
class SectionProxy(MutableMapping):
12571206
"""A proxy for a single section from a parser."""
12581207

0 commit comments

Comments
 (0)