Update utils.latinify to support Python 3

This commit is contained in:
Domenic Barbuzzi 2019-10-01 12:11:11 -04:00
parent 1115a941c1
commit 96d5734e51
2 changed files with 40 additions and 1 deletions

View file

@ -761,7 +761,10 @@ _UNICODE_MAP = {
"EN DASH": "-",
"HORIZONTAL BAR": "-",
"HORIZONTAL ELLIPSIS": "...",
"LEFT SINGLE QUOTATION MARK": "'",
"RIGHT SINGLE QUOTATION MARK": "'",
"LEFT DOUBLE QUOTATION MARK": '"',
"RIGHT DOUBLE QUOTATION MARK": '"',
}
@ -788,10 +791,13 @@ def latinify(string, default="?", pure_ascii=False):
from unicodedata import name
if isinstance(string, bytes):
string = string.decode("utf8")
converted = []
for unich in iter(string):
try:
ch = unich.decode("ascii")
ch = unich.encode("utf8").decode("ascii")
except UnicodeDecodeError:
# deduce a latin letter equivalent from the Unicode data
# point name; e.g., since `name(u'á') == 'LATIN SMALL