| 298 | |
| 299 | |
| 300 | def _from_toml( |
| 301 | toml_string: str | None = None, |
| 302 | filename: str | PathLike | None = None, |
| 303 | encoding: str = "utf-8", |
| 304 | errors: str = "strict", |
| 305 | ): |
| 306 | if filename: |
| 307 | _exists(filename) |
| 308 | if toml_read_library.__name__ == "toml": # type: ignore |
| 309 | with open(filename, "r", encoding=encoding, errors=errors) as f: |
| 310 | data = toml_read_library.load(f) # type: ignore |
| 311 | else: |
| 312 | with open(filename, "rb") as f: |
| 313 | data = toml_read_library.load(f) # type: ignore |
| 314 | elif toml_string: |
| 315 | data = toml_read_library.loads(toml_string) # type: ignore |
| 316 | else: |
| 317 | raise BoxError("from_toml requires a string or filename") |
| 318 | return data |
| 319 | |
| 320 | |
| 321 | def _to_msgpack(obj, filename: str | PathLike | None = None, **kwargs): |