| Total Complexity | 6 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |