TomlRsProvider
Base classes
| Name |
Children |
Inherits |
TomlProviderBase configz.toml_tools.base Base class for all TOML providers. |
|
|
⋔ Inheritance diagram
graph TD
4193656000["provider.TomlRsProvider"]
2503906984["base.TomlProviderBase"]
925645236["abc.ABC"]
2751680898["builtins.object"]
2503906984 --> 4193656000
925645236 --> 2503906984
2751680898 --> 925645236
🛈 DocStrings
Bases: TomlProviderBase
TOML-RS implementation of the TOML provider interface.
Source code in src/configz/toml_tools/toml_rs_provider/provider.py
| class TomlRsProvider(TomlProviderBase):
"""TOML-RS implementation of the TOML provider interface."""
@staticmethod
def load_toml(data: str | bytes | TextIOWrapper | Path | UPath) -> Any:
"""Load TOML using toml_rs."""
import toml_rs
try:
source_content: str | None = None
source_path: Path | UPath | None = None
match data:
case Path() | UPath():
source_path = data
bytes_data = data.read_bytes()
source_content = bytes_data.decode(errors="replace")
return toml_rs.load(BytesIO(bytes_data))
case TextIOWrapper():
content = data.read()
source_content = content
return toml_rs.loads(content)
case bytes():
content = data.decode()
source_content = content
return toml_rs.loads(content)
case str():
source_content = data
return toml_rs.loads(data)
except toml_rs.TOMLDecodeError as exc:
raise TomlLoadError(
f"Invalid TOML: {exc.msg}",
line=exc.lineno,
column=exc.colno,
source_path=str(source_path) if isinstance(source_path, UPath) else source_path,
source_content=source_content,
) from exc
@staticmethod
def dump_toml(data: Any, *, pretty: bool = False) -> str:
"""Dump data to TOML string using toml_rs."""
import toml_rs
return toml_rs.dumps(data, pretty=pretty)
|
dump_toml(data: Any, *, pretty: bool = False) -> str
Dump data to TOML string using toml_rs.
Source code in src/configz/toml_tools/toml_rs_provider/provider.py
| @staticmethod
def dump_toml(data: Any, *, pretty: bool = False) -> str:
"""Dump data to TOML string using toml_rs."""
import toml_rs
return toml_rs.dumps(data, pretty=pretty)
|
load_toml(data: str | bytes | TextIOWrapper | Path | UPath) -> Any
Load TOML using toml_rs.
Source code in src/configz/toml_tools/toml_rs_provider/provider.py
| @staticmethod
def load_toml(data: str | bytes | TextIOWrapper | Path | UPath) -> Any:
"""Load TOML using toml_rs."""
import toml_rs
try:
source_content: str | None = None
source_path: Path | UPath | None = None
match data:
case Path() | UPath():
source_path = data
bytes_data = data.read_bytes()
source_content = bytes_data.decode(errors="replace")
return toml_rs.load(BytesIO(bytes_data))
case TextIOWrapper():
content = data.read()
source_content = content
return toml_rs.loads(content)
case bytes():
content = data.decode()
source_content = content
return toml_rs.loads(content)
case str():
source_content = data
return toml_rs.loads(data)
except toml_rs.TOMLDecodeError as exc:
raise TomlLoadError(
f"Invalid TOML: {exc.msg}",
line=exc.lineno,
column=exc.colno,
source_path=str(source_path) if isinstance(source_path, UPath) else source_path,
source_content=source_content,
) from exc
|
:fa-brands-github: Show source on GitHub