diff options
author | Hugo van Kemenade <hugovk@users.noreply.github.com> | 2023-05-26 06:06:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-26 06:06:32 (GMT) |
commit | 3f9c60f51ef820937e7e0f95f45e63fa0ae21e6c (patch) | |
tree | e3faa330550df992beeb418bb9ba95f472e4ef1c /Lib/configparser.py | |
parent | 0242e9a57aa87ed0b5cac526f65631c654a39054 (diff) | |
download | cpython-3f9c60f51ef820937e7e0f95f45e63fa0ae21e6c.zip cpython-3f9c60f51ef820937e7e0f95f45e63fa0ae21e6c.tar.gz cpython-3f9c60f51ef820937e7e0f95f45e63fa0ae21e6c.tar.bz2 |
gh-104886: Remove deprecated configparser.LegacyInterpolation (#104887)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r-- | Lib/configparser.py | 49 |
1 files changed, 1 insertions, 48 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py index dee5a0d..9640f71 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -155,7 +155,7 @@ __all__ = ("NoSectionError", "DuplicateOptionError", "DuplicateSectionError", "ParsingError", "MissingSectionHeaderError", "ConfigParser", "RawConfigParser", "Interpolation", "BasicInterpolation", "ExtendedInterpolation", - "LegacyInterpolation", "SectionProxy", "ConverterMapping", + "SectionProxy", "ConverterMapping", "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH") _default_dict = dict @@ -491,53 +491,6 @@ class ExtendedInterpolation(Interpolation): "found: %r" % (rest,)) -class LegacyInterpolation(Interpolation): - """Deprecated interpolation used in old versions of ConfigParser. - Use BasicInterpolation or ExtendedInterpolation instead.""" - - _KEYCRE = re.compile(r"%\(([^)]*)\)s|.") - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - warnings.warn( - "LegacyInterpolation has been deprecated since Python 3.2 " - "and will be removed from the configparser module in Python 3.13. " - "Use BasicInterpolation or ExtendedInterpolation instead.", - DeprecationWarning, stacklevel=2 - ) - - def before_get(self, parser, section, option, value, vars): - rawval = value - depth = MAX_INTERPOLATION_DEPTH - while depth: # Loop through this until it's done - depth -= 1 - if value and "%(" in value: - replace = functools.partial(self._interpolation_replace, - parser=parser) - value = self._KEYCRE.sub(replace, value) - try: - value = value % vars - except KeyError as e: - raise InterpolationMissingOptionError( - option, section, rawval, e.args[0]) from None - else: - break - if value and "%(" in value: - raise InterpolationDepthError(option, section, rawval) - return value - - def before_set(self, parser, section, option, value): - return value - - @staticmethod - def _interpolation_replace(match, parser): - s = match.group(1) - if s is None: - return match.group() - else: - return "%%(%s)s" % parser.optionxform(s) - - class RawConfigParser(MutableMapping): """ConfigParser that does not do interpolation.""" |