aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-01-23 14:40:20 +0300
committerFrederick Muriuki Muriithi2023-01-23 14:40:20 +0300
commit50d07d1997876a7c64e82c3c86e97f238bda29f5 (patch)
treef8ec87ad8b54d6c4898419068fe7ce5ff9c15f18 /gn3/auth
parentb9139c2356f75103bc5fd17f074f4ee0e74b64aa (diff)
downloadgenenetwork3-50d07d1997876a7c64e82c3c86e97f238bda29f5.tar.gz
auth: Add missing module
Diffstat (limited to 'gn3/auth')
-rw-r--r--gn3/auth/dictify.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/gn3/auth/dictify.py b/gn3/auth/dictify.py
new file mode 100644
index 0000000..274ebb0
--- /dev/null
+++ b/gn3/auth/dictify.py
@@ -0,0 +1,17 @@
+"""Module for dictifying objects"""
+
+from typing import Any
+
+# TYPE = TypeVar("TYPE")
+
+__dictifiers__ = {}#: dict[TYPE, Callable[[TYPE], dict[str, Any]]] = {}
+
+# def register_dictifier(obj_type: TYPE, dictifier: Callable[[TYPE], dict[str, Any]]):
+def register_dictifier(obj_type, dictifier):
+ """Register a new dictifier function"""
+ global __dictifiers__ # pylint: disable=[global-variable-not-assigned]
+ __dictifiers__[obj_type] = dictifier
+
+def dictify(obj: Any) -> dict[str, Any]:
+ """Turn `obj` to a dict representation."""
+ return __dictifiers__[type(obj)](obj)