def open_archive(stream, filename):
name, ext = os.path.splitext(os.path.basename(filename))<EOL>def targz_handler(stream):<EOL><INDENT>return TarGZAdapter(tarfile.open(fileobj=stream, mode='<STR_LIT>'))<EOL><DEDENT>cls = [zipfile.ZipFile, targz_handler]['<STR_LIT>' in ext]<EOL>archive = cls(stream)<EOL>return archive<EOL>
Open an archive (tarball or zip) and return the object.