Browse Source

Allow asciify to deal with instances of unicode

master
Sebastian Pipping 11 years ago
parent
commit
bb880e494b
  1. 11
      client-barcode/freitagslib/encoding.py

11
client-barcode/freitagslib/encoding.py

@ -6,7 +6,14 @@ @@ -6,7 +6,14 @@
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 = (
('ö', 'oe'),
('Ö', 'Oe'),
@ -26,7 +33,7 @@ def asciify(utf8): @@ -26,7 +33,7 @@ def asciify(utf8):
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)
return unitext.encode('ascii')

Loading…
Cancel
Save