avoid formatting binary strings
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 1 Dec 2017 15:14:56 +0000 (16:14 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 5 Nov 2018 11:16:39 +0000 (12:16 +0100)
Postpone bytes conversion of CNF-encoded objects until the last
moment to work around missing interpolation of bytes objects in
Python 3.3 (the version still in use on the Intranator).

Reference: https://bufs.python.org/issue3982

src/cnfvar.py

index 6b7c267..6428141 100644 (file)
@@ -552,10 +552,9 @@ def renumber_vars(root, parent=None):
 #                                serialization
 #
 
-cnf_line_nest_indent = b"  "
-cnf_line_base_fmt    = b"%d %s,%d: \"%s\""
-cnf_line_child_fmt   = b"%d %s(%d) %s,%d: \"%s\""
-
+cnf_line_nest_indent = "  "
+cnf_line_base_fmt    = "%d %s,%d: \"%s\""
+cnf_line_child_fmt   = "%d %s(%d) %s,%d: \"%s\""
 
 def format_cnf_vars(da, var):
     """
@@ -567,27 +566,28 @@ def format_cnf_vars(da, var):
     if depth > 0:
         line = cnf_line_child_fmt \
             % (var["number"],
-               cnf_line_nest_indent * depth,
-               var["parent"],
-               to_latin1(var["varname"]),
-               var["instance"],
-               to_latin1(var["data"]))
+            cnf_line_nest_indent * depth,
+            var["parent"],
+            var["varname"],
+            var["instance"],
+            var["data"])
     else:
         line = cnf_line_base_fmt \
             % (var["number"],
-               to_latin1(var["varname"]),
-               var["instance"],
-               to_latin1(var["data"]))
+            var["varname"],
+            var["instance"],
+            var["data"])
 
     comment = var.get("comment", None)
     if comment and len (comment) != 0:
-        line = line + (b" # %s" % to_latin1(comment))
+        line = line + (" # %s" % comment)
 
-    acc.append(line)
+    acc.append(to_latin1 (line))
 
     children = var.get("children", None)
     if children is not None:
         (_, acc) = functools.reduce(format_cnf_vars, children, (depth + 1, acc))
+
     return (depth, acc)
 
 
@@ -656,7 +656,7 @@ def dump_cnf_string(root, renumber=False):
 
 def print_cnf(root, out=None, renumber=False):
     if root is not None:
-        output_cnf(root, out or sys.stdout, renumber=renumber, bytes=False)
+        output_cnf(root, out or sys.stdout, renumber=renumber)
 
 
 def write_cnf(*argv, **kw_argv):