From 6195ad475cddce2007b125b856829cbb41defd30 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 15 Oct 2021 08:49:23 +0300 Subject: resource_manager: Add OrderedEnum Borrowed from: --- wqflask/wqflask/resource_manager.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 -- cgit v1.2.3