| Total Complexity | 4 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import warnings |
||
|
|
|||
| 2 | from typing import Mapping |
||
| 3 | |||
| 4 | from pocketutils.core import SmartEnum |
||
| 5 | |||
| 6 | |||
| 7 | class MsgLevel(SmartEnum): |
||
| 8 | INFO = 1 |
||
| 9 | SUCCESS = 2 |
||
| 10 | NOTICE = 3 |
||
| 11 | WARNING = 4 |
||
| 12 | FAILURE = 5 |
||
| 13 | |||
| 14 | |||
| 15 | class MsgFormatter: |
||
| 16 | def __init__(self): |
||
| 17 | warnings.warn("MsgFormatter will be removed", DeprecationWarning) |
||
| 18 | |||
| 19 | def __call__(self, message: str, level: MsgLevel) -> str: |
||
| 20 | raise NotImplementedError() |
||
| 21 | |||
| 22 | |||
| 23 | class MsgFormatterSimple(MsgFormatter): |
||
| 24 | def __init__(self, prefixes: Mapping[MsgLevel, str], suffixes: Mapping[MsgLevel, str]): |
||
| 25 | super().__init__() |
||
| 26 | self.prefixes, self.suffixes = prefixes, suffixes |
||
| 27 | |||
| 28 | def __call__(self, message: str, level: MsgLevel) -> str: |
||
| 29 | return self.prefixes.get(level, "") + message + self.suffixes.get(level, "") |
||
| 30 | |||
| 31 | |||
| 32 | __all__ = ["MsgLevel", "MsgFormatter", "MsgFormatterSimple"] |
||
| 33 |