summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVal Neekman <val@neekware.com>2015-04-11 22:18:27 -0400
committerVal Neekman <val@neekware.com>2015-04-11 22:18:27 -0400
commita1d0dfdf09913b7e5fdedcc7447fb9482d365c29 (patch)
treeebde3586ca1329705db4a8b9e537edd80191662f
parentf90ecf1905c9d06f32e676a2dcaff311f82df868 (diff)
downloadpython-slugify-a1d0dfdf09913b7e5fdedcc7447fb9482d365c29.tar.gz
remove six dependancy
-rw-r--r--slugify/slugify.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/slugify/slugify.py b/slugify/slugify.py
index 2cc7db2..82f67fe 100644
--- a/slugify/slugify.py
+++ b/slugify/slugify.py
@@ -2,12 +2,17 @@ import re
import unicodedata
import types
import sys
+
try:
from htmlentitydefs import name2codepoint
+ _unicode = unicode
+ _unicode_type = types.UnicodeType
except ImportError:
from html.entities import name2codepoint
+ _unicode = str
+ _unicode_type = str
-from unidecode import unidecode
+import unidecode
__all__ = ['slugify']
@@ -82,8 +87,16 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
:return (str):
"""
+ # ensure text is unicode
+ if not isinstance(text, _unicode_type):
+ text = _unicode(text, 'utf-8', 'ignore')
+
# decode unicode
- text = unidecode(text)
+ text = unidecode.unidecode(text)
+
+ # ensure text is still in unicode
+ if not isinstance(text, _unicode_type):
+ text = _unicode(text, 'utf-8', 'ignore')
# character entity reference
if entities: