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