diff options
| author | Val Neekman <val@neekware.com> | 2015-04-11 22:03:34 -0400 |
|---|---|---|
| committer | Val Neekman <val@neekware.com> | 2015-04-11 22:03:34 -0400 |
| commit | f90ecf1905c9d06f32e676a2dcaff311f82df868 (patch) | |
| tree | adb49e182792a29fb3381425262beee8484c91ec /slugify | |
| parent | f64f1a3e84a73d54def5f89130c07a7b0814424e (diff) | |
| download | python-slugify-f90ecf1905c9d06f32e676a2dcaff311f82df868.tar.gz | |
remove 2to3 depenancy, add save word order
Diffstat (limited to 'slugify')
| -rw-r--r-- | slugify/__init__.py | 7 | ||||
| -rw-r--r-- | slugify/slugify.py | 32 |
2 files changed, 18 insertions, 21 deletions
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)) |
