Skip to content

Commit 37b32dc

Browse files
committed
[tools/dictparser] Properly handle attribute maps
- Always use the odml format arguments key attribute name when saving. - Always use the mapped odml format attribute name when loading.
1 parent eeff592 commit 37b32dc

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

odml/tools/dict_parser.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def to_dict(self, odml_document):
3333
tag = getattr(odml_document, attr)
3434

3535
if tag:
36-
parsed_doc[attr] = tag
36+
# Always use the arguments key attribute name when saving
37+
parsed_doc[i] = tag
3738

3839
return parsed_doc
3940

@@ -60,7 +61,8 @@ def get_sections(self, section_list):
6061
tag = getattr(section, attr)
6162

6263
if tag:
63-
section_dict[attr] = tag
64+
# Always use the arguments key attribute name when saving
65+
section_dict[i] = tag
6466

6567
section_seq.append(section_dict)
6668

@@ -89,7 +91,8 @@ def get_properties(props_list):
8991
prop.dtype.endswith("-tuple") and len(prop.value) > 0:
9092
prop_dict["value"] = "(%s)" % ";".join(prop.value[0])
9193
else:
92-
prop_dict[attr] = tag
94+
# Always use the arguments key attribute name when saving
95+
prop_dict[i] = tag
9396

9497
props_seq.append(prop_dict)
9598

@@ -143,7 +146,8 @@ def to_odml(self, parsed_doc):
143146
if attr == 'sections':
144147
doc_secs = self.parse_sections(self.parsed_doc['sections'])
145148
elif attr:
146-
doc_attrs[i] = self.parsed_doc[i]
149+
# Make sure to always use the correct odml format attribute name
150+
doc_attrs[odmlfmt.Document.map(attr)] = self.parsed_doc[i]
147151

148152
doc = odmlfmt.Document.create(**doc_attrs)
149153
for sec in doc_secs:
@@ -166,7 +170,8 @@ def parse_sections(self, section_list):
166170
elif attr == 'sections':
167171
children_secs = self.parse_sections(section['sections'])
168172
elif attr:
169-
sec_attrs[attr] = section[attr]
173+
# Make sure to always use the correct odml format attribute name
174+
sec_attrs[odmlfmt.Section.map(attr)] = section[attr]
170175

171176
sec = odmlfmt.Section.create(**sec_attrs)
172177
for prop in sec_props:
@@ -188,7 +193,8 @@ def parse_properties(self, props_list):
188193
for i in _property:
189194
attr = self.is_valid_attribute(i, odmlfmt.Property)
190195
if attr:
191-
prop_attrs[attr] = _property[attr]
196+
# Make sure to always use the correct odml format attribute name
197+
prop_attrs[odmlfmt.Property.map(attr)] = _property[attr]
192198

193199
prop = odmlfmt.Property.create(**prop_attrs)
194200
odml_props.append(prop)

0 commit comments

Comments
 (0)