5
5
python -m odml.tools.xmlparser file.odml
6
6
"""
7
7
import csv
8
+ import sys
8
9
from lxml import etree as ET
9
10
from lxml .builder import E
10
11
# this is needed for py2exe to include lxml completely
11
12
from lxml import _elementpath as _dummy
12
- import sys
13
13
14
14
try :
15
15
from StringIO import StringIO
@@ -118,10 +118,9 @@ def write_file(self, filename):
118
118
else :
119
119
data = str (self )
120
120
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 )
125
124
126
125
127
126
def load (filename ):
@@ -260,8 +259,6 @@ def parse_tag(self, root, fmt, insert_children=True):
260
259
else :
261
260
tag = fmt .map (node .tag )
262
261
if tag in arguments :
263
- # TODO make this an error, however first figure out a
264
- # way to let <odML version=><version/> pass
265
262
self .warn ("Element <%s> is given multiple times in "
266
263
"<%s> tag" % (node .tag , root .tag ), node )
267
264
@@ -277,20 +274,19 @@ def parse_tag(self, root, fmt, insert_children=True):
277
274
% (node .tag , root .tag ), node )
278
275
279
276
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 ()))
283
278
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 )
287
282
288
283
# Instantiate the current odML object with the parsed attributes.
289
284
obj = fmt .create (** arguments )
290
285
291
286
if insert_children :
292
287
for child in children :
293
288
obj .append (child )
289
+
294
290
return obj
295
291
296
292
def parse_odML (self , root , fmt ):
0 commit comments