diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/_pyio.py | 10 | ||||
| -rw-r--r-- | Lib/fileinput.py | 4 | ||||
| -rw-r--r-- | Lib/imp.py | 4 | ||||
| -rw-r--r-- | Lib/test/test_imp.py | 2 | ||||
| -rw-r--r-- | Lib/zipfile.py | 4 |
5 files changed, 19 insertions, 5 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 78c6dfb4cd..d6eee79e01 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -62,8 +62,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, '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 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, 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,9 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, if "U" in modes: if creating or writing or appending: raise ValueError("can't use U and writing mode at once") + import warnings + warnings.warn("'U' mode is deprecated", + DeprecationWarning, 2) reading = True if text and binary: raise ValueError("can't have text and binary mode at once") diff --git a/Lib/fileinput.py b/Lib/fileinput.py index 3215154e88..11ba82df87 100644 --- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -222,6 +222,10 @@ class FileInput: 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: + import warnings + warnings.warn("Use of 'U' mode is deprecated", + DeprecationWarning, 2) self._mode = mode if openhook: if inplace: diff --git a/Lib/imp.py b/Lib/imp.py index 1144cd1f64..c8449c6155 100644 --- a/Lib/imp.py +++ b/Lib/imp.py @@ -103,7 +103,7 @@ def source_from_cache(path): 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 @@ -297,7 +297,7 @@ def find_module(name, path=None): 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 --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index cf27a712d5..78f573407c 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -165,7 +165,7 @@ class ImportTests(unittest.TestCase): self.assertIsNotNone(file) self.assertTrue(filename[:-3].endswith(temp_mod_name)) self.assertEqual(info[0], '.py') - self.assertEqual(info[1], 'U') + self.assertEqual(info[1], 'r') self.assertEqual(info[2], imp.PY_SOURCE) mod = imp.load_module(temp_mod_name, file, filename, info) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index ae65b42f70..fad52a246d 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1117,6 +1117,10 @@ class ZipFile: """Return file-like object for 'name'.""" if mode not in ("r", "U", "rU"): raise RuntimeError('open() requires mode "r", "U", or "rU"') + if 'U' in mode: + import warnings + warnings.warn("'U' mode is deprecated", + DeprecationWarning, 2) if pwd and not isinstance(pwd, bytes): raise TypeError("pwd: expected bytes, got %s" % type(pwd)) if not self.fp: |
