From 44c66c72c9045a7824d07175cfc07845e4d7d28a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 29 Dec 2012 22:54:49 +0200 Subject: Issue #16486: Make aifc files work with 'with' as context managers. --- Lib/aifc.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Lib/aifc.py') diff --git a/Lib/aifc.py b/Lib/aifc.py index a19b38f4aa..67ea5dadc0 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. # -- cgit v1.2.1