From 0f85c5c360f2f9f32614a5e47da27666dd1e12a1 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 29 Jan 2010 18:48:32 +0000 Subject: [PATCH] Fix output handling to avoid potential UnicodeEncodeError. (trunk r15196) svn path=/main/branches/2.1.7/; revision=15250 --- bin/check-implicit-pointer-usage.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/check-implicit-pointer-usage.py b/bin/check-implicit-pointer-usage.py index ebd4c3629..1f6417b58 100755 --- a/bin/check-implicit-pointer-usage.py +++ b/bin/check-implicit-pointer-usage.py @@ -37,15 +37,20 @@ if sys.hexversion < 0x3000000: pointer_pattern = unicode(pointer_pattern, encoding='utf_8') unicode_quote_open = unicode('\xE2\x80\x98', encoding='utf_8') unicode_quote_close = unicode('\xE2\x80\x99', encoding='utf_8') + out = sys.stdout else: unicode_quote_open = '\u2018' unicode_quote_close = '\u2019' + out = sys.stdout.buffer pointer_pattern = re.compile(pointer_pattern) last_implicit_filename = "" last_implicit_linenum = -1 last_implicit_func = "" +def write(msg): + out.write(msg.encode('utf_8', 'backslashreplace')) + while True: if sys.hexversion >= 0x3000000: line = sys.stdin.buffer.readline().decode('utf_8', 'replace') @@ -69,6 +74,7 @@ while True: pointer_linenum = int(m.group(2)) if (last_implicit_filename == pointer_filename and last_implicit_linenum == pointer_linenum): - print(("Function `%s' implicitly converted to pointer at " \ - "%s:%d" % (last_implicit_func, last_implicit_filename, - last_implicit_linenum))) + write("Function `%s' implicitly converted to pointer at " \ + "%s:%d\n" % (last_implicit_func, + last_implicit_filename, + last_implicit_linenum)) -- 2.26.2