cherry picked cb5d027b about context managers
[nepi.git] / src / nepi / resources / omf / omf6_parser.py
index 6e72077..68786b6 100644 (file)
@@ -3,9 +3,8 @@
 #    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -176,7 +175,7 @@ class OMF6Parser(Logger):
         event = self._check_for_tag(root, namespaces, "event")
 
         log = "STATUS -- "
-        for elt in props.keys():
+        for elt in props:
             ns, tag = elt.split('}')
             if tag == "it":
                 log = log + "membership : " + props[elt]+" -- "
@@ -186,18 +185,16 @@ class OMF6Parser(Logger):
             elif tag == "msg":
                 if event == "STDOUT" : 
                     filename = os.path.join("/tmp", "%s.out" % uid)
-                    f = open(filename,'a+')
-                    # XXX: Adding fake \n for visual formatting 
-                    msg = props[elt] + "\n"
-                    f.write(msg)
-                    f.close()
+                    with open(filename,'a+') as f:
+                        # XXX: Adding fake \n for visual formatting 
+                        msg = props[elt] # + "\n"
+                        f.write(msg)
                 elif event == "STDERR" :
                     filename = os.path.join("/tmp", "%s.err" % uid)
-                    f = open(filename,'a+')
-                    # XXX: Adding fake \n for visual formatting 
-                    msg = props[elt] + "\n"
-                    f.write(msg)
-                    f.close()
+                    with open(filename,'a+') as f:
+                        # XXX: Adding fake \n for visual formatting 
+                        msg = props[elt] # + "\n"
+                        f.write(msg)
                 log = log + tag +" : " + props[elt]+" -- "
             else:
                 log = log + tag +" : " + props[elt]+" -- "