illustration   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 32
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Illustration.__str__() 0 9 3
A Illustration.__init__() 0 20 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A remove_wiki_unsafe_characters() 0 4 1
1
from pathlib import Path
2
from re import sub
3
4
from .state_of_illustrations import StateOfIllustrations  # type: ignore
5
6
7
def remove_wiki_unsafe_characters(upload_filename) -> str:
8
    upload_filename = sub(r"[{\[]", "(", upload_filename)
9
    upload_filename = sub(r"[}\]]", ")", upload_filename)
10
    return upload_filename
11
12
13
class Illustration:
14
    def __init__(
15
        self,
16
        upload_filename: str,
17
        size_in_pixels: int,
18
        state_of_illustrations: StateOfIllustrations,
19
        original_file_path: Path | None = None,
20
    ) -> None:
21
        assert isinstance(upload_filename, str)
22
        upload_filename = remove_wiki_unsafe_characters(upload_filename)
23
        self.upload_filename = upload_filename
24
25
        assert isinstance(size_in_pixels, int)
26
        self.size_in_pixels = size_in_pixels
27
28
        assert isinstance(state_of_illustrations, StateOfIllustrations)
29
        self.state_of_illustrations = state_of_illustrations
30
31
        if original_file_path:
32
            assert isinstance(original_file_path, Path)
33
        self.original_file_path = original_file_path
34
35
    def __str__(self) -> str:
36
        if (
37
            self.state_of_illustrations == StateOfIllustrations.YesAndAvailable
38
            or self.state_of_illustrations == StateOfIllustrations.YesButUnavailable
39
        ):
40
            return f"\n[[Fájl:{self.upload_filename}|keret|keretnélküli|{self.size_in_pixels}px]]"
41
        else:
42
            raise ValueError(
43
                "No images were expected in the quiz but one image filename was requested!"
44
            )
45