diff options
| author | Arthur Darcet <arthur.darcet@m4x.org> | 2013-05-10 10:59:18 +0200 |
|---|---|---|
| committer | Arthur Darcet <arthur.darcet@m4x.org> | 2013-05-10 12:04:23 +0200 |
| commit | b3544c648de03322ed1a1599216f63383976ef08 (patch) | |
| tree | 8cbde37e41019eae4aa80f70346c5cf9454fa74f /slugify | |
| parent | e951142f77402cd4e0bdca69ea4aea5bb466c310 (diff) | |
| download | python-slugify-b3544c648de03322ed1a1599216f63383976ef08.tar.gz | |
Support python3
Diffstat (limited to 'slugify')
| -rw-r--r-- | slugify/__init__.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/slugify/__init__.py b/slugify/__init__.py index f8de605..fffab01 100644 --- a/slugify/__init__.py +++ b/slugify/__init__.py @@ -6,8 +6,9 @@ __all__ = ['slugify'] import re import unicodedata +import types +import sys from htmlentitydefs import name2codepoint -from types import UnicodeType from unidecode import unidecode # character entity reference @@ -42,14 +43,15 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w """ Make a slug from the given text """ # text to unicode - if type(text) != UnicodeType: + if type(text) != types.UnicodeType: text = unicode(text, 'utf-8', 'ignore') # decode unicode ( 影師嗎 = Ying Shi Ma) text = unidecode(text) # text back to unicode - text = unicode(text, 'utf-8', 'ignore') + if type(text) != types.UnicodeType: + text = unicode(text, 'utf-8', 'ignore') # character entity reference if entities: @@ -70,7 +72,9 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w pass # translate - text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore') + text = unicodedata.normalize('NFKD', text) + if sys.version_info < (3,): + text = text.encode('ascii', 'ignore') # replace unwanted characters text = REPLACE1_REXP.sub('', text.lower()) # replace ' with nothing instead with - |
