diff -r 130597102dac Doc/library/fileinput.rst --- a/Doc/library/fileinput.rst Tue Nov 19 15:56:05 2013 +0200 +++ b/Doc/library/fileinput.rst Tue Nov 19 23:58:07 2013 +0200 @@ -144,7 +144,9 @@ and :meth:`~io.TextIOBase.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 and will raise an exception in future versions of + Python. :term:`Universal newlines` mode is always enabled in text mode. The *openhook*, when given, must be a function that takes two arguments, *filename* and *mode*, and returns an accordingly opened file-like object. You @@ -160,6 +162,9 @@ .. versionchanged:: 3.2 Can be used as a context manager. + .. versionchanged:: 3.4 + ``'rU'`` and ``'U'`` modes are deprecated. + **Optional in-place filtering:** if the keyword argument ``inplace=True`` is passed to :func:`fileinput.input` or to the :class:`FileInput` constructor, the diff -r 130597102dac Doc/library/functions.rst --- a/Doc/library/functions.rst Tue Nov 19 15:56:05 2013 +0200 +++ b/Doc/library/functions.rst Tue Nov 19 23:58:07 2013 +0200 @@ -872,8 +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 - not be used in new code) + ``'U'`` :term:`universal newlines` mode (deprecated) ========= =============================================================== The default mode is ``'r'`` (open for reading text, synonym of ``'rt'``). @@ -894,6 +893,10 @@ files; all the processing is done by Python itself, and is therefore platform-independent. + ```'U'``` mode is deprecated and will raise an exception in future versions + of Python. It has no effect in Python 3. Use *newline* to control + :term:`universal newlines` mode. + *buffering* is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size @@ -1029,6 +1032,9 @@ .. versionchanged:: 3.4 The file is now non-inheritable. + .. versionchanged:: 3.4 + ``'U'`` mode is deprecated. + .. XXX works for bytes too, but should it? .. function:: ord(c) diff -r 130597102dac Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst Tue Nov 19 15:56:05 2013 +0200 +++ b/Doc/library/zipfile.rst Tue Nov 19 23:58:07 2013 +0200 @@ -206,8 +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 + :term:`universal newlines` support in the read-only object. These modes + are deprecated and will raise an exception in future versions of Python. + Use :class:`io.TextIOWrapper` 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 130597102dac Lib/_pyio.py --- a/Lib/_pyio.py Tue Nov 19 15:56:05 2013 +0200 +++ b/Lib/_pyio.py Tue Nov 19 23:58:07 2013 +0200 @@ -62,8 +62,7 @@ '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) ========= =============================================================== The default mode is 'rt' (open for reading text). For binary random @@ -79,6 +78,10 @@ returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given. + 'U' mode is deprecated and will raise an exception in future versions + of Python. It has no effect in Python 3. Use newline to control + universal newlines mode. + buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate @@ -174,6 +177,8 @@ if "U" in modes: if creating or writing or appending: raise ValueError("can't use U and writing mode at once") + warnings.warn("'U' mode is deprecated", + DeprecationWarning) reading = True if text and binary: raise ValueError("can't have text and binary mode at once") diff -r 130597102dac Lib/fileinput.py --- a/Lib/fileinput.py Tue Nov 19 15:56:05 2013 +0200 +++ b/Lib/fileinput.py Tue Nov 19 23:58:07 2013 +0200 @@ -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 130597102dac Lib/imp.py --- a/Lib/imp.py Tue Nov 19 15:56:05 2013 +0200 +++ b/Lib/imp.py Tue Nov 19 23:58:07 2013 +0200 @@ -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 @@ -279,7 +279,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 130597102dac Lib/zipfile.py --- a/Lib/zipfile.py Tue Nov 19 15:56:05 2013 +0200 +++ b/Lib/zipfile.py Tue Nov 19 23:58:07 2013 +0200 @@ -1116,7 +1116,10 @@ def open(self, name, mode="r", pwd=None): """Return file-like object for 'name'.""" if mode not in ("r", "U", "rU"): - raise RuntimeError('open() requires mode "r", "U", or "rU"') + raise RuntimeError('open() requires mode "r"') + if 'U' in mode: + warnings.warn("'U' mode is deprecated", + DeprecationWarning) if pwd and not isinstance(pwd, bytes): raise TypeError("pwd: expected bytes, got %s" % type(pwd)) if not self.fp: diff -r 130597102dac Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c Tue Nov 19 15:56:05 2013 +0200 +++ b/Modules/_io/_iomodule.c Tue Nov 19 23:58:07 2013 +0200 @@ -126,8 +126,7 @@ "'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)\n" "========= ===============================================================\n" "\n" "The default mode is 'rt' (open for reading text). For binary random\n" @@ -143,6 +142,10 @@ "returned as strings, the bytes having been first decoded using a\n" "platform-dependent encoding or using the specified encoding if given.\n" "\n" +"'U' mode is deprecated and will raise an exception in future versions\n" +"of Python. It has no effect in Python 3. Use newline to control\n" +"universal newlines mode.\n" +"\n" "buffering is an optional integer used to set the buffering policy.\n" "Pass 0 to switch buffering off (only allowed in binary mode), 1 to select\n" "line buffering (only usable in text mode), and an integer > 1 to indicate\n" @@ -310,6 +313,9 @@ "can't use U and writing mode at once"); return NULL; } + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'U' mode is deprecated", 1) < 0) + return NULL; reading = 1; } diff -r 130597102dac Tools/iobench/iobench.py --- a/Tools/iobench/iobench.py Tue Nov 19 15:56:05 2013 +0200 +++ b/Tools/iobench/iobench.py Tue Nov 19 23:58:07 2013 +0200 @@ -24,6 +24,8 @@ try: return open(fn, mode, encoding=encoding or TEXT_ENCODING) except TypeError: + if 'r' in mode: + mode += 'U' # 'U' mode is needed only in Python 2.x return open(fn, mode) def get_file_sizes(): @@ -380,7 +382,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 130597102dac Tools/scripts/diff.py --- a/Tools/scripts/diff.py Tue Nov 19 15:56:05 2013 +0200 +++ b/Tools/scripts/diff.py Tue Nov 19 23:58:07 2013 +0200 @@ -38,9 +38,9 @@ fromdate = file_mtime(fromfile) todate = file_mtime(tofile) - with open(fromfile, 'U') as ff: + with open(fromfile) as ff: fromlines = ff.readlines() - with open(tofile, 'U') as tf: + with open(tofile) as tf: tolines = tf.readlines() if options.u: diff -r 130597102dac Tools/scripts/ndiff.py --- a/Tools/scripts/ndiff.py Tue Nov 19 15:56:05 2013 +0200 +++ b/Tools/scripts/ndiff.py Tue Nov 19 23:58:07 2013 +0200 @@ -60,7 +60,7 @@ # couldn't be opened def fopen(fname): try: - return open(fname, 'U') + return open(fname) except IOError as detail: return fail("couldn't open " + fname + ": " + str(detail))