mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.14] gh-65697: Improved error msg for configparser key validation (GH-135527) (#135541)
gh-65697: Improved error msg for configparser key validation (GH-135527)
* Improved error msg for configparser key validation and added note in 3.14 whatsnew
* Properly added change to configparser
* 📜🤖 Added by blurb_it.
---------
(cherry picked from commit 81237fbcf6
)
Co-authored-by: Jacob Austin Lincoln <99031153+lincolnj1@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
ee141f0277
commit
6ae54553d4
3 changed files with 16 additions and 4 deletions
|
@ -1218,11 +1218,14 @@ class RawConfigParser(MutableMapping):
|
|||
|
||||
def _validate_key_contents(self, key):
|
||||
"""Raises an InvalidWriteError for any keys containing
|
||||
delimiters or that match the section header pattern"""
|
||||
delimiters or that begins with the section header pattern"""
|
||||
if re.match(self.SECTCRE, key):
|
||||
raise InvalidWriteError("Cannot write keys matching section pattern")
|
||||
if any(delim in key for delim in self._delimiters):
|
||||
raise InvalidWriteError("Cannot write key that contains delimiters")
|
||||
raise InvalidWriteError(
|
||||
f"Cannot write key {key}; begins with section pattern")
|
||||
for delim in self._delimiters:
|
||||
if delim in key:
|
||||
raise InvalidWriteError(
|
||||
f"Cannot write key {key}; contains delimiter {delim}")
|
||||
|
||||
def _validate_value_types(self, *, section="", option="", value=""):
|
||||
"""Raises a TypeError for illegal non-string values.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue