Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,22 @@ def __iter__(self):
if not line:
break
yield line

def __enter__(self):
#INFO: This was used in Python3.6, but we aren't based off io.BufferedReader in Python2
# self._check()
return self

def __exit__(self, type, value, traceback):
if type is None:
self.close()
else:
# An exception occurred. We must not call close() because
# it would try to write end-of-archive blocks and padding.
if not self._extfileobj:
self.fileobj.close()


#class ExFileObject

#------------------
Expand Down Expand Up @@ -1946,14 +1962,16 @@ def gettarinfo(self, name=None, arcname=None, fileobj=None):
tarinfo.devminor = os.minor(statres.st_rdev)
return tarinfo

def list(self, verbose=True):
def list(self, verbose=True, members=None):
"""Print a table of contents to sys.stdout. If `verbose' is False, only
the names of the members are printed. If it is True, an `ls -l'-like
output is produced.
"""
self._check()

for tarinfo in self:
if members is None:
members = self.getmembers()
for tarinfo in members:
if verbose:
print filemode(tarinfo.mode),
print "%s/%s" % (tarinfo.uname or tarinfo.uid,
Expand Down
Loading