Skip to content

Commit 927738e

Browse files
digaru19achilleas-k
authored andcommitted
to_string method in odmlparser
1 parent 405a658 commit 927738e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

odml/tools/odmlparser.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,26 @@ def get_values(self, value_list):
122122
return value_seq
123123

124124
def write_file(self, odml_document, filename):
125+
file = open(filename, 'w')
126+
file.write(self.to_string(odml_document))
127+
file.close()
128+
129+
def to_string(self, odml_document):
130+
string_doc = ''
125131

126132
if self.parser == 'XML' or self.parser == 'ODML':
127-
xmlparser.XMLWriter(odml_document).write_file(filename)
133+
string_doc = str(xmlparser.XMLWriter(odml_document))
128134
else:
129135
self.to_dict(odml_document)
130136
odml_output = {}
131137
odml_output['Document'] = self.parsed_doc
132138
odml_output['odml-version'] = odml_version
133139

134-
f = open(filename, 'w')
135140
if self.parser == 'YAML':
136-
f.write(yaml.dump(odml_output, default_flow_style=False))
141+
string_doc = yaml.dump(odml_output, default_flow_style=False)
137142
elif self.parser == 'JSON':
138-
f.write(json.dumps(odml_output, indent=4))
139-
f.close()
143+
string_doc = json.dumps(odml_output, indent=4)
144+
return string_doc
140145

141146

142147
class ODMLReader:
@@ -253,7 +258,7 @@ def parse_values(self, value_list):
253258
return odml_values
254259

255260

256-
def fromFile(self, file):
261+
def from_file(self, file):
257262

258263
if self.parser == 'XML' or self.parser == 'ODML':
259264
odml_doc = xmlparser.XMLReader().fromFile(file)
@@ -281,7 +286,7 @@ def fromFile(self, file):
281286
return self.to_odml()
282287

283288

284-
def fromString(self, string):
289+
def from_string(self, string):
285290

286291
if self.parser == 'XML' or self.parser == 'ODML':
287292
odml_doc = xmlparser.XMLReader().fromString(string)

0 commit comments

Comments
 (0)