Add converter modules (JSON, YAML, TOML, CSV)
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
41
src/converters/toml_converter.py
Normal file
41
src/converters/toml_converter.py
Normal 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)
|
||||
Reference in New Issue
Block a user