mirror of
https://github.com/python/cpython.git
synced 2025-07-30 06:34:15 +00:00
Issue #7232: Add support for the context manager protocol
to the TarFile class.
This commit is contained in:
parent
8af970ab58
commit
6458104188
4 changed files with 92 additions and 0 deletions
|
@ -2411,6 +2411,20 @@ class TarFile(object):
|
|||
"""
|
||||
if level <= self.debug:
|
||||
print >> sys.stderr, msg
|
||||
|
||||
def __enter__(self):
|
||||
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()
|
||||
self.closed = True
|
||||
# class TarFile
|
||||
|
||||
class TarIter:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue