code: def _open(file_, mode='r'):
    
    if isinstance(file_, string_types):
      _, ext = path.splitext(file_)
      if ext in {'.bz2', '.gz'}:
        s = tarfile.open(file_)
        return s.extractfile(s.next())
      else:
        return open(file_, mode)
    return file_
docs: Open file object given filenames, open files or even archives.