Make translitcodec optional, and work nicely without it.
This commit is contained in:
parent
78fa73bcd5
commit
e535b9b36f
@ -16,7 +16,13 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
# This import *is* used; see word.encode('tranlit/long') below.
|
# This import *is* used; see word.encode('tranlit/long') below.
|
||||||
|
from unicodedata import normalize
|
||||||
|
|
||||||
|
try:
|
||||||
import translitcodec
|
import translitcodec
|
||||||
|
USING_TRANSLITCODEC = True
|
||||||
|
except ImportError:
|
||||||
|
USING_TRANSLITCODEC = False
|
||||||
|
|
||||||
|
|
||||||
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
|
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
|
||||||
@ -28,8 +34,11 @@ def slugify(text, delim=u'-'):
|
|||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
for word in _punct_re.split(text.lower()):
|
for word in _punct_re.split(text.lower()):
|
||||||
# Uses translitcodec!
|
if USING_TRANSLITCODEC:
|
||||||
word = word.encode('translit/long')
|
word = word.encode('translit/long')
|
||||||
|
else:
|
||||||
|
word = normalize('NFKD', word).encode('ascii', 'ignore')
|
||||||
|
|
||||||
if word:
|
if word:
|
||||||
result.append(word)
|
result.append(word)
|
||||||
return unicode(delim.join(result))
|
return unicode(delim.join(result))
|
||||||
|
3
setup.py
3
setup.py
@ -53,13 +53,14 @@ setup(
|
|||||||
'jinja2',
|
'jinja2',
|
||||||
'sphinx',
|
'sphinx',
|
||||||
'Babel',
|
'Babel',
|
||||||
'translitcodec',
|
|
||||||
'argparse',
|
'argparse',
|
||||||
'webtest',
|
'webtest',
|
||||||
'ConfigObj',
|
'ConfigObj',
|
||||||
'Markdown',
|
'Markdown',
|
||||||
'sqlalchemy>=0.7.0',
|
'sqlalchemy>=0.7.0',
|
||||||
'sqlalchemy-migrate',
|
'sqlalchemy-migrate',
|
||||||
|
## This is optional!
|
||||||
|
# 'translitcodec',
|
||||||
## For now we're expecting that users will install this from
|
## For now we're expecting that users will install this from
|
||||||
## their package managers.
|
## their package managers.
|
||||||
# 'lxml',
|
# 'lxml',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user