diff options
author | Boris Bobrov <breton@cynicmansion.ru> | 2014-03-11 15:50:01 +0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2014-03-11 11:01:04 -0500 |
commit | 2636dddfa65e6d1e7601aee4d1e8d7d47f7f13a7 (patch) | |
tree | 40fd9aefadeee8fdde320cd3cf80a6c320245ca7 /mediagoblin/tools | |
parent | 1e80c976e2f32968ecaec7b7cebee5755931fa7c (diff) | |
download | mediagoblin-2636dddfa65e6d1e7601aee4d1e8d7d47f7f13a7.tar.lz mediagoblin-2636dddfa65e6d1e7601aee4d1e8d7d47f7f13a7.tar.xz mediagoblin-2636dddfa65e6d1e7601aee4d1e8d7d47f7f13a7.zip |
added new slugify with unidecode
Diffstat (limited to 'mediagoblin/tools')
-rw-r--r-- | mediagoblin/tools/url.py | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/mediagoblin/tools/url.py b/mediagoblin/tools/url.py index d9179f9e..657c0373 100644 --- a/mediagoblin/tools/url.py +++ b/mediagoblin/tools/url.py @@ -15,15 +15,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import re -# This import *is* used; see word.encode('tranlit/long') below. -from unicodedata import normalize - -try: - import translitcodec - USING_TRANSLITCODEC = True -except ImportError: - USING_TRANSLITCODEC = False - +from unidecode import unidecode _punct_re = re.compile(r'[\t !"#:$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') @@ -34,11 +26,5 @@ def slugify(text, delim=u'-'): """ result = [] for word in _punct_re.split(text.lower()): - if USING_TRANSLITCODEC: - word = word.encode('translit/long') - else: - word = normalize('NFKD', word).encode('ascii', 'ignore') - - if word: - result.append(word) + result.extend(unidecode(word).split()) return unicode(delim.join(result)) |