tarfile.open(mode='w:gz'|'w|gz'|..., fileobj=StringIO()) fails.

Lars Gustäbel lars at gustaebel.de
Tue May 27 08:47:40 EDT 2008


On Tue, May 27, 2008 at 01:51:47AM -0700, sebastian.noack at googlemail.com wrote:
> I have written a FileWrapper class as workaround, which works for me
> (see the code below). The FileWrapper object holds an internal file-
> like object and maps its attributes, but prevents the user (in this
> case tarfile) from closing the internal file, so I can still access
> StringIO's content after closing the TarFile object.
> 
> But this should not be required to create in memory tar files. It is
> definitely a bug, that TarFile closes external file objects passed to
> tarfile.open, when closing the TarFile object. The code which opens a
> file is also responsible for closing it.

You're right, _BZ2Proxy.close() calls the wrapped file object's close() method
and that is definitely not the desired behaviour. So, if you can do without 'bz2'
modes for now, you're problem is gone, all other modes work fine.

I fixed it (r63744), so the next beta release will work as expected. Your test
script helped a lot, thanks.

Regards,

-- 
Lars Gustäbel
lars at gustaebel.de

A casual stroll through a lunatic asylum shows that
faith does not prove anything.
(Friedrich Nietzsche)



More information about the Python-list mailing list