summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-12-21 21:53:37 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-12-21 21:53:37 (GMT)
commit8d855d83046dd8a55cd216e642470191e6eab55f (patch)
tree994b94cdb6b1bfda618c4754792ea0696da0fdbf /Lib/test/test_zipfile.py
parent7f8f41808b82b5e4812bc2e2d484a6fc8f02295c (diff)
downloadcpython-8d855d83046dd8a55cd216e642470191e6eab55f.zip
cpython-8d855d83046dd8a55cd216e642470191e6eab55f.tar.gz
cpython-8d855d83046dd8a55cd216e642470191e6eab55f.tar.bz2
#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.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index a0367e1..d90e771 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -1089,6 +1089,12 @@ class DecryptionTests(unittest.TestCase):
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):