From: W. Trevor King Date: Sun, 22 Aug 2010 13:34:37 +0000 (-0400) Subject: Add hooke.util.yaml.data_constructor to rebuild hooke.curve.Data.info. X-Git-Url: http://git.tremily.us/?p=hooke.git;a=commitdiff_plain;h=838af47943e082c6e09d120d7a5244943195e9b8 Add hooke.util.yaml.data_constructor to rebuild hooke.curve.Data.info. --- diff --git a/hooke/util/yaml.py b/hooke/util/yaml.py index e7f9980..46d6e2a 100644 --- a/hooke/util/yaml.py +++ b/hooke/util/yaml.py @@ -54,12 +54,16 @@ import types import numpy import yaml import yaml.constructor +from yaml.constructor import ConstructorError import yaml.representer from ..curve import Data, Curve from ..playlist import FilePlaylist +DATA_INFO_TAG = u'!hooke.curve.DataInfo' + + if False: # YAML dump debugging code """To help isolate data types etc. that give YAML problems. @@ -120,9 +124,14 @@ def data_representer(dumper, data): for key in info.keys(): if key.startswith('raw '): del(info[key]) - return dumper.represent_mapping(u'!hooke.curve.DataInfo', info) + return dumper.represent_mapping(DATA_INFO_TAG, info) yaml.add_representer(Data, data_representer) +def data_constructor(loader, node): + info = loader.construct_mapping(node) + return Data(shape=(0,0), dtype=numpy.float32, info=info) +yaml.add_constructor(DATA_INFO_TAG, data_constructor) + def object_representer(dumper, data): cls = type(data) if cls in copy_reg.dispatch_table: