Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tarfile with socket incompatability #55667

Closed
AlexLeach mannequin opened this issue Mar 10, 2011 · 3 comments
Closed

tarfile with socket incompatability #55667

AlexLeach mannequin opened this issue Mar 10, 2011 · 3 comments
Labels
extension-modules C modules in the Modules dir

Comments

@AlexLeach
Copy link
Mannequin

AlexLeach mannequin commented Mar 10, 2011

BPO 11458
Nosy @bitdancer
Files
  • unnamed
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-03-10.03:46:01.692>
    created_at = <Date 2011-03-10.02:33:59.354>
    labels = ['extension-modules']
    title = 'tarfile with socket incompatability'
    updated_at = <Date 2011-03-10.09:59:09.989>
    user = 'https://bugs.python.org/AlexLeach'

    bugs.python.org fields:

    activity = <Date 2011-03-10.09:59:09.989>
    actor = 'Alex.Leach'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-03-10.03:46:01.692>
    closer = 'r.david.murray'
    components = ['Extension Modules']
    creation = <Date 2011-03-10.02:33:59.354>
    creator = 'Alex.Leach'
    dependencies = []
    files = ['21069']
    hgrepos = []
    issue_num = 11458
    keywords = []
    message_count = 3.0
    messages = ['130482', '130486', '130496']
    nosy_count = 2.0
    nosy_names = ['r.david.murray', 'Alex.Leach']
    pr_nums = []
    priority = 'normal'
    resolution = 'works for me'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue11458'
    versions = []

    @AlexLeach
    Copy link
    Mannequin Author

    AlexLeach mannequin commented Mar 10, 2011

    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

    @AlexLeach AlexLeach mannequin added the extension-modules C modules in the Modules dir label Mar 10, 2011
    @bitdancer
    Copy link
    Member

    I believe you are looking for mode 'r|'.

    @AlexLeach
    Copy link
    Mannequin Author

    AlexLeach mannequin commented Mar 10, 2011

    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\>


    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant