Skip to content

provider

Class info

Classes

Name Children Inherits
TomlRsProvider
configz.toml_tools.toml_rs_provider.provider
TOML-RS implementation of the TOML provider interface.

    🛈 DocStrings

    TOML-RS provider implementation.

    TomlRsProvider

    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 staticmethod

    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 staticmethod

    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