I/O
momapy.io
Base classes and functions for reading and writing maps
Classes:
| Name | Description |
|---|---|
IOResult |
Base class for I/O results |
Reader |
Base class for readers |
ReaderResult |
Base class for reader results |
Writer |
Base class for writers |
WriterResult |
Base class for writer results |
Functions:
| Name | Description |
|---|---|
read |
Read a map file and return a reader result using the given registered reader. If no reader is given, will check for an appropriate reader among the registered readers, using the |
register_reader |
Register a reader |
register_writer |
Register a writer |
write |
Write an object to a file and return a writer result using the given registered writer |
IOResult
dataclass
Base class for I/O results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exceptions
|
list[Exception]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
Reader
Bases: ABC
Base class for readers
Methods:
| Name | Description |
|---|---|
check_file |
Return |
read |
Read a file and return a reader result using the reader |
check_file
classmethod
read
abstractmethod
classmethod
read(file_path: str | PathLike, **options) -> ReaderResult
ReaderResult
dataclass
ReaderResult(
exceptions: list[Exception] = list(),
obj: Any | None = None,
annotations: dict | None = None,
notes: dict | None = None,
ids: dict | None = None,
file_path: str | PathLike | None = None,
)
Bases: IOResult
Base class for reader results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exceptions
|
list[Exception]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
obj
|
Any | None
|
|
None
|
annotations
|
dict | None
|
|
None
|
notes
|
dict | None
|
|
None
|
ids
|
dict | None
|
|
None
|
file_path
|
str | PathLike | None
|
|
None
|
Writer
Bases: ABC
Base class for writers
Methods:
| Name | Description |
|---|---|
write |
Write an object to a file and return a writer result using the writer |
write
abstractmethod
classmethod
write(
obj: Any, file_path: str | PathLike, **options
) -> WriterResult
Write an object to a file and return a writer result using the writer
WriterResult
dataclass
WriterResult(
exceptions: list[Exception] = list(),
obj: Any | None = None,
file_path: str | PathLike | None = None,
)
Bases: IOResult
Base class for writer results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exceptions
|
list[Exception]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
obj
|
Any | None
|
|
None
|
file_path
|
str | PathLike | None
|
|
None
|
read
read(
file_path: str | PathLike,
reader: str | None = None,
**options,
) -> ReaderResult
Read a map file and return a reader result using the given registered reader. If no reader is given, will check for an appropriate reader among the registered readers, using the check_file method of each reader. If there is more than one appropriate reader, will use the first one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | PathLike
|
The path of the file to read |
required |
reader
|
str | None
|
The registered reader |
None
|
options
|
Options to be passed to the reader |
{}
|
Returns:
| Type | Description |
|---|---|
ReaderResult
|
A reader result |
Source code in src/momapy/io.py
register_reader
register_writer
write
write(
obj: Any,
file_path: str | PathLike,
writer: str,
**options,
) -> WriterResult
Write an object to a file and return a writer result using the given registered writer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to write |
required |
file_path
|
str | PathLike
|
The path of the file to write to |
required |
writer
|
str
|
The registered writer |
required |
options
|
Options to be passed to the writer |
{}
|
Returns:
| Type | Description |
|---|---|
WriterResult
|
A writer result |