更新
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
from typing import Dict, Any, Callable, TypedDict
|
||||
|
||||
class AlgorithmConfig(TypedDict):
|
||||
algo_name: str
|
||||
defaults: Dict[str, Any]
|
||||
revisor: Callable[[dict, int, bool], None]
|
||||
|
||||
_algorithms: Dict[str, AlgorithmConfig] = {}
|
||||
|
||||
def register_algorithm(algo_name: str, defaults: Dict[str, Any], revisor: Callable):
|
||||
_algorithms[algo_name] = {
|
||||
'algo_name': algo_name,
|
||||
'defaults': defaults,
|
||||
'revisor': revisor
|
||||
}
|
||||
|
||||
def get_algorithm(algo_name: str) -> AlgorithmConfig:
|
||||
if algo_name not in _algorithms:
|
||||
raise ValueError(f"算法 {algo_name}' 未找到, 可用值: {list_algorithms()}")
|
||||
return _algorithms[algo_name]
|
||||
|
||||
def list_algorithms() -> list[str]:
|
||||
return list(_algorithms.keys())
|
||||
|
||||
# 导入注册
|
||||
from . import sm2
|
||||
register_algorithm(
|
||||
algo_name=sm2.algo_name,
|
||||
defaults=sm2.defaults,
|
||||
revisor=sm2.revisor
|
||||
)
|
||||
|
||||
__all__ = ['get_algorithm', 'list_algorithms', 'register_algorithm', 'AlgorithmConfig']
|
||||
Reference in New Issue
Block a user