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: tarfile with socket incompatability
Type: Stage: resolved
Components: Extension Modules Versions:
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: Alex.Leach, r.david.murray
Priority: normal Keywords:

Created on 2011-03-10 02:33 by Alex.Leach, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
unnamed Alex.Leach, 2011-03-10 09:59
Messages (3)
msg130482 - (view) Author: Alex Leach (Alex.Leach) Date: 2011-03-10 02:33
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
msg130486 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-03-10 03:46
I believe you are looking for mode 'r|'.
msg130496 - (view) Author: Alex Leach (Alex.Leach) Date: 2011-03-10 09:59
Thanks! =D

On Thu, Mar 10, 2011 at 3:46 AM, R. David Murray <report@bugs.python.org>wrote:

>
> R. David Murray <rdmurray@bitdance.com> added the comment:
>
> I believe you are looking for mode 'r|'.
>
> ----------
> nosy: +r.david.murray
> resolution:  -> works for me
> stage:  -> committed/rejected
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue11458>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:57:14adminsetgithub: 55667
2011-03-10 09:59:09Alex.Leachsetfiles: + unnamed

messages: + msg130496
nosy: r.david.murray, Alex.Leach
2011-03-10 03:46:01r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg130486

resolution: works for me
stage: resolved
2011-03-10 02:33:59Alex.Leachcreate