MCPcopy Create free account
hub / github.com/cdgriffith/Box / _from_toml

Function _from_toml

box/converters.py:300–318  ·  view source on GitHub ↗
(
    toml_string: str | None = None,
    filename: str | PathLike | None = None,
    encoding: str = "utf-8",
    errors: str = "strict",
)

Source from the content-addressed store, hash-verified

298
299
300def _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
321def _to_msgpack(obj, filename: str | PathLike | None = None, **kwargs):

Callers 5

test_from_tomlMethod · 0.90
test_from_toml_fileMethod · 0.90
test_bad_from_tomlMethod · 0.90
from_tomlMethod · 0.90
from_tomlMethod · 0.90

Calls 2

BoxErrorClass · 0.90
_existsFunction · 0.85

Tested by 3

test_from_tomlMethod · 0.72
test_from_toml_fileMethod · 0.72
test_bad_from_tomlMethod · 0.72