forked from pool/rpmlint
OBS-URL: https://build.opensuse.org/package/show/devel:openSUSE:Factory:rpmlint/rpmlint?expand=0&rev=373
This commit is contained in:
parent
6b2de62510
commit
bd5a563be3
@ -1,28 +1,20 @@
|
||||
From 6d0278d1fb39426467f79ec5bd1637b2d95cca3b Mon Sep 17 00:00:00 2001
|
||||
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] Avoid messing with the error encoding (Fixes #61)
|
||||
Subject: [PATCH] Solve exceptions on printing str (Fixes #61)
|
||||
|
||||
Rather than doing something different in the tty/non-tty case,
|
||||
just call print() directly, which does the right thing without
|
||||
throwing exceptions.
|
||||
Handle printing of str gracefully by first encoding
|
||||
it to unicode before printing it in the proper encoding.
|
||||
Also fix python2 check.
|
||||
---
|
||||
Filter.py | 24 ++++--------------------
|
||||
1 file changed, 4 insertions(+), 20 deletions(-)
|
||||
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
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import locale
|
||||
-import sys
|
||||
import textwrap
|
||||
|
||||
import Config
|
||||
@@ -24,21 +23,6 @@ _diagnostic = list()
|
||||
@@ -24,20 +24,20 @@ _diagnostic = list()
|
||||
_badness_score = 0
|
||||
printed_messages = {"I": 0, "W": 0, "E": 0}
|
||||
|
||||
@ -37,39 +29,22 @@ Index: rpmlint-rpmlint-1.8/Filter.py
|
||||
- __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):
|
||||
_print("I", pkg, reason, details)
|
||||
@@ -90,7 +74,7 @@ def _print(msgtype, pkg, reason, details
|
||||
if threshold >= 0:
|
||||
_diagnostic.append(s + "\n")
|
||||
else:
|
||||
- __print(s)
|
||||
+ print(s)
|
||||
if Config.info:
|
||||
printDescriptions(reason)
|
||||
return True
|
||||
@@ -102,8 +86,8 @@ def printDescriptions(reason):
|
||||
try:
|
||||
d = _details[reason]
|
||||
if d and d != '' and d != "\n":
|
||||
- __print(textwrap.fill(d, 78))
|
||||
- __print("")
|
||||
+ print(textwrap.fill(d, 78))
|
||||
+ print("")
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@@ -128,7 +112,7 @@ def printAllReasons():
|
||||
if len(last_reason):
|
||||
printDescriptions(last_reason)
|
||||
last_reason = reason
|
||||
- __print(diag[:-1])
|
||||
+ print(diag[:-1])
|
||||
if Config.info and len(last_reason):
|
||||
printDescriptions(last_reason)
|
||||
_diagnostic = list()
|
||||
|
Loading…
Reference in New Issue
Block a user