From 4c9fb0b8b94bbd422dc0ea63c50c784624bf6be5 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Wed, 27 May 2020 09:01:19 -0400 Subject: Add context manager for BinaryViews in the python API --- python/binaryview.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'python/binaryview.py') diff --git a/python/binaryview.py b/python/binaryview.py index 9074b58c..994d9edd 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -1323,6 +1323,12 @@ class BinaryView(object): self._notifications = {} self._next_address = None # Do NOT try to access view before init() is called, use placeholder + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.file.close() + def __del__(self): for i in self.notifications.values(): i._unregister() -- cgit v1.3.1