mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Close #20404: blacklist non-text encodings in io.TextIOWrapper
- io.TextIOWrapper (and hence the open() builtin) now use the internal codec marking system added for issue #19619 - also tweaked the C code to only look up the encoding once, rather than multiple times - the existing output type checks remain in place to deal with unmarked third party codecs.
This commit is contained in:
parent
1ea4e4174b
commit
a9b15241c6
6 changed files with 141 additions and 41 deletions
|
@ -1503,6 +1503,11 @@ class TextIOWrapper(TextIOBase):
|
|||
if not isinstance(encoding, str):
|
||||
raise ValueError("invalid encoding: %r" % encoding)
|
||||
|
||||
if not codecs.lookup(encoding)._is_text_encoding:
|
||||
msg = ("%r is not a text encoding; "
|
||||
"use codecs.open() to handle arbitrary codecs")
|
||||
raise LookupError(msg % encoding)
|
||||
|
||||
if errors is None:
|
||||
errors = "strict"
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue