diff -r 60163fc72017 Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py Mon Jan 13 13:51:42 2014 -0500 +++ b/Lib/test/test_zipfile.py Tue Jan 14 21:05:27 2014 +0200 @@ -646,7 +646,7 @@ self.assertTrue('SyntaxError' not in reportStr) # then check that the filter works on individual files - with captured_stdout() as reportSIO: + with captured_stdout() as reportSIO, self.assertWarns(UserWarning): zipfp.writepy(packagedir, filterfunc=lambda fn: 'bad' not in fn) reportStr = reportSIO.getvalue() @@ -896,7 +896,9 @@ # Create the ZIP archive with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: zipfp.writestr("name", "foo") - zipfp.writestr("name", "bar") + with self.assertWarns(UserWarning): + zipfp.writestr("name", "bar") + self.assertEqual(zipfp.namelist(), ["name"] * 2) with zipfile.ZipFile(TESTFN2, "r") as zipfp: infos = zipfp.infolist() @@ -1213,7 +1215,8 @@ # check a comment that is too long is truncated with zipfile.ZipFile(TESTFN, mode="w") as zipf: - zipf.comment = comment2 + b'oops' + with self.assertWarns(UserWarning): + zipf.comment = comment2 + b'oops' zipf.writestr("foo.txt", "O, for a Muse of Fire!") with zipfile.ZipFile(TESTFN, mode="r") as zipfr: self.assertEqual(zipfr.comment, comment2) diff -r 60163fc72017 Lib/zipfile.py --- a/Lib/zipfile.py Mon Jan 13 13:51:42 2014 -0500 +++ b/Lib/zipfile.py Tue Jan 14 21:05:27 2014 +0200 @@ -1104,10 +1104,10 @@ if not isinstance(comment, bytes): raise TypeError("comment: expected bytes, got %s" % type(comment)) # check for valid comment length - if len(comment) >= ZIP_MAX_COMMENT: - if self.debug: - print('Archive comment is too long; truncating to %d bytes' - % ZIP_MAX_COMMENT) + if len(comment) > ZIP_MAX_COMMENT: + import warnings + warnings.warn('Archive comment is too long; truncating to %d bytes' + % ZIP_MAX_COMMENT, stacklevel=2) comment = comment[:ZIP_MAX_COMMENT] self._comment = comment self._didModify = True @@ -1296,8 +1296,8 @@ def _writecheck(self, zinfo): """Check for errors before writing a file to the archive.""" if zinfo.filename in self.NameToInfo: - if self.debug: # Warning for duplicate names - print("Duplicate name:", zinfo.filename) + import warnings + warnings.warn('Duplicate name: %r' % zinfo.filename, stacklevel=3) if self.mode not in ("w", "a"): raise RuntimeError('write() requires mode "w" or "a"') if not self.fp: