summaryrefslogtreecommitdiff
path: root/python/binaryview.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2020-05-27 09:01:19 -0400
committerPeter LaFosse <peter@vector35.com>2020-05-27 10:26:29 -0400
commit4c9fb0b8b94bbd422dc0ea63c50c784624bf6be5 (patch)
tree546be963cb4227b4a4bf5fcfff64907eb1af5aa0 /python/binaryview.py
parentfed4a230aab3b689b57ce02edd8948691f94baee (diff)
Add context manager for BinaryViews in the python API
Diffstat (limited to 'python/binaryview.py')
-rw-r--r--python/binaryview.py6
1 files changed, 6 insertions, 0 deletions
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()