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

pocketutils.misc.messages   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A MsgFormatter.__call__() 0 2 1
A MsgFormatterSimple.__init__() 0 3 1
A MsgFormatter.__init__() 0 2 1
A MsgFormatterSimple.__call__() 0 2 1
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