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.

Author Alex.Leach
Recipients Alex.Leach
Date 2011-03-10.02:33:59
SpamBayes Score 4.8128914e-08
Marked as misclassified No
Message-id <1299724439.89.0.965974216357.issue11458@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

I'm trying to parse the contents of tar archives (.tgz) on the fly, and failing to do so. The tar archives in question have directory hierarchies, and only if a TarInfo object is a file (.isreg() ) will I try and read it's contents.

I figured a sensible idea would be to pass a socket(.makefile()) object to the fileobj attribute of tarfile.open. This doesn't work because a socket file descriptor does not have a tell() method. I understand that a socket object shouldn't need to have a tell method, but why should the fileobj passed to tarfile.open need it?

Code:-

def get_headers( self, file_name ):
    sock = socket.socket()
    sock.bind(('localhost',0))
    fd = sock.makefile()
    handle = tarfile.open( file_name,'r',fileobj=fd ) # This line breaks

I'm currently testing on Python v2.6.6 EPD 6.3-2 64 bit, on an Autumn 2010 Mac Pro.

My dirty bug-fix idea is to subclass tarfile.TarFile, and give it a tell() method, to just return 0. I don't want to have to do that. Any alternative suggestions would be greatly appreciated.

Cheers,
Alex
History
Date User Action Args
2011-03-10 02:33:59Alex.Leachsetrecipients: + Alex.Leach
2011-03-10 02:33:59Alex.Leachsetmessageid: <1299724439.89.0.965974216357.issue11458@psf.upfronthosting.co.za>
2011-03-10 02:33:59Alex.Leachlinkissue11458 messages
2011-03-10 02:33:59Alex.Leachcreate