diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-01-06 21:41:08 -0600 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-01-06 21:41:08 -0600 |
commit | e535b9b36fb3b336e3a2c69608d3935d5033ace2 (patch) | |
tree | 89f0ca5c8b9c37ed334cd7b6701f67c2ca7910a8 | |
parent | 78fa73bcd57f46b3711eba22a3537f3965069d4f (diff) | |
download | mediagoblin-e535b9b36fb3b336e3a2c69608d3935d5033ace2.tar.lz mediagoblin-e535b9b36fb3b336e3a2c69608d3935d5033ace2.tar.xz mediagoblin-e535b9b36fb3b336e3a2c69608d3935d5033ace2.zip |
Make translitcodec optional, and work nicely without it.
-rw-r--r-- | mediagoblin/tools/url.py | 15 | ||||
-rw-r--r-- | setup.py | 3 |
2 files changed, 14 insertions, 4 deletions
diff --git a/mediagoblin/tools/url.py b/mediagoblin/tools/url.py index de16536c..8604ad5f 100644 --- a/mediagoblin/tools/url.py +++ b/mediagoblin/tools/url.py @@ -16,7 +16,13 @@ import re # This import *is* used; see word.encode('tranlit/long') below. -import translitcodec +from unicodedata import normalize + +try: + import translitcodec + USING_TRANSLITCODEC = True +except ImportError: + USING_TRANSLITCODEC = False _punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') @@ -28,8 +34,11 @@ def slugify(text, delim=u'-'): """ result = [] for word in _punct_re.split(text.lower()): - # Uses translitcodec! - 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)) @@ -53,13 +53,14 @@ setup( 'jinja2', 'sphinx', 'Babel', - 'translitcodec', 'argparse', 'webtest', 'ConfigObj', 'Markdown', 'sqlalchemy>=0.7.0', 'sqlalchemy-migrate', + ## This is optional! + # 'translitcodec', ## For now we're expecting that users will install this from ## their package managers. # 'lxml', |