Skip to content

Commit

Permalink
autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Apr 10, 2024
1 parent 0f44569 commit d239c02
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions fileformats/datascience/image.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import typing as ty
from fileformats.core.exceptions import FileFormatsError
from fileformats.core.exceptions import FormatMismatchError
from fileformats.image import RasterImage
from fileformats.core.mixin import WithMagicVersion


class Vtk(WithMagicVersion, RasterImage):
"""VTK image file format. as described at http://www.princeton.edu/~efeibush/viscourse/vtk.pdf"""

magic_pattern = rb" #vtkDataFileVersion (\d).(\d)"
binary = True
ext = '.vtk'
mime_types = ('application/x-vtk', 'application/x-vtk-ascii', 'application/x-vtk-binary')
ext = ".vtk"
mime_types = (
"application/x-vtk",
"application/x-vtk-ascii",
"application/x-vtk-binary",
)

@property
def header_info(self) -> ty.Tuple[bytes, str]:
Expand All @@ -22,19 +27,21 @@ def header_info(self) -> ty.Tuple[bytes, str]:
format : str
The format of the VTK file, either 'ascii' or 'binary'.
"""
header_end: int = self.contents.find(b'\n')
header_end: int = self.contents.find(b"\n")
header: bytes = self.contents[:header_end]
format_end: int = self.contents.find(b'\n', header_end + 1)
contents_format = self.contents[header_end:format_end].strip().decode("utf-8").lower()
format_end: int = self.contents.find(b"\n", header_end + 1)
contents_format = (
self.contents[header_end:format_end].strip().decode("utf-8").lower()
)
if contents_format not in ("ascii", "binary"):
raise FileFormatsError(
raise FormatMismatchError(
f"Unknown VTK format: {contents_format} (must be 'ascii' or 'binary')"
)
# type_end: int = self.contents.find(b'\n', format_end + 1)
# type_str = self.contents[format_end:type_end].strip().decode("utf-8").lower()
# match = re.match(r"(?<!\w)DATASET (\w+)", type_str)
# if not match:
# raise FileFormatsError(
# raise FormatMismatchError(
# f"VTK file does not contain a DATASET type: {type_str}"
# )
return header, contents_format

0 comments on commit d239c02

Please sign in to comment.