summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-31 17:21:00 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-31 17:21:00 (GMT)
commitc7797dc7482035ee166ca2e941b623382b92e1fc (patch)
tree526e26fa4dac506f02859fdbe946d33ed4165f5e /Lib/_pyio.py
parentcfb7028df4bdf12325786e48ebef3b4982efa119 (diff)
downloadcpython-c7797dc7482035ee166ca2e941b623382b92e1fc.zip
cpython-c7797dc7482035ee166ca2e941b623382b92e1fc.tar.gz
cpython-c7797dc7482035ee166ca2e941b623382b92e1fc.tar.bz2
Issue #19543: Emit deprecation warning for known non-text encodings.
Backported issues #19619: encode() and decode() methods and constructors of str, unicode and bytearray classes now emit deprecation warning for known non-text encodings when Python is ran with the -3 option. Backported issues #20404: io.TextIOWrapper (and hence io.open()) now uses the internal codec marking system added to emit deprecation warning for known non-text encodings at stream construction time when Python is ran with the -3 option.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index a7f4301..694b778 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -7,6 +7,7 @@ from __future__ import (print_function, unicode_literals)
import os
import abc
import codecs
+import sys
import warnings
import errno
# Import thread instead of threading to reduce startup cost
@@ -1497,6 +1498,11 @@ class TextIOWrapper(TextIOBase):
if not isinstance(encoding, basestring):
raise ValueError("invalid encoding: %r" % encoding)
+ if sys.py3kwarning and not codecs.lookup(encoding)._is_text_encoding:
+ msg = ("%r is not a text encoding; "
+ "use codecs.open() to handle arbitrary codecs")
+ warnings.warnpy3k(msg % encoding, stacklevel=2)
+
if errors is None:
errors = "strict"
else: