Passed
Push — main ( b312d0...29adcf )
by Douglas
01:37
created

pocketutils.misc.messages.MsgFormatter.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import warnings
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from typing import Mapping
3
4
from pocketutils.core import SmartEnum
5
6
7
class MsgLevel(SmartEnum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
8
    INFO = 1
9
    SUCCESS = 2
10
    NOTICE = 3
11
    WARNING = 4
12
    FAILURE = 5
13
14
15
class MsgFormatter:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
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):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
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