Allow asciify to deal with instances of unicode
This commit is contained in:
parent
bb468f25bf
commit
bb880e494b
|
@ -6,7 +6,14 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
def asciify(utf8):
|
def ensure_unicode(candidate, encoding='utf-8'):
|
||||||
|
if isinstance(candidate, basestring) \
|
||||||
|
and not isinstance(candidate, unicode):
|
||||||
|
return unicode(candidate, encoding)
|
||||||
|
return candidate
|
||||||
|
|
||||||
|
|
||||||
|
def asciify(text):
|
||||||
_mapping = (
|
_mapping = (
|
||||||
('ö', 'oe'),
|
('ö', 'oe'),
|
||||||
('Ö', 'Oe'),
|
('Ö', 'Oe'),
|
||||||
|
@ -26,7 +33,7 @@ def asciify(utf8):
|
||||||
|
|
||||||
return _mapping.get(ord(unichar), fix(unichar))
|
return _mapping.get(ord(unichar), fix(unichar))
|
||||||
|
|
||||||
unichars = utf8.decode('utf-8')
|
unichars = ensure_unicode(text, 'utf-8')
|
||||||
unitext = ''.join(subst(e) for e in unichars)
|
unitext = ''.join(subst(e) for e in unichars)
|
||||||
return unitext.encode('ascii')
|
return unitext.encode('ascii')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue