diff -r 6ea8b8671f73 Doc/library/fileinput.rst --- a/Doc/library/fileinput.rst Wed Aug 21 21:52:50 2013 +0300 +++ b/Doc/library/fileinput.rst Thu Aug 22 10:12:45 2013 +0300 @@ -143,7 +143,8 @@ sequential order; random access and :meth:`readline` cannot be mixed. With *mode* you can specify which file mode will be passed to :func:`open`. It - must be one of ``'r'``, ``'rU'``, ``'U'`` and ``'rb'``. + must be one of ``'r'``, ``'rU'``, ``'U'`` and ``'rb'``. ``'rU'`` and ``'U'`` + modes are deprecated, unneeded in new code and will not be used in new code. The *openhook*, when given, must be a function that takes two arguments, *filename* and *mode*, and returns an accordingly opened file-like object. You diff -r 6ea8b8671f73 Doc/library/functions.rst --- a/Doc/library/functions.rst Wed Aug 21 21:52:50 2013 +0300 +++ b/Doc/library/functions.rst Thu Aug 22 10:12:45 2013 +0300 @@ -872,7 +872,7 @@ ``'b'`` binary mode ``'t'`` text mode (default) ``'+'`` open a disk file for updating (reading and writing) - ``'U'`` universal newlines mode (for backwards compatibility; should + ``'U'`` universal newlines mode (deprecated; unneeded in new code; should not be used in new code) ========= =============================================================== diff -r 6ea8b8671f73 Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst Wed Aug 21 21:52:50 2013 +0300 +++ b/Doc/library/zipfile.rst Thu Aug 22 10:12:45 2013 +0300 @@ -206,9 +206,10 @@ is the name of the file in the archive, or a :class:`ZipInfo` object. The *mode* parameter, if included, must be one of the following: ``'r'`` (the default), ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable - :term:`universal newlines` support in the read-only object. *pwd* is the - password used for encrypted files. Calling :meth:`.open` on a closed - ZipFile will raise a :exc:`RuntimeError`. + :term:`universal newlines` support in the read-only object (deprecated; + should not be used in new code; use :class:`io.TextWrapper` for reading + compressed text files). *pwd* is the password used for encrypted files. + Calling :meth:`.open` on a closed ZipFile will raise a :exc:`RuntimeError`. .. note:: diff -r 6ea8b8671f73 Lib/_pyio.py --- a/Lib/_pyio.py Wed Aug 21 21:52:50 2013 +0300 +++ b/Lib/_pyio.py Thu Aug 22 10:12:45 2013 +0300 @@ -62,8 +62,8 @@ 'b' binary mode 't' text mode (default) '+' open a disk file for updating (reading and writing) - 'U' universal newline mode (for backwards compatibility; unneeded - for new code) + 'U' universal newline mode (deprecated; unneeded for new code; should + not be used in new code) ========= =============================================================== The default mode is 'rt' (open for reading text). For binary random @@ -172,6 +172,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 6ea8b8671f73 Lib/fileinput.py --- a/Lib/fileinput.py Wed Aug 21 21:52:50 2013 +0300 +++ b/Lib/fileinput.py Thu Aug 22 10:12:45 2013 +0300 @@ -222,6 +222,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 6ea8b8671f73 Lib/imp.py --- a/Lib/imp.py Wed Aug 21 21:52:50 2013 +0300 +++ b/Lib/imp.py Thu Aug 22 10:12:45 2013 +0300 @@ -103,7 +103,7 @@ def get_suffixes(): """**DEPRECATED**""" extensions = [(s, 'rb', C_EXTENSION) for s in machinery.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 @@ -274,7 +274,7 @@ raise ImportError(_ERR_MSG.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 6ea8b8671f73 Lib/zipfile.py --- a/Lib/zipfile.py Wed Aug 21 21:52:50 2013 +0300 +++ b/Lib/zipfile.py Thu Aug 22 10:12:45 2013 +0300 @@ -1108,8 +1108,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 6ea8b8671f73 Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c Wed Aug 21 21:52:50 2013 +0300 +++ b/Modules/_io/_iomodule.c Thu Aug 22 10:12:45 2013 +0300 @@ -126,8 +126,8 @@ "'b' binary mode\n" "'t' text mode (default)\n" "'+' open a disk file for updating (reading and writing)\n" -"'U' universal newline mode (for backwards compatibility; unneeded\n" -" for new code)\n" +"'U' universal newline mode (deprecated; unneeded for new code; should\n" +" not be used in new code)\n" "========= ===============================================================\n" "\n" "The default mode is 'rt' (open for reading text). For binary random\n" @@ -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 6ea8b8671f73 Tools/iobench/iobench.py --- a/Tools/iobench/iobench.py Wed Aug 21 21:52:50 2013 +0300 +++ b/Tools/iobench/iobench.py Thu Aug 22 10:12:45 2013 +0300 @@ -7,6 +7,7 @@ import re import sys import time +import io from optparse import OptionParser out = sys.stdout @@ -24,6 +25,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(): @@ -380,7 +383,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 6ea8b8671f73 Tools/scripts/diff.py --- a/Tools/scripts/diff.py Wed Aug 21 21:52:50 2013 +0300 +++ b/Tools/scripts/diff.py Thu Aug 22 10:12:45 2013 +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 6ea8b8671f73 Tools/scripts/ndiff.py --- a/Tools/scripts/ndiff.py Wed Aug 21 21:52:50 2013 +0300 +++ b/Tools/scripts/ndiff.py Thu Aug 22 10:12:45 2013 +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))