This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
from abc import abstractmethod
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
from typing import Any, Final, Iterable, Iterator, Protocol, Sequence, TypeVar, overload
|
||||
from typing import (
|
||||
Any,
|
||||
Final,
|
||||
Iterable,
|
||||
Iterator,
|
||||
Protocol,
|
||||
Sequence,
|
||||
TypeVar,
|
||||
overload,
|
||||
)
|
||||
|
||||
from numpy.typing import NDArray
|
||||
|
||||
@@ -18,15 +27,19 @@ class ProgressHandler(Protocol):
|
||||
|
||||
class FileHandler:
|
||||
@abstractmethod
|
||||
def create(self, filename: str, content: bytes, text: bool = False): ...
|
||||
def create(
|
||||
self, filename: str, content: bytes, text: bool = False
|
||||
) -> Path | None: ...
|
||||
|
||||
def image(self, filename: str, image: NDArray[Any]):
|
||||
from io import BytesIO
|
||||
|
||||
import imageio.v3 as iio
|
||||
from pygifsicle import optimize # type: ignore
|
||||
|
||||
data = iio.imwrite("<bytes>", image, extension=Path(filename).suffix) # type: ignore
|
||||
self.create(filename, data, False)
|
||||
path = self.create(filename, data, False)
|
||||
|
||||
assert path is not None
|
||||
optimize(path, options=["--no-warnings"])
|
||||
|
||||
|
||||
class BaseSolver:
|
||||
|
@@ -14,3 +14,4 @@ class FileHandlerAPI(FileHandler):
|
||||
with open(self.folder.joinpath(filename), "wb") as fp:
|
||||
fp.write(content)
|
||||
dump_api_message("file", {"filename": filename, "size": len(content)})
|
||||
return self.folder.joinpath(filename)
|
||||
|
@@ -18,3 +18,4 @@ class SimpleFileHandler(FileHandler):
|
||||
self.folder.mkdir(exist_ok=True)
|
||||
with open(self.folder.joinpath(filename), "wb") as fp:
|
||||
fp.write(content)
|
||||
return self.folder.joinpath(filename)
|
||||
|
Reference in New Issue
Block a user