36 lines
843 B
Python
36 lines
843 B
Python
from typing import Any, Text, MutableMapping
|
|
|
|
import toml
|
|
|
|
from jeeves.core.objects import Flow, BaseObject
|
|
|
|
|
|
class ObjectParser:
|
|
object: BaseObject = None
|
|
|
|
@classmethod
|
|
def from_json(cls, serialized: Text) -> BaseObject:
|
|
return cls.object.parse_raw(serialized)
|
|
|
|
@classmethod
|
|
def from_dict(cls, serialized: MutableMapping[str, Any]) -> BaseObject:
|
|
return cls.object.parse_obj(serialized)
|
|
|
|
@classmethod
|
|
def from_toml(cls, serialized: Text) -> BaseObject:
|
|
dct = toml.loads(serialized)
|
|
return cls.from_dict(dct)
|
|
|
|
@classmethod
|
|
def from_toml_file(cls, path) -> BaseObject:
|
|
dct = toml.load(path)
|
|
return cls.from_dict(dct)
|
|
|
|
@classmethod
|
|
def to_dict(cls, obj: BaseObject) -> dict:
|
|
return obj.dict()
|
|
|
|
|
|
class FlowParser(ObjectParser):
|
|
object = Flow
|