diff -r d0f775432705 Lib/_pyio.py --- a/Lib/_pyio.py Thu Jun 28 01:45:48 2012 +0200 +++ b/Lib/_pyio.py Thu Jun 28 12:21:26 2012 +0300 @@ -173,6 +173,8 @@ if "U" in modes: if creating or writing or appending: raise ValueError("can't use U and writing mode at once") + warnings.warn("Use of 'U' mode is deprecated", + DeprecationWarning) reading = True if text and binary: raise ValueError("can't have text and binary mode at once") diff -r d0f775432705 Lib/fileinput.py --- a/Lib/fileinput.py Thu Jun 28 01:45:48 2012 +0200 +++ b/Lib/fileinput.py Thu Jun 28 12:21:26 2012 +0300 @@ -224,6 +224,9 @@ if mode not in ('r', 'rU', 'U', 'rb'): raise ValueError("FileInput opening mode must be one of " "'r', 'rU', 'U' and 'rb'") + if 'U' in mode: + warnings.warn("Use of 'U' mode is deprecated", + DeprecationWarning) self._mode = mode if openhook: if inplace: diff -r d0f775432705 Lib/imp.py --- a/Lib/imp.py Thu Jun 28 01:45:48 2012 +0200 +++ b/Lib/imp.py Thu Jun 28 12:21:26 2012 +0300 @@ -42,7 +42,7 @@ 'defined on importlib.machinery instead', DeprecationWarning, 2) extensions = [(s, 'rb', C_EXTENSION) for s in extension_suffixes()] - source = [(s, 'U', PY_SOURCE) for s in machinery.SOURCE_SUFFIXES] + source = [(s, 'r', PY_SOURCE) for s in machinery.SOURCE_SUFFIXES] bytecode = [(s, 'rb', PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES] return extensions + source + bytecode @@ -228,7 +228,7 @@ raise ImportError('No module name {!r}'.format(name), name=name) encoding = None - if mode == 'U': + if 'b' not in mode: with open(file_path, 'rb') as file: encoding = tokenize.detect_encoding(file.readline)[0] file = open(file_path, mode, encoding=encoding) diff -r d0f775432705 Lib/zipfile.py --- a/Lib/zipfile.py Thu Jun 28 01:45:48 2012 +0200 +++ b/Lib/zipfile.py Thu Jun 28 12:21:26 2012 +0300 @@ -1098,8 +1098,11 @@ def open(self, name, mode="r", pwd=None): """Return file-like object for 'name'.""" + if 'U' in mode: + warnings.warn("Use of 'U' mode is deprecated", + DeprecationWarning) if mode not in ("r", "U", "rU"): - raise RuntimeError('open() requires mode "r", "U", or "rU"') + raise RuntimeError('open() requires mode "r"') if pwd and not isinstance(pwd, bytes): raise TypeError("pwd: expected bytes, got %s" % type(pwd)) if not self.fp: diff -r d0f775432705 Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c Thu Jun 28 01:45:48 2012 +0200 +++ b/Modules/_io/_iomodule.c Thu Jun 28 12:21:26 2012 +0300 @@ -310,6 +310,9 @@ "can't use U and writing mode at once"); return NULL; } + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Use of 'U' mode is deprecated", 1) < 0) + return NULL; reading = 1; } diff -r d0f775432705 Tools/iobench/iobench.py --- a/Tools/iobench/iobench.py Thu Jun 28 01:45:48 2012 +0200 +++ b/Tools/iobench/iobench.py Thu Jun 28 12:21:26 2012 +0300 @@ -9,6 +9,7 @@ import re import sys import time +import io from optparse import OptionParser out = sys.stdout @@ -26,6 +27,8 @@ try: return open(fn, mode, encoding=encoding or TEXT_ENCODING) except TypeError: + if 'r' in mode: + mode += 'U' return open(fn, mode) def get_file_sizes(): @@ -382,7 +385,7 @@ f.write(os.urandom(size)) # Text files chunk = [] - with text_open(__file__, "rU", encoding='utf8') as f: + with text_open(__file__, "r", encoding='utf8') as f: for line in f: if line.startswith("# "): break diff -r d0f775432705 Tools/scripts/diff.py --- a/Tools/scripts/diff.py Thu Jun 28 01:45:48 2012 +0200 +++ b/Tools/scripts/diff.py Thu Jun 28 12:21:26 2012 +0300 @@ -38,9 +38,9 @@ fromdate = file_mtime(fromfile) todate = file_mtime(tofile) - with open(fromfile, 'U') as ff: + with open(fromfile, 'r') as ff: fromlines = ff.readlines() - with open(tofile, 'U') as tf: + with open(tofile, 'r') as tf: tolines = tf.readlines() if options.u: diff -r d0f775432705 Tools/scripts/ndiff.py --- a/Tools/scripts/ndiff.py Thu Jun 28 01:45:48 2012 +0200 +++ b/Tools/scripts/ndiff.py Thu Jun 28 12:21:26 2012 +0300 @@ -60,7 +60,7 @@ # couldn't be opened def fopen(fname): try: - return open(fname, 'U') + return open(fname, 'r') except IOError as detail: return fail("couldn't open " + fname + ": " + str(detail))