From 0a5772cbb762ec7aabb1ba52c70d4c4c967eb699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 4 Jul 2015 10:48:36 +0300 Subject: [PATCH] More python 3 fixing --- Filter.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Filter.py b/Filter.py index eaa8384b..1c3bfe25 100644 --- a/Filter.py +++ b/Filter.py @@ -7,6 +7,7 @@ # Purpose : filter the output of rpmlint to allow exceptions. ############################################################################# +from __future__ import print_function import locale import sys import textwrap @@ -27,10 +28,15 @@ if sys.stdout.isatty(): def __print(s): print(s) else: + __stdout = sys.stdout + if not __stdout.encoding: # Python < 3 only? + import codecs + if hasattr(__stdout, "buffer"): + __stdout = __stdout.buffer + __stdout = codecs.getwriter( + locale.getpreferredencoding())(__stdout, "replace") def __print(s): - if isinstance(s, unicode): - s = s.encode(locale.getpreferredencoding(), "replace") - print(s) + print(s, file=__stdout) def printInfo(pkg, reason, *details): @@ -75,7 +81,8 @@ def _print(msgtype, pkg, reason, details): Testing.addOutput(s) else: if _rawout: - print >>_rawout, s.encode(locale.getpreferredencoding(), "replace") + print(s.encode(locale.getpreferredencoding(), "replace"), + file=_rawout) if not Config.isFiltered(s): printed_messages[msgtype] += 1 _badness_score += badness