X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/538526fc82b771cbc149743f129d8b1ae7e3cba2..4e361d55331351f56077e5f9999ecb4ee7e93819:/src/sortify.py diff --git a/src/sortify.py b/src/sortify.py index 61cb9d892..58807bb01 100644 --- a/src/sortify.py +++ b/src/sortify.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import re from fnpdjango.utils.text import char_map @@ -6,7 +5,7 @@ from fnpdjango.utils.text import char_map # Specifies diacritics order. # Default order is zero, max is 9 char_order = { - u'ż': 1, u'Ż': 1, + 'ż': 1, 'Ż': 1, } @@ -33,12 +32,12 @@ def sortify(value): """ - if not isinstance(value, unicode): - value = unicode(value, 'utf-8') + if not isinstance(value, str): + value = str(value, 'utf-8') # try to replace chars value = re.sub('[^a-zA-Z0-9\\s\\-]', replace_char, value) value = value.lower() value = re.sub(r'[^a-z0-9~]+', ' ', value) - return value.encode('ascii', 'ignore') + return value.encode('ascii', 'ignore').decode('ascii')