This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: wrong % of params for format string in ZipFile.printdir()
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: alanmcintyre, rhettinger, szabihernyo
Priority: high Keywords:

Created on 2007-04-11 12:58 by szabihernyo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg31762 - (view) Author: Szabolcs Berecz (szabihernyo) Date: 2007-04-11 12:58
In zipfile.py:448
date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time
should be changed to
date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time[:6]

checked with python2.[45] on windows and linux


>>> from zipfile import ZipFile
>>> from StringIO import StringIO
>>> s = StringIO()
>>> zf = ZipFile(s, 'w')
>>> zf.writestr('file.ext', '123')
>>> zf.printdir()
File Name                                             Modified             Size
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/zipfile.py", line 448, in printdir
    date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time
TypeError: int argument required
>>> zf.filelist[0].date_time
(2007, 4, 11, 13, 38, 58, 2, 101, 1)
>>>
msg31763 - (view) Author: Alan McIntyre (alanmcintyre) * (Python committer) Date: 2007-04-11 13:34
The same problem appears to be present in 2.6 as well.  The date_time attribute of ZipInfo is a time.struct_time in 2.4 and 2.6 (I don't have 2.5 available to check at the moment), not a tuple.  I'm assuming this could be fixed by changing that line to:

date = "%d-%02d-%02d %02d:%02d:%02d" % tuple(zinfo.date_time)[:6]

At the moment I can't connect to the svn server; when I can I'll submit a patch for the trunk and 2.5.
msg31764 - (view) Author: Alan McIntyre (alanmcintyre) * (Python committer) Date: 2007-04-12 03:28
Patches to fix this have been posted for 2.5 (#1698915) and 2.6 (#1698917)
msg59931 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-01-14 23:05
Fixed in revision 59959
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44829
2008-01-14 23:05:01rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg59931
2007-04-11 12:58:45szabihernyocreate