tarobj.close()
os.unlink("big")
- fo = open("sample.tar.gz", 'rb') # will not be released on tarfile.close()
- fo.seek(pos)
- tarobj = TarFile.open(mode="r#gz", fileobj=fo)
- tarobj.extract(tarobj.next())
- tarobj.close()
- fo.close()
+ with open("sample.tar.gz", 'rb') as fo:
+ fo.seek(pos)
+ tarobj = TarFile.open(mode="r#gz", fileobj=fo)
+ tarobj.extract(tarobj.next())
+ tarobj.close()
assert os.path.exists("big")
assert hash == self.md5sum("big")
os.unlink("small2")
# extract only the "small" file
- fo = open("sample.tar.gz", 'rb') # will not be released on tarfile.close()
- fo.seek(pos)
- tarobj = TarFile.open(mode="r#gz", fileobj=fo)
- tarobj.extract(tarobj.next())
- tarobj.close()
- fo.close()
+ with open("sample.tar.gz", 'rb') as fo:
+ fo.seek(pos)
+ tarobj = TarFile.open(mode="r#gz", fileobj=fo)
+ tarobj.extract(tarobj.next())
+ tarobj.close()
assert os.path.exists("small")
assert hash['small'] == self.md5sum("small")