diff -Nurd itstool-2.0.6.orig/itstool.in itstool-2.0.6/itstool.in --- itstool-2.0.6.orig/itstool.in 2018-11-08 13:11:00.000000000 -0500 +++ itstool-2.0.6/itstool.in 2021-01-13 00:58:48.000000000 -0500 @@ -44,9 +44,25 @@ else: return str(s) ustr_type = str + def pr_str(s): + """Return a string that can be safely print()ed""" + # Since print works on both bytes and unicode, just return the argument + return s + uout = sys.stdout else: string_types = basestring, ustr = ustr_type = unicode + def pr_str(s): + """Return a string that can be safely print()ed""" + if isinstance(s, str): + # Since print works on str, just return the argument + return s + else: + # print may not work on unicode if the output encoding cannot be + # detected, so just encode with UTF-8 + return unicode.encode(s, 'utf-8') + import codecs + uout = codecs.getwriter('utf-8')(sys.stdout) NS_ITS = 'http://www.w3.org/2005/11/its' NS_ITST = 'http://itstool.org/extensions/' @@ -1060,9 +1076,9 @@ if strict: raise else: - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % ( + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % ( (lang + ' ') if lang is not None else '', - msgstr.encode('utf-8'))) + msgstr))) self._xml_err = '' return node def scan_node(node): @@ -1087,9 +1103,9 @@ if strict: raise else: - sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % ( + sys.stderr.write(pr_str('Warning: Could not merge %stranslation for msgid:\n%s\n' % ( (lang + ' ') if lang is not None else '', - msgstr.encode('utf-8'))) + msgstr))) self._xml_err = '' ctxt.doc().freeDoc() return node @@ -1552,7 +1568,7 @@ if opts.test is None: doc.generate_messages() if opts.output is None or opts.output == '-': - out = sys.stdout + out = uout else: try: out = io.open(opts.output, 'wt', encoding='utf-8')