Add converter modules (JSON, YAML, TOML, CSV)
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-02-01 19:01:13 +00:00
parent e89ed9cbc7
commit d4242163b2

View File

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