fix: removed 'normalize' in ActionFlow
This commit is contained in:
@@ -20,17 +20,14 @@ class ActionFlow:
|
|||||||
self.indices: dict[str, int] = {}
|
self.indices: dict[str, int] = {}
|
||||||
self.actions: list[type[Action]] = []
|
self.actions: list[type[Action]] = []
|
||||||
self.on: list[bool] = []
|
self.on: list[bool] = []
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def normalize(cls, kind):
|
|
||||||
return str.upper(kind.__name__)
|
|
||||||
|
|
||||||
def do(self, action: str):
|
def do(self, action: type[Action]):
|
||||||
index = self.indices.get(action)
|
name = action.__name__
|
||||||
|
index = self.indices.get(name)
|
||||||
assert index is not None
|
assert index is not None
|
||||||
|
|
||||||
if self.on[index]: raise Unavailable(action)
|
if self.on[index]: raise Unavailable(name)
|
||||||
if self.on[index] is None: raise NotAllowed(action)
|
if self.on[index] is None: raise NotAllowed(name)
|
||||||
value = self.actions[index].prepare()
|
value = self.actions[index].prepare()
|
||||||
self.on[index] = bool(value)
|
self.on[index] = bool(value)
|
||||||
|
|
||||||
@@ -40,27 +37,27 @@ class ActionFlow:
|
|||||||
self.on[index] = False
|
self.on[index] = False
|
||||||
self.actions[index].perform()
|
self.actions[index].perform()
|
||||||
|
|
||||||
def index(self, kind: type[Action]) -> int:
|
def index(self, action: type[Action]) -> int:
|
||||||
name = self.normalize(kind)
|
name = action.__name__
|
||||||
index = self.indices.get(name)
|
index = self.indices.get(name)
|
||||||
assert index is not None
|
assert index is not None
|
||||||
return index
|
return index
|
||||||
|
|
||||||
def allow(self, kind, value=True):
|
def allow(self, action: type[Action], value=True):
|
||||||
index = self.index(kind)
|
index = self.index(action)
|
||||||
self.on[index] = False if value else None
|
self.on[index] = False if value else None
|
||||||
|
|
||||||
def append(self, kind):
|
def append(self, action: type[Action]):
|
||||||
name = self.normalize(kind)
|
name = action.__name__
|
||||||
index = len(self.indices)
|
index = len(self.indices)
|
||||||
|
|
||||||
self.indices[name] = index
|
self.indices[name] = index
|
||||||
self.actions.insert(index, kind)
|
self.actions.insert(index, action)
|
||||||
self.on.insert(index, None)
|
self.on.insert(index, None)
|
||||||
|
|
||||||
def remove(self, kind):
|
def remove(self, action: type[Action]):
|
||||||
name = self.normalize(kind)
|
name = action.__name__
|
||||||
index = self.index(kind)
|
index = self.index(action)
|
||||||
|
|
||||||
self.indices.pop(name)
|
self.indices.pop(name)
|
||||||
self.actions.pop(index)
|
self.actions.pop(index)
|
||||||
|
|||||||
Reference in New Issue
Block a user