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:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import six
|
||||||
from testtools import TestCase
|
from testtools import TestCase
|
||||||
from troveclient import utils
|
from troveclient import utils
|
||||||
|
|
||||||
@@ -36,5 +37,5 @@ class UtilsTest(TestCase):
|
|||||||
import unicodedata # noqa
|
import unicodedata # noqa
|
||||||
|
|
||||||
self.assertEqual('not_unicode', utils.slugify('not_unicode'))
|
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!'))
|
self.assertEqual('slugify-test', utils.slugify('SLUGIFY% test!'))
|
||||||
|
@@ -224,10 +224,7 @@ def slugify(value):
|
|||||||
and converts spaces to hyphens.
|
and converts spaces to hyphens.
|
||||||
|
|
||||||
From Django's "django/template/defaultfilters.py".
|
From Django's "django/template/defaultfilters.py".
|
||||||
|
|
||||||
|
Make use strutils.to_slug from openstack common
|
||||||
"""
|
"""
|
||||||
import unicodedata
|
return strutils.to_slug(value, incoming=None, errors="strict")
|
||||||
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)
|
|
||||||
|
Reference in New Issue
Block a user