from enum import Enum class Perm(Enum): DOC_ACL = 0b000000000001 DOC_READ = 0b000000000010 DOC_DELETE = 0b000000000100 ROLE_ACL = 0b000000001000 SUBJECT_NEW = 0b000000010000 SUBJECT_DOWN = 0b000000100000 SUBJECT_UP = 0b000001000000 DOC_NEW = 0b000010000000 ROLE_NEW = 0b000100000000 ROLE_DOWN = 0b001000000000 ROLE_UP = 0b010000000000 ROLE_MOD = 0b100000000000 @staticmethod def get_perm(bit_array: int): for perm in Perm: if bit_array == perm.value: return perm return None @staticmethod def get_int(perms): if isinstance(perms, list): return sum([p.value for p in perms if isinstance(p, Perm)]) return perms.value if isinstance(perms, Perm) else 0 @staticmethod def check_perm(perm, bit_array: int): return perm.value & bit_array == perm.value