35 lines
1.1 KiB
Diff
35 lines
1.1 KiB
Diff
|
From 8fd904b53c028dded0b308ee95f1a5ff998584fd Mon Sep 17 00:00:00 2001
|
||
|
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
||
|
Date: Thu, 4 Jul 2019 00:31:49 +0200
|
||
|
Subject: [PATCH] Ugly workaround for RPM 4.14 vs 4.15 python3 bindings
|
||
|
incompatibility
|
||
|
|
||
|
Fixes https://github.com/rpm-software-management/rpmlint/issues/202
|
||
|
---
|
||
|
Pkg.py | 11 ++++++++++-
|
||
|
1 file changed, 10 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/Pkg.py b/Pkg.py
|
||
|
index 8d01f301..1b257716 100644
|
||
|
--- a/Pkg.py
|
||
|
+++ b/Pkg.py
|
||
|
@@ -143,8 +143,17 @@ def is_utf8(fname):
|
||
|
|
||
|
|
||
|
def is_utf8_bytestr(s):
|
||
|
+ """Returns True whether the given text is UTF-8.
|
||
|
+ Due to changes in rpm, needs to handle both bytes and unicode."""
|
||
|
try:
|
||
|
- s.decode('UTF-8')
|
||
|
+ if hasattr(s, 'decode'):
|
||
|
+ s.decode('utf-8')
|
||
|
+ elif hasattr(s, 'encode'):
|
||
|
+ s.encode('utf-8')
|
||
|
+ else:
|
||
|
+ unexpected = type(s).__name__
|
||
|
+ raise TypeError(
|
||
|
+ 'Expected str/unicode/bytes, not {}'.format(unexpected))
|
||
|
except UnicodeError:
|
||
|
return False
|
||
|
return True
|