- Issue #2091: error correctly on open() with mode 'U' and '+'

open() accepted a 'U' mode string containing '+', but 'U' can only be used with
'r'. Patch from Jeff Balogh and John O'Connor.
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 50ad9ff..33d8a3f 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -181,8 +181,8 @@
     text = "t" in modes
     binary = "b" in modes
     if "U" in modes:
-        if creating or writing or appending:
-            raise ValueError("can't use U and writing mode at once")
+        if creating or writing or appending or updating:
+            raise ValueError("mode U cannot be combined with 'x', 'w', 'a', or '+'")
         import warnings
         warnings.warn("'U' mode is deprecated",
                       DeprecationWarning, 2)
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index d54e976..94f189a 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -139,7 +139,7 @@
 
     def testModeStrings(self):
         # check invalid mode strings
-        for mode in ("", "aU", "wU+"):
+        for mode in ("", "aU", "wU+", "U+", "+U", "rU+"):
             try:
                 f = self.open(TESTFN, mode)
             except ValueError: