From 18325f7c053e092ff2ff161baf28a50c8fcfc843 Mon Sep 17 00:00:00 2001 From: Syping Date: Mon, 25 Mar 2024 13:43:10 +0100 Subject: [PATCH] pyragephoto: add 'with' support --- src/python/ragephoto.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/python/ragephoto.py b/src/python/ragephoto.py index b44a802..a1574c6 100644 --- a/src/python/ragephoto.py +++ b/src/python/ragephoto.py @@ -79,8 +79,16 @@ class RagePhoto: def __init__(self): self.__instance = libragephoto.ragephoto_open() - def __del__(self): + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): libragephoto.ragephoto_close(self.__instance) + self.__instance = None + + def __del__(self): + if self.__instance is not None: + libragephoto.ragephoto_close(self.__instance) def clear(self): libragephoto.ragephoto_clear(self.__instance)