Source code for core.control.serialization

from .control import Control
from .pyserial import serialize_controls
from openalea.core.serialization import AbstractSaver, AbstractLoader, AbstractDeserializer


class ControlSerializer(object):
[docs] def serialize(self, obj, protocol=None, **kwds):
[docs] if isinstance(obj, Control): obj = [obj] return serialize_controls(obj) class ControlDeserializer(AbstractDeserializer):
[docs] def deserialize(self, lines, protocol=None, **kwds):
[docs] ns = {} for l in lines: try: exec l in ns except: pass controls = ns.get('controls', []) return controls class ControlSaver(AbstractSaver):
[docs] dtype = 'IControl' protocols = ['text/x-python'] def _serialize(self, obj, protocol, **kwds): serializer = ControlSerializer() return serializer.serialize(obj, protocol=protocol, **kwds) class ControlLoader(AbstractLoader):
[docs] dtype = 'IControl' protocols = ['text/x-python'] def _deserialize(self, lines, protocol, **kwds): serializer = ControlDeserializer() return serializer.deserialize(lines, protocol=protocol, **kwds)