55 python -m odml.tools.xmlparser file.odml
66"""
77import csv
8+ import sys
89from lxml import etree as ET
910from lxml .builder import E
1011# this is needed for py2exe to include lxml completely
1112from lxml import _elementpath as _dummy
12- import sys
1313
1414try :
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
127126def 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