-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_factory.py
More file actions
47 lines (32 loc) · 1.15 KB
/
format_factory.py
File metadata and controls
47 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import enum
from app.error.unknown_format_exception import UnknownFormatException
from app.io.bmp import BMPReader, BMPWriter
from app.io.format_reader import FormatReader
from app.io.format_writer import FormatWriter
class KnownFormat(enum.Enum):
BMP = 0
@classmethod
def from_string(cls, data_format: str) -> 'KnownFormat':
match data_format:
case 'bmp':
return cls.BMP
case _:
raise UnknownFormatException(data_format)
@classmethod
def get_available_formats(cls) -> list[str]:
return [e.name.lower() for e in cls]
@classmethod
def default(cls) -> 'KnownFormat':
return KnownFormat.BMP
def get_reader_from_format(data_format: KnownFormat) -> FormatReader:
match data_format:
case KnownFormat.BMP:
return BMPReader()
case _:
assert False, "unreachable"
def get_writer_from_format(data_format: KnownFormat) -> FormatWriter:
match data_format:
case KnownFormat.BMP:
return BMPWriter()
case _:
assert False, "unreachable"