Skip to content

Commit 76c6816

Browse files
committed
[xmlparser] Code cleanup
1 parent dfab3fc commit 76c6816

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

odml/tools/xmlparser.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
python -m odml.tools.xmlparser file.odml
66
"""
77
import csv
8+
import sys
89
from lxml import etree as ET
910
from lxml.builder import E
1011
# this is needed for py2exe to include lxml completely
1112
from lxml import _elementpath as _dummy
12-
import sys
1313

1414
try:
1515
from StringIO import StringIO
@@ -118,10 +118,9 @@ def write_file(self, filename):
118118
else:
119119
data = str(self)
120120

121-
f = open(filename, "w")
122-
f.write(self.header)
123-
f.write(data)
124-
f.close()
121+
with open(filename, "w") as file:
122+
file.write(self.header)
123+
file.write(data)
125124

126125

127126
def load(filename):
@@ -260,8 +259,6 @@ def parse_tag(self, root, fmt, insert_children=True):
260259
else:
261260
tag = fmt.map(node.tag)
262261
if tag in arguments:
263-
# TODO make this an error, however first figure out a
264-
# way to let <odML version=><version/> pass
265262
self.warn("Element <%s> is given multiple times in "
266263
"<%s> tag" % (node.tag, root.tag), node)
267264

@@ -277,20 +274,19 @@ def parse_tag(self, root, fmt, insert_children=True):
277274
% (node.tag, root.tag), node)
278275

279276
if sys.version_info > (3,):
280-
self.check_mandatory_arguments(dict(list(arguments.items()) +
281-
list(extra_args.items())),
282-
fmt, root.tag, root)
277+
check_args = dict(list(arguments.items()) + list(extra_args.items()))
283278
else:
284-
self.check_mandatory_arguments(dict(arguments.items() +
285-
extra_args.items()),
286-
fmt, root.tag, root)
279+
check_args = dict(arguments.items() + extra_args.items())
280+
281+
self.check_mandatory_arguments(check_args, fmt, root.tag, root)
287282

288283
# Instantiate the current odML object with the parsed attributes.
289284
obj = fmt.create(**arguments)
290285

291286
if insert_children:
292287
for child in children:
293288
obj.append(child)
289+
294290
return obj
295291

296292
def parse_odML(self, root, fmt):

0 commit comments

Comments
 (0)