summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Darcet <arthur.darcet@m4x.org>2013-05-10 10:59:18 +0200
committerArthur Darcet <arthur.darcet@m4x.org>2013-05-10 12:04:23 +0200
commitb3544c648de03322ed1a1599216f63383976ef08 (patch)
tree8cbde37e41019eae4aa80f70346c5cf9454fa74f
parente951142f77402cd4e0bdca69ea4aea5bb466c310 (diff)
downloadpython-slugify-b3544c648de03322ed1a1599216f63383976ef08.tar.gz
Support python3
-rw-r--r--.travis.yml5
-rwxr-xr-xsetup.py9
-rw-r--r--slugify/__init__.py12
3 files changed, 18 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml
index 6990722..d4796fa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,12 @@ language: python
python:
- "2.6"
- "2.7"
+ - "3.2"
+ - "3.3"
install:
- pip install -q -r requirements.txt --use-mirrors
+before_script:
+ - if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then 2to3 --no-diffs --write --nobackups slugify; fi
+ - if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then 2to3 --no-diffs --write --nobackups slugify; fi
script: python test.py
diff --git a/setup.py b/setup.py
index 509282f..4499a0d 100755
--- a/setup.py
+++ b/setup.py
@@ -60,9 +60,9 @@ def get_package_data(package):
if sys.argv[-1] == 'publish':
os.system("python setup.py sdist upload")
args = {'version': get_version(package)}
- print "You probably want to also tag the version now:"
- print " git tag -a %(version)s -m 'version %(version)s'" % args
- print " git push --tags"
+ print("You probably want to also tag the version now:")
+ print(" git tag -a %(version)s -m 'version %(version)s'" % args)
+ print(" git push --tags")
sys.exit()
@@ -77,7 +77,8 @@ setup(
packages=get_packages(package),
package_data=get_package_data(package),
install_requires=install_requires,
- classifiers=classifiers
+ classifiers=classifiers,
+ use_2to3=True,
)
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 -