Merge "Fix unicode issue"

This commit is contained in:
Jenkins
2013-10-23 15:37:15 +00:00
committed by Gerrit Code Review
2 changed files with 5 additions and 11 deletions

View File

@@ -18,6 +18,7 @@
# under the License. # under the License.
import os import os
import six
from testtools import TestCase from testtools import TestCase
from troveclient import utils from troveclient import utils
@@ -55,5 +56,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!'))

View File

@@ -216,10 +216,6 @@ class HookableMixin(object):
hook_func(*args, **kwargs) hook_func(*args, **kwargs)
_slugify_strip_re = re.compile(r'[^\w\s-]')
_slugify_hyphenate_re = re.compile(r'[-\s]+')
# http://code.activestate.com/recipes/ # http://code.activestate.com/recipes/
# 577257-slugify-make-a-string-usable-in-a-url-or-filename/ # 577257-slugify-make-a-string-usable-in-a-url-or-filename/
def slugify(value): def slugify(value):
@@ -228,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)