def listTar(tarfilename):
    tf = tarfile.open(tarfilename)
    members = tf.getmembers()
    rootChildren = []
    for entry in members:
        ename = '/' + entry.name.strip('/')
        if '/' not in ename:
            rootChildren.append(ename)
        if entry.isdir():
            children = [
                m.name.split('/')[-1] for m in members
                if (m.name.startswith(ename[1:] + '/') and
                    '/' not in m.name[len(ename[1:] + '/')])]
            yield (ename, children, None)
        else:
            f = tf.extractfile(entry)
            yield (ename, None, f)
    yield('', rootChildren, None)
dataset/ETHPy150Open phihag/vulnsrv/set_content.py/listTar/original