Skip to content
Snippets Groups Projects
Commit 13425e4e authored by Florian Ziemen's avatar Florian Ziemen
Browse files

basic serialization and deserialization

parent ba835122
No related branches found
No related tags found
No related merge requests found
Pipeline #53461 passed with warnings
import utils
import logging
from collections.abc import Sequence
......@@ -17,6 +15,9 @@ class dataset_location:
def is_valid(self) -> bool:
return all(x is not None for x in vars(self).values())
def serialize(self):
return vars(self)
class dataset:
def __init__(
......@@ -31,7 +32,18 @@ class dataset:
def is_valid(self) -> bool:
return (
all(x is not None for x in vars(self).values())
and type(self.serve) is bool
and isinstance(self.serve, bool)
and all(type(x) is dataset_location for x in self.locations)
and all(x.is_valid() for x in self.locations)
)
def serialize(self):
rd = dict(self.vars())
rd["locations"] = set(x.serialize() for x in self.locations)
return rd
def from_dict(the_dict):
locations = set(dataset_location(**x) for x in the_dict["locations"])
return dataset(
name=the_dict["name"], serve=the_dict["serve"], locations=locations
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment