@@ -71,6 +71,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
7171 'b' binary mode
7272 't' text mode (default)
7373 '+' open a disk file for updating (reading and writing)
74+ 'U' universal newline mode (deprecated)
7475 ========= ===============================================================
7576
7677 The default mode is 'rt' (open for reading text). For binary random
@@ -86,6 +87,10 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
8687 returned as strings, the bytes having been first decoded using a
8788 platform-dependent encoding or using the specified encoding if given.
8889
90+ 'U' mode is deprecated and will raise an exception in future versions
91+ of Python. It has no effect in Python 3. Use newline to control
92+ universal newlines mode.
93+
8994 buffering is an optional integer used to set the buffering policy.
9095 Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
9196 line buffering (only usable in text mode), and an integer > 1 to indicate
@@ -171,7 +176,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
171176 if errors is not None and not isinstance (errors , str ):
172177 raise TypeError ("invalid errors: %r" % errors )
173178 modes = set (mode )
174- if modes - set ("axrwb+t " ) or len (mode ) > len (modes ):
179+ if modes - set ("axrwb+tU " ) or len (mode ) > len (modes ):
175180 raise ValueError ("invalid mode: %r" % mode )
176181 creating = "x" in modes
177182 reading = "r" in modes
@@ -180,6 +185,13 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
180185 updating = "+" in modes
181186 text = "t" in modes
182187 binary = "b" in modes
188+ if "U" in modes :
189+ if creating or writing or appending or updating :
190+ raise ValueError ("mode U cannot be combined with 'x', 'w', 'a', or '+'" )
191+ import warnings
192+ warnings .warn ("'U' mode is deprecated" ,
193+ DeprecationWarning , 2 )
194+ reading = True
183195 if text and binary :
184196 raise ValueError ("can't have text and binary mode at once" )
185197 if creating + reading + writing + appending > 1 :
0 commit comments