fixes
authorVolker Birk <vb@pep-project.org>
Fri, 11 Oct 2019 21:38:48 +0200
changeset 32 2b7b48758eaa
parent 31 d3dddb80d1f5
child 33 12c0bdcb709d
fixes
backend.py
yml2c
yml2proc
--- a/backend.py	Mon Sep 23 19:25:58 2019 +0200
+++ b/backend.py	Fri Oct 11 21:38:48 2019 +0200
@@ -246,7 +246,7 @@
             hasContent = True
         resultParms = self.values.copy()
         macros = self.macros.copy()
-        toDelete = resultParms.keys()
+        toDelete = [ key for key in resultParms.keys() ]
         for key in toDelete:
             if key[0] == "*":
                 del resultParms[key]
--- a/yml2c	Mon Sep 23 19:25:58 2019 +0200
+++ b/yml2c	Fri Oct 11 21:38:48 2019 +0200
@@ -20,10 +20,7 @@
 
 def w(msg):
     if isinstance(msg, BaseException):
-        try:
-            msg = str(msg) + "\n"
-        except:
-            msg = u(msg) + u"\n"
+        msg = str(msg) + "\n"
     if type(msg) is bytes:
         msg = codecs.encode(msg, sys.stderr.encoding)
     sys.stderr.write(msg)
@@ -87,10 +84,10 @@
     w("\n")
     sys.exit(1)
 except KeyError as msg:
-    w(u"not found: " + u(msg) + u"\n")
+    w("not found: " + u(msg) + "\n")
     sys.exit(4)
 except LookupError as msg:
-    w(u"not found: " + u(msg) + u"\n")
+    w("not found: " + u(msg) + "\n")
     sys.exit(4)
 except Exception as msg:
     w(msg)
--- a/yml2proc	Mon Sep 23 19:25:58 2019 +0200
+++ b/yml2proc	Fri Oct 11 21:38:48 2019 +0200
@@ -32,9 +32,7 @@
         try:
             msg = str(msg) + "\n"
         except:
-            msg = u(msg) + u"\n"
-    if type(msg) is str:
-        msg = codecs.encode(msg, sys.stderr.encoding)
+            msg = u(msg) + "\n"
     sys.stderr.write(msg)
 
 optParser = OptionParser()
@@ -114,7 +112,7 @@
 try:
     ymlC = ymlCStyle()
 
-    rtext = u""
+    rtext = ""
 
     if not options.emptyinput:
         files = fileinput.input(args, mode="rU", openhook=fileinput.hook_encoded(options.encoding))
@@ -132,7 +130,7 @@
                 rtext = backend.finish(result)
 
     if not rtext:
-        rtext = u"<empty/>"
+        rtext = "<empty/>"
 
     def ymldebug(context, text):
         if options.trace:
@@ -153,7 +151,7 @@
     if options.xpath:
         tree = etree.fromstring(rtext)
         ltree = tree.xpath(codecs.decode(options.xpath, options.encoding))
-        rtext = u""
+        rtext = ""
         try:
             for rtree in ltree:
                 rtext += etree.tostring(rtree, pretty_print=options.pretty, encoding=unicode)
@@ -186,7 +184,7 @@
                     params[key] = u(value)
         if options.stringparams:
             for key, value in eval(options.stringparams).iteritems():
-                params[key] = u"'" + u(value) + u"'"
+                params[key] = "'" + u(value) + "'"
 
         rresult = transform(doc, **params)
         # lxml is somewhat buggy
@@ -226,18 +224,18 @@
     w("\n")
     sys.exit(1)
 except YMLAssert as msg:
-    w(u"YML Assertion failed: " + u(msg) + u"\n")
+    w("YML Assertion failed: " + u(msg) + "\n")
     sys.exit(2)
 except KeyError as msg:
-    w(u"not found: " + u(msg) + u"\n")
+    w("not found: " + u(msg) + "\n")
     sys.exit(4)
 except LookupError as msg:
-    w(u"not found: " + u(msg) + u"\n")
+    w("not found: " + u(msg) + "\n")
     sys.exit(4)
 except etree.XMLSyntaxError as e:
     log = e.error_log.filter_from_level(etree.ErrorLevels.FATAL)
     for entry in log:
-        w(u"XML error: " + u(entry.message) + u"\n")
+        w("XML error: " + u(entry.message) + "\n")
     sys.exit(5)
 except Exception as msg:
     w(msg)