New submission from Alex Leach <beamesle...@gmail.com>:

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

----------
components: Extension Modules
messages: 130482
nosy: Alex.Leach
priority: normal
severity: normal
status: open
title: tarfile with socket incompatability

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11458>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to