diff -r 62d844d2bd07 Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst Fri May 13 21:19:22 2016 +0300 +++ b/Doc/library/zipfile.rst Sat May 14 23:44:54 2016 +0300 @@ -234,7 +234,7 @@ ZipFile Objects With ``mode='w'``, a writable file handle is returned, which supports the :meth:`~io.BufferedIOBase.write` method. While a writable file handle is open, attempting to read or write other files in the ZIP file will raise a - :exc:`RuntimeError`. + :exc:`ValueError`. When writing a file, if the file size is not known in advance but may exceed 2 GiB, pass ``force_zip64=True`` to ensure that the header format is diff -r 62d844d2bd07 Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py Fri May 13 21:19:22 2016 +0300 +++ b/Lib/test/test_zipfile.py Sat May 14 23:44:54 2016 +0300 @@ -1450,15 +1450,15 @@ class OtherTests(unittest.TestCase): with zipf.open('foo', mode='w') as w2: w2.write(msg1) with zipf.open('bar', mode='w') as w1: - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.open('handle', mode='w') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.open('foo', mode='r') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.writestr('str', 'abcde') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.write(__file__, 'file') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.close() w1.write(msg2) with zipf.open('baz', mode='w') as w2: diff -r 62d844d2bd07 Lib/zipfile.py --- a/Lib/zipfile.py Fri May 13 21:19:22 2016 +0300 +++ b/Lib/zipfile.py Sat May 14 23:44:54 2016 +0300 @@ -696,7 +696,7 @@ class _SharedFile: def read(self, n=-1): with self._lock: if self._writing(): - raise RuntimeError("Can't read from the ZIP file while there " + raise ValueError("Can't read from the ZIP file while there " "is an open writing handle on it. " "Close the writing handle before trying to read.") self._file.seek(self._pos) @@ -1388,7 +1388,7 @@ class ZipFile: return self._open_to_write(zinfo, force_zip64=force_zip64) if self._writing: - raise RuntimeError("Can't read from the ZIP file while there " + raise ValueError("Can't read from the ZIP file while there " "is an open writing handle on it. " "Close the writing handle before trying to read.") @@ -1467,9 +1467,9 @@ class ZipFile: "the ZIP file." ) if self._writing: - raise RuntimeError("Can't write to the ZIP file while there is " - "another write handle open on it. " - "Close the first handle before opening another.") + raise ValueError("Can't write to the ZIP file while there is " + "another write handle open on it. " + "Close the first handle before opening another.") # Sizes and CRC are overwritten with correct data after processing the file if not hasattr(zinfo, 'file_size'): @@ -1613,7 +1613,7 @@ class ZipFile: raise RuntimeError( "Attempt to write to ZIP archive that was already closed") if self._writing: - raise RuntimeError( + raise ValueError( "Can't write to ZIP archive while an open writing handle exists" ) @@ -1672,7 +1672,7 @@ class ZipFile: raise RuntimeError( "Attempt to write to ZIP archive that was already closed") if self._writing: - raise RuntimeError( + raise ValueError( "Can't write to ZIP archive while an open writing handle exists." ) @@ -1695,9 +1695,9 @@ class ZipFile: return if self._writing: - raise RuntimeError("Can't close the ZIP file while there is " - "an open writing handle on it. " - "Close the writing handle before closing the zip.") + raise ValueError("Can't close the ZIP file while there is " + "an open writing handle on it. " + "Close the writing handle before closing the zip.") try: if self.mode in ('w', 'x', 'a') and self._didModify: # write ending records