Fix unicode isue

In Python 3, all string is unicode.
Replace unicode() with six.u()
Make use of strutils.to_slug() for slugify() definition

Partial implements: blueprint py33-support

Change-Id: I6a1e19c095a2fbafcbe47b34c7af17e1b0353b9e
This commit is contained in:
Kui Shi
2013-10-15 06:50:33 +08:00
parent d114208442
commit 2070d4267c
2 changed files with 5 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import os
import six
from testtools import TestCase
from troveclient import utils
@@ -36,5 +37,5 @@ class UtilsTest(TestCase):
import unicodedata # noqa
self.assertEqual('not_unicode', utils.slugify('not_unicode'))
self.assertEqual('unicode', utils.slugify(unicode('unicode')))
self.assertEqual('unicode', utils.slugify(six.u('unicode')))
self.assertEqual('slugify-test', utils.slugify('SLUGIFY% test!'))

View File

@@ -224,10 +224,7 @@ def slugify(value):
and converts spaces to hyphens.
From Django's "django/template/defaultfilters.py".
Make use strutils.to_slug from openstack common
"""
import unicodedata
if not isinstance(value, unicode):
value = unicode(value)
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(_slugify_strip_re.sub('', value).strip().lower())
return _slugify_hyphenate_re.sub('-', value)
return strutils.to_slug(value, incoming=None, errors="strict")