diff --git a/src/converters/toml_converter.py b/src/converters/toml_converter.py new file mode 100644 index 0000000..45635ca --- /dev/null +++ b/src/converters/toml_converter.py @@ -0,0 +1,41 @@ +"""TOML converter module.""" + +import tomlkit +from typing import Any + +from .base import BaseConverter + + +class TOMLConverter(BaseConverter): + """Converter for TOML format.""" + + format_name = 'toml' + extensions = ('.toml',) + + def loads(self, content: str) -> Any: + """Parse TOML string to Python object. + + Args: + content: TOML string content + + Returns: + Parsed Python object + + Raises: + tomlkit.exceptions.ParseError: If content is not valid TOML + """ + return tomlkit.parse(content) + + def dumps(self, data: Any, indent: int = 2) -> str: + """Serialize Python object to TOML string. + + Args: + data: Python object to serialize + indent: Ignored for TOML (uses its own formatting) + + Returns: + TOML string representation + """ + if isinstance(data, tomlkit.TOMLDocument): + return tomlkit.dumps(data) + return tomlkit.dumps(data)