summaryrefslogtreecommitdiff
path: root/python/constantrenderer.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2025-11-20 09:58:28 -0500
committerPeter LaFosse <peter@vector35.com>2025-11-21 10:02:50 -0500
commit5880769cbac1362aad46a34faec4c553fa9fcac6 (patch)
tree02db205b7aa915900cbfc10384940b3750eb7d69 /python/constantrenderer.py
parentf52693d50de6a5c97afa0274277edca18cfa00ea (diff)
Add get and __contains__ methods to all *MetaClass
Fixes: https://github.com/Vector35/binaryninja-api/issues/7588
Diffstat (limited to 'python/constantrenderer.py')
-rw-r--r--python/constantrenderer.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/python/constantrenderer.py b/python/constantrenderer.py
index 7f4c251c..a0c2c98c 100644
--- a/python/constantrenderer.py
+++ b/python/constantrenderer.py
@@ -20,7 +20,7 @@
import traceback
import ctypes
-from typing import Optional
+from typing import Optional, Any
import binaryninja
from . import _binaryninjacore as core
@@ -51,6 +51,23 @@ class _ConstantRendererMetaClass(type):
raise KeyError("'%s' is not a valid renderer" % str(value))
return CoreConstantRenderer(handle=renderer)
+ def __contains__(cls: '_ConstantRendererMetaClass', name: object) -> bool:
+ if not isinstance(name, str):
+ return False
+ try:
+ cls[name]
+ return True
+ except KeyError:
+ return False
+
+ def get(cls: '_ConstantRendererMetaClass', name: str, default: Any = None) -> Optional['ConstantRenderer']:
+ try:
+ return cls[name]
+ except KeyError:
+ if default is not None:
+ return default
+ return None
+
class ConstantRenderer(metaclass=_ConstantRendererMetaClass):
"""