aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/url.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tools/url.py')
-rw-r--r--mediagoblin/tools/url.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/mediagoblin/tools/url.py b/mediagoblin/tools/url.py
index 7477173a..8604ad5f 100644
--- a/mediagoblin/tools/url.py
+++ b/mediagoblin/tools/url.py
@@ -15,7 +15,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
-import translitcodec
+# 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
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
@@ -27,7 +34,11 @@ def slugify(text, delim=u'-'):
"""
result = []
for word in _punct_re.split(text.lower()):
- word = word.encode('translit/long')
+ if USING_TRANSLITCODEC:
+ word = word.encode('translit/long')
+ else:
+ word = normalize('NFKD', word).encode('ascii', 'ignore')
+
if word:
result.append(word)
return unicode(delim.join(result))