mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-37330: open() no longer accept 'U' in file mode (GH-28118)
open(), io.open(), codecs.open() and fileinput.FileInput no longer accept "U" ("universal newline") in the file mode. This flag was deprecated since Python 3.3.
This commit is contained in:
parent
a806608705
commit
19ba2122ac
13 changed files with 61 additions and 104 deletions
|
@ -714,11 +714,23 @@ class UTF16Test(ReadTest, unittest.TestCase):
|
|||
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
|
||||
with open(os_helper.TESTFN, 'wb') as fp:
|
||||
fp.write(s)
|
||||
with warnings_helper.check_warnings(('', DeprecationWarning)):
|
||||
reader = codecs.open(os_helper.TESTFN, 'U', encoding=self.encoding)
|
||||
with reader:
|
||||
with codecs.open(os_helper.TESTFN, 'r',
|
||||
encoding=self.encoding) as reader:
|
||||
self.assertEqual(reader.read(), s1)
|
||||
|
||||
def test_invalid_modes(self):
|
||||
for mode in ('U', 'rU', 'r+U'):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
codecs.open(os_helper.TESTFN, mode, encoding=self.encoding)
|
||||
self.assertIn('invalid mode', str(cm.exception))
|
||||
|
||||
for mode in ('rt', 'wt', 'at', 'r+t'):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
codecs.open(os_helper.TESTFN, mode, encoding=self.encoding)
|
||||
self.assertIn("can't have text and binary mode at once",
|
||||
str(cm.exception))
|
||||
|
||||
|
||||
class UTF16LETest(ReadTest, unittest.TestCase):
|
||||
encoding = "utf-16-le"
|
||||
ill_formed_sequence = b"\x80\xdc"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue