Files
data-format-converter/src/converters/toml_converter.py
7000pctAUTO d4242163b2
Some checks failed
CI / test (push) Has been cancelled
Add converter modules (JSON, YAML, TOML, CSV)
2026-02-01 19:01:13 +00:00

42 lines
1.0 KiB
Python

"""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)