summaryrefslogtreecommitdiffstats
path: root/Lib/aifc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2012-12-29 20:54:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2012-12-29 20:54:49 (GMT)
commit44c66c72c9045a7824d07175cfc07845e4d7d28a (patch)
treea88a17bd7c1a4fb9542d5d9a4f7d91c80eb303e4 /Lib/aifc.py
parentff2840a76f04c8846e8ad5b7e8379998ab3e87a6 (diff)
downloadcpython-44c66c72c9045a7824d07175cfc07845e4d7d28a.zip
cpython-44c66c72c9045a7824d07175cfc07845e4d7d28a.tar.gz
cpython-44c66c72c9045a7824d07175cfc07845e4d7d28a.tar.bz2
Issue #16486: Make aifc files work with 'with' as context managers.
Diffstat (limited to 'Lib/aifc.py')
-rw-r--r--Lib/aifc.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py
index a19b38f..67ea5da 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -334,6 +334,12 @@ class Aifc_read:
# else, assume it is an open file object already
self.initfp(f)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ self.close()
+
#
# User visible methods.
#
@@ -553,6 +559,12 @@ class Aifc_write:
def __del__(self):
self.close()
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ self.close()
+
#
# User visible methods.
#