Index: Lib/zipfile.py =================================================================== --- Lib/zipfile.py (révision 68576) +++ Lib/zipfile.py (copie de travail) @@ -841,7 +841,12 @@ def setpassword(self, pwd): """Set default password for encrypted files.""" - self.pwd = pwd + if pwd and not isinstance(pwd, str): + raise TypeError("string expected for the password, not %s" % type(pwd)) + if pwd: + self.pwd = pwd + else: + self.pwd = None def read(self, name, pwd=None): """Return file bytes (as a string) for name.""" @@ -851,6 +856,8 @@ """Return file-like object for 'name'.""" if mode not in ("r", "U", "rU"): raise RuntimeError, 'open() requires mode "r", "U", or "rU"' + if pwd and not isinstance(pwd, str): + raise TypeError("string expected for the password, not %s" % type(pwd)) if not self.fp: raise RuntimeError, \ "Attempt to read ZIP archive that was already closed" @@ -955,6 +962,9 @@ """Extract the ZipInfo object 'member' to a physical file on the path targetpath. """ + if pwd and not isinstance(pwd, str): + raise TypeError("string expected for the password, not %s" % type(pwd)) + # build the destination pathname, replacing # forward slashes to platform specific separators. if targetpath[-1:] == "/": Index: Lib/test/test_zipfile.py =================================================================== --- Lib/test/test_zipfile.py (révision 68576) +++ Lib/test/test_zipfile.py (copie de travail) @@ -866,6 +866,11 @@ self.zip2.setpassword("12345") self.assertEquals(self.zip2.read("zero"), self.plain2) + def test_unicode_password(self): + self.assertRaises(TypeError, self.zip.setpassword, u"unicode") + self.assertRaises(TypeError, self.zip.read, "test.txt", u"python") + self.assertRaises(TypeError, self.zip.open, "test.txt", pwd=u"python") + self.assertRaises(TypeError, self.zip.extract, "test.txt", pwd=u"python") class TestsWithRandomBinaryFiles(unittest.TestCase): def setUp(self):