|
163 | 163 | "MultilineContinuationError", "UnnamedSectionDisabledError", |
164 | 164 | "ConfigParser", "RawConfigParser", |
165 | 165 | "Interpolation", "BasicInterpolation", "ExtendedInterpolation", |
166 | | - "SectionProxy", "ConverterMapping", "InvalidInputError", |
| 166 | + "SectionProxy", "ConverterMapping", "InvalidWriteError", |
167 | 167 | "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH", "UNNAMED_SECTION") |
168 | 168 |
|
169 | 169 | _default_dict = dict |
@@ -375,8 +375,10 @@ class _UnnamedSection: |
375 | 375 | def __repr__(self): |
376 | 376 | return "<UNNAMED_SECTION>" |
377 | 377 |
|
378 | | -class InvalidInputError(Error): |
379 | | - """Raised when attempting to write a key which contains any delimiters""" |
| 378 | +class InvalidWriteError(Error): |
| 379 | + """Raised when attempting to write data that would cause file .ini corruption. |
| 380 | + ex: writing a key which begins with the section header pattern would |
| 381 | + read back as a new section """ |
380 | 382 |
|
381 | 383 | def __init__(self, msg=''): |
382 | 384 | Error.__init__(self, msg) |
@@ -1222,13 +1224,12 @@ def _convert_to_boolean(self, value): |
1222 | 1224 | return self.BOOLEAN_STATES[value.lower()] |
1223 | 1225 |
|
1224 | 1226 | def _validate_key_contents(self, key): |
1225 | | - """Raises an InvalidInputError for any keys containing |
| 1227 | + """Raises an InvalidWriteError for any keys containing |
1226 | 1228 | delimiters or that match the section header pattern""" |
1227 | 1229 | if re.match(self.SECTCRE, key): |
1228 | | - raise InvalidInputError("Cannot write keys matching section pattern") |
1229 | | - for delim in self._delimiters: |
1230 | | - if delim in key: |
1231 | | - raise InvalidInputError("Cannot write key that contains delimiters") |
| 1230 | + raise InvalidWriteError("Cannot write keys matching section pattern") |
| 1231 | + if any(delim in key for delim in self._delimiters): |
| 1232 | + raise InvalidWriteError("Cannot write key that contains delimiters") |
1232 | 1233 |
|
1233 | 1234 | def _validate_value_types(self, *, section="", option="", value=""): |
1234 | 1235 | """Raises a TypeError for illegal non-string values. |
|
0 commit comments