summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVal Neekman <val@neekware.com>2015-04-11 22:03:34 -0400
committerVal Neekman <val@neekware.com>2015-04-11 22:03:34 -0400
commitf90ecf1905c9d06f32e676a2dcaff311f82df868 (patch)
treeadb49e182792a29fb3381425262beee8484c91ec
parentf64f1a3e84a73d54def5f89130c07a7b0814424e (diff)
downloadpython-slugify-f90ecf1905c9d06f32e676a2dcaff311f82df868.tar.gz
remove 2to3 depenancy, add save word order
-rw-r--r--.travis.yml6
-rw-r--r--CHANGELOG.md8
-rw-r--r--README.md24
-rw-r--r--slugify/__init__.py7
-rw-r--r--slugify/slugify.py32
-rw-r--r--test.py3
6 files changed, 53 insertions, 27 deletions
diff --git a/.travis.yml b/.travis.yml
index d51b361..d6ee375 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,10 +6,8 @@ python:
- "3.3"
- "3.4"
- pypy
+
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
- - if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then 2to3 --no-diffs --write --nobackups slugify; fi
+
script: python test.py
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b2bd1af..966cb5d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+## 0.1.1
+
+Enhancement:
+
+ - Added more test
+ - Added option to save word order
+ - Removed 2to3 dependency
+
## 0.1.0
Enhancement:
diff --git a/README.md b/README.md
index 97a1548..a6572ae 100644
--- a/README.md
+++ b/README.md
@@ -89,6 +89,30 @@ How to use
txt = 'jaja---lol-méméméoo--a'
r = slugify(txt, max_length=20, word_boundary=True, separator="ZZZZZZ")
self.assertEqual(r, "jajaZZZZZZlolZZZZZZmememeooZZZZZZa")
+
+ txt = "___This is a test ---"
+ r = slugify(txt)
+ self.assertEqual(r, "this-is-a-test")
+
+ txt = "___This is a test___"
+ r = slugify(txt)
+ self.assertEqual(r, "this-is-a-test")
+
+ txt = 'one two three four five'
+ r = slugify(txt, max_length=13, word_boundary=True, save_order=True)
+ self.assertEqual(r, "one-two-three")
+
+ txt = 'one two three four five'
+ r = slugify(txt, max_length=13, word_boundary=True, save_order=False)
+ self.assertEqual(r, "one-two-three")
+
+ txt = 'one two three four five'
+ r = slugify(txt, max_length=12, word_boundary=True, save_order=False)
+ self.assertEqual(r, "one-two-four")
+
+ txt = 'one two three four five'
+ r = slugify(txt, max_length=12, word_boundary=True, save_order=True)
+ self.assertEqual(r, "one-two")
```
Running the tests
diff --git a/slugify/__init__.py b/slugify/__init__.py
index a0b2249..08f721a 100644
--- a/slugify/__init__.py
+++ b/slugify/__init__.py
@@ -1,5 +1,6 @@
-# -*- coding: utf-8 -*-
+from .slugify import *
-__version__ = '0.1.0'
-from slugify import *
+__author__ = 'Val Neekman @ Neekware Inc. [@vneekman]'
+__description__ = 'A Python slugify application that also handles Unicode'
+__version__ = '0.1.1'
diff --git a/slugify/slugify.py b/slugify/slugify.py
index aae4622..2cc7db2 100644
--- a/slugify/slugify.py
+++ b/slugify/slugify.py
@@ -1,14 +1,18 @@
-# -*- coding: utf-8 -*-
-
-__all__ = ['slugify']
-
import re
import unicodedata
import types
import sys
-from htmlentitydefs import name2codepoint
+try:
+ from htmlentitydefs import name2codepoint
+except ImportError:
+ from html.entities import name2codepoint
+
from unidecode import unidecode
+
+__all__ = ['slugify']
+
+
# character entity reference
CHAR_ENTITY_REXP = re.compile('&(%s);' % '|'.join(name2codepoint))
@@ -78,17 +82,9 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
:return (str):
"""
- # text to unicode
- if not isinstance(text, types.UnicodeType):
- text = unicode(text, 'utf-8', 'ignore')
-
- # decode unicode ( 影師嗎 = Ying Shi Ma)
+ # decode unicode
text = unidecode(text)
- # text back to unicode
- if not isinstance(text, types.UnicodeType):
- text = unicode(text, 'utf-8', 'ignore')
-
# character entity reference
if entities:
text = CHAR_ENTITY_REXP.sub(lambda m: unichr(name2codepoint[m.group(1)]), text)
@@ -131,7 +127,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
def main():
if len(sys.argv) < 2:
- print "Usage %s TEXT TO SLUGIFY" % sys.argv[0]
- return
- text = ' '.join(sys.argv[1:])
- print slugify(text) \ No newline at end of file
+ print("Usage %s TEXT TO SLUGIFY" % sys.argv[0])
+ else:
+ text = ' '.join(sys.argv[1:])
+ print(slugify(text))
diff --git a/test.py b/test.py
index 7471997..88027ee 100644
--- a/test.py
+++ b/test.py
@@ -96,6 +96,5 @@ class TestSequenceFunctions(unittest.TestCase):
r = slugify(txt, max_length=12, word_boundary=True, save_order=True)
self.assertEqual(r, "one-two")
-
if __name__ == '__main__':
- unittest.main() \ No newline at end of file
+ unittest.main()