From 54b61fd5a090061b1016e1fee115c6808bbb06ed Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 16 Dec 2017 15:05:06 +0100 Subject: [PATCH] Add a method to convert str to ascii in Python 3 --- glances/compat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/glances/compat.py b/glances/compat.py index f191c0a4..1a646d01 100644 --- a/glances/compat.py +++ b/glances/compat.py @@ -64,7 +64,9 @@ if PY3: def to_ascii(s): """Convert the bytes string to a ASCII string Usefull to remove accent (diacritics)""" - return str(s, 'utf-8') + if isinstance(s, binary_type): + return s + return s.encode('ascii', 'ignore') def listitems(d): return list(d.items()) @@ -124,7 +126,7 @@ else: Usefull to remove accent (diacritics)""" if isinstance(s, binary_type): return s - return unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore') + return unicodedata.normalize('NFKD', s).encode('ascii', 'ignore') def listitems(d): return d.items() -- GitLab