mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-03 15:15:02 +03:00
Add a method to convert str to ascii in Python 3
This commit is contained in:
parent
1a4219b208
commit
54b61fd5a0
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user