[New-bugs-announce] [issue3039] tarfile.TarFileCompat.writestr(ZipInfo, str) raises AttributeError

Jason Kankiewicz report at bugs.python.org
Thu Jun 5 04:22:47 CEST 2008


New submission from Jason Kankiewicz <jkankiewicz at acm.org>:

tarfile.TarFileCompat.writestr( self, zinfo, bytes ) raises
AttributeError("'ZipInfo' object has no attribute 'name'") because an
analog to the tarfile.TarInfo.name attribute cannot be monkeypatched
into the zinfo argument value when it's an instance of zipfile.ZipInfo.

The zipfile.ZipInfo class' attributes are slots, so no ad hoc attributes
can be monkeypatched into an instance of it.

I've replaced the monkeypatching of zinfo with the creation of a new
tarfile.TarInfo object, tinfo, which receives its relevant values instead.

This revealed another problem with the assignment of zinfo.file_size to
tinfo.size: if zinfo.file_size has not been assigned a value then an
AttributeError("file_size") will be raised because the slotted attribute
doesn't exist.
Being that the documentation for zipfile.ZipFile.writestr( self,
zinfo_or_arcname, bytes ) claims that a zipfile.ZipInfo object value for
zinfo_or_arcname must contain "at least the filename, date and time",
it's highly likely that zinfo.file_size will be unassigned in ordinary use.
I fixed this problem by ignoring the value of zinfo.file_size and using
the value of len(bytes) instead, just like the implementation of
zipfile.ZipFile.writestr.

I would have provided a patch for tarfile.TarFileCompat.writestr's unit
test suite, but it doesn't appear to exist.

----------
components: Library (Lib)
files: tarfile.TarFileCompat.patch
keywords: patch
messages: 67708
nosy: jkankiewicz
severity: normal
status: open
title: tarfile.TarFileCompat.writestr(ZipInfo, str) raises AttributeError
type: crash
versions: Python 2.5, Python 2.6, Python 3.0
Added file: http://bugs.python.org/file10520/tarfile.TarFileCompat.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3039>
_______________________________________


More information about the New-bugs-announce mailing list