SHA256
1
0
forked from pool/rpmlint
rpmlint/0001-Avoid-messing-with-the-error-encoding-Fixes-61.patch

51 lines
1.6 KiB
Diff

From 8169818dbad3f8f6fccbc7e3de99e86b37ad45f6 Mon Sep 17 00:00:00 2001
From: Dirk Mueller <dirk@dmllr.de>
Date: Mon, 22 Feb 2016 09:12:39 +0100
Subject: [PATCH] Solve exceptions on printing str (Fixes #61)
Handle printing of str gracefully by first encoding
it to unicode before printing it in the proper encoding.
Also fix python2 check.
---
Filter.py | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
Index: rpmlint-rpmlint-1.8/Filter.py
===================================================================
--- rpmlint-rpmlint-1.8.orig/Filter.py
+++ rpmlint-rpmlint-1.8/Filter.py
@@ -24,20 +24,20 @@ _diagnostic = list()
_badness_score = 0
printed_messages = {"I": 0, "W": 0, "E": 0}
-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")
+__stdout = sys.stdout
+__preferred_encoding = locale.getpreferredencoding()
+if hasattr(__stdout, 'xreadlines'): # Python < 3 only
+ import codecs
+ if hasattr(__stdout, "buffer"):
+ __stdout = __stdout.buffer
+ __stdout = codecs.getwriter(
+ __preferred_encoding)(sys.stdout, 'replace')
- def __print(s):
- print(s, file=__stdout)
+
+def __print(s):
+ if isinstance(s, str) and hasattr(s, 'decode'):
+ s = s.decode(__preferred_encoding, 'replace')
+ print(s, file=__stdout)
def printInfo(pkg, reason, *details):