aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2021-10-15 08:49:23 +0300
committerBonfaceKilz2021-10-25 14:00:14 +0300
commit6195ad475cddce2007b125b856829cbb41defd30 (patch)
tree16d496852da4023a8be876a764273a4d32ef8077
parent026a0f4e46a1909b16433bf1620f1b778fa6b913 (diff)
downloadgenenetwork2-6195ad475cddce2007b125b856829cbb41defd30.tar.gz
resource_manager: Add OrderedEnum
Borrowed from: <https://github.com/woodruffw/ordered_enum/tree/master/src/ordered_enum>
-rw-r--r--wqflask/wqflask/resource_manager.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/wqflask/wqflask/resource_manager.py b/wqflask/wqflask/resource_manager.py
index dfd853b2..330600ed 100644
--- a/wqflask/wqflask/resource_manager.py
+++ b/wqflask/wqflask/resource_manager.py
@@ -1,13 +1,26 @@
import redis
import json
+import functools
+from enum import Enum
from typing import Dict
+@functools.total_ordering
+class OrderedEnum(Enum):
+ @classmethod
+ @functools.lru_cache(None)
+ def _member_list(cls):
+ return list(cls)
+ def __lt__(self, other):
+ if self.__class__ is other.__class__:
+ member_list = self.__class__._member_list()
+ return member_list.index(self) < member_list.index(other)
+ return NotImplemented