summaryrefslogtreecommitdiff
path: root/python/downloadprovider.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/downloadprovider.py
parentf52693d50de6a5c97afa0274277edca18cfa00ea (diff)
Add get and __contains__ methods to all *MetaClass
Fixes: https://github.com/Vector35/binaryninja-api/issues/7588
Diffstat (limited to 'python/downloadprovider.py')
-rw-r--r--python/downloadprovider.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/python/downloadprovider.py b/python/downloadprovider.py
index 2fd94ac3..a1ff94bf 100644
--- a/python/downloadprovider.py
+++ b/python/downloadprovider.py
@@ -23,6 +23,7 @@ import ctypes
from json import dumps
import sys
import traceback
+from typing import Any, Optional
from urllib.parse import urlencode
# Binary Ninja Components
@@ -269,6 +270,23 @@ class _DownloadProviderMetaclass(type):
raise KeyError(f"'{value}' is not a valid download provider")
return DownloadProvider(provider)
+ def __contains__(cls: '_DownloadProviderMetaclass', name: object) -> bool:
+ if not isinstance(name, str):
+ return False
+ try:
+ cls[name]
+ return True
+ except KeyError:
+ return False
+
+ def get(cls: '_DownloadProviderMetaclass', name: str, default: Any = None) -> Optional['DownloadProvider']:
+ try:
+ return cls[name]
+ except KeyError:
+ if default is not None:
+ return default
+ return None
+
class DownloadProvider(metaclass=_DownloadProviderMetaclass):
name = None