liblaf.melon.io.abc
¶
Reusable dispatchers for readers, writers, and converters.
Classes:
-
AbstractConverter–Callable that converts one object into another mesh representation.
-
AbstractReader–Callable that loads an object from a path.
-
AbstractWriter–Callable that writes an object to a path.
-
ConverterDispatcher–Single-dispatch conversion registry with identity conversion built in.
-
ReaderDispatcher–Dispatch readers by file suffix with an optional fallback reader.
-
WriterDispatcher–Dispatch writers first by file suffix and then by object type.
Attributes:
-
save(WriterDispatcher[Any]) –Write registered mesh and scene objects to disk based on path suffix.
save
module-attribute
¶
save: WriterDispatcher[Any] = WriterDispatcher()
Write registered mesh and scene objects to disk based on path suffix.
AbstractConverter
¶
AbstractReader
¶
AbstractWriter
¶
ConverterDispatcher
¶
Single-dispatch conversion registry with identity conversion built in.
The target type is registered as an identity conversion, so callers can pass through objects that are already in the requested representation.
Examples:
>>> converter = ConverterDispatcher(str)
>>> converter("mesh")
'mesh'
>>> @converter.register(int)
... def _from_int(obj, /, **kwargs):
... return str(obj)
>>> converter(42)
'42'
Parameters:
-
to_type(type[T]) –Target type returned unchanged when the input already has that runtime type.
-
registry(_SingleDispatchCallable[T], default:<dynamic>) –Underlying
functools.singledispatchregistry.
Methods:
Attributes:
-
registry(_SingleDispatchCallable[T]) –Underlying
functools.singledispatchregistry. -
to_type(type[T]) –Target type returned unchanged when the input already has that runtime type.
registry
class-attribute
instance-attribute
¶
Underlying functools.singledispatch registry.
to_type
instance-attribute
¶
to_type: type[T]
Target type returned unchanged when the input already has that runtime type.
register
¶
register[F](
cls: _RegType, converter: AbstractConverter[F, T]
) -> AbstractConverter[F, T]
register[F](
cls: _RegType, converter: None = None
) -> Callable[
[AbstractConverter[F, T]], AbstractConverter[F, T]
]
Source code in src/liblaf/melon/io/abc/_converter.py
ReaderDispatcher
¶
Dispatch readers by file suffix with an optional fallback reader.
Raises:
-
KeyError–If the path suffix is unknown and no fallback reader exists.
Attributes:
Parameters:
-
to_type(type[T]) – -
fallback(AbstractReader[T] | None, default:None) – -
registry(dict[str, AbstractReader[T]], default:<class 'dict'>) –dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
Methods:
registry
class-attribute
instance-attribute
¶
registry: dict[str, AbstractReader[T]] = field(
factory=dict
)
__call__
¶
Source code in src/liblaf/melon/io/abc/_reader.py
register
¶
register(
suffixes: Iterable[str], reader: AbstractReader[T]
) -> AbstractReader[T]
register(
suffixes: Iterable[str], reader: None = None
) -> Callable[[AbstractReader[T]], AbstractReader[T]]
Source code in src/liblaf/melon/io/abc/_reader.py
register_fallback
¶
register_fallback(
reader: AbstractReader[T],
) -> AbstractReader[T]
WriterDispatcher
¶
Dispatch writers first by file suffix and then by object type.
Registered writers receive a pathlib.Path. Parent directories are created
before the writer is called, which keeps concrete writer implementations
focused on serialization.
Raises:
-
KeyError–If no writer registry exists for the path suffix.
-
NotImplementedError–If the suffix exists but the object type is not registered for that suffix.
Parameters:
-
registry(dict[str, _SingleDispatchCallable[None]], default:<class 'dict'>) –dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
Methods:
Attributes:
registry
class-attribute
instance-attribute
¶
__call__
¶
Source code in src/liblaf/melon/io/abc/_writer.py
register
¶
register(
cls: _RegType,
suffixes: Iterable[str],
writer: AbstractWriter[T],
) -> AbstractWriter[T]
register(
cls: _RegType,
suffixes: Iterable[str],
writer: None = None,
) -> Callable[[AbstractWriter[T]], AbstractWriter[T]]