From 394bfb508f11f949336723412164a86c185ba024 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 3 Feb 2022 07:59:33 +0100 Subject: [PATCH] Scripts: Fix output for python 3 Change-Id: Ie914e04b25bdd4e41a9d2b3a9002385f5867ad6b Reviewed-by: Eike Ziller --- scripts/uichanges.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/uichanges.py b/scripts/uichanges.py index 0dcc054a8f3..126cbfc9a31 100755 --- a/scripts/uichanges.py +++ b/scripts/uichanges.py @@ -181,6 +181,15 @@ def diffContext(ctx, old, new): return report + +def stringify(obj): + stringTypes = (str, unicode) if sys.version_info.major == 2 else (str) + if isinstance(obj, stringTypes): + return obj + if isinstance(obj, bytes): + tmp = obj.decode('cp1252') if platform.system() in ('Microsoft','Windows') else obj.decode() + return tmp + # --- The main program oldGenerator = Generator() @@ -203,21 +212,21 @@ newContextSet = set(newTree.keys()) for c in sorted(oldContextSet.difference(newContextSet)): report = diffContext(c, oldTree[c], {}) if report: - print(report.encode('utf-8')) + print(stringify(report.encode('utf-8'))) else: unchangedContexts += 1 for c in sorted(newContextSet.difference(oldContextSet)): report = diffContext(c, {}, newTree[c]) if report: - print(report.encode('utf-8')) + print(stringify(report.encode('utf-8'))) else: unchangedContexts += 1 for c in sorted(newContextSet.intersection(oldContextSet)): report = diffContext(c, oldTree[c], newTree[c]) if report: - print(report.encode('utf-8')) + print(stringify(report.encode('utf-8'))) else: unchangedContexts += 1