Merged revisions 87430 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r87430 | r.david.murray | 2010-12-21 16:53:37 -0500 (Tue, 21 Dec 2010) | 9 lines
#4871: check that zipfile password is bytes, and give useful error message.
Previously passing a string in as the password would fail either with
an assertion error or a TypeError with a confusing error message.
Note that a string can't be accepted since zipfile has no way to
guess what encoding should be used to turn it into bytes.
Patch by Victor Stinner.
........
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 26bc47b..c989bf0 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -991,6 +991,12 @@
self.zip2.setpassword(b"12345")
self.assertEqual(self.zip2.read("zero"), self.plain2)
+ def test_unicode_password(self):
+ self.assertRaises(TypeError, self.zip.setpassword, "unicode")
+ self.assertRaises(TypeError, self.zip.read, "test.txt", "python")
+ self.assertRaises(TypeError, self.zip.open, "test.txt", pwd="python")
+ self.assertRaises(TypeError, self.zip.extract, "test.txt", pwd="python")
+
class TestsWithRandomBinaryFiles(unittest.TestCase):
def setUp(self):