Fix unicode issue
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 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!'))
|
||||
|
@@ -212,10 +212,6 @@ class HookableMixin(object):
|
||||
hook_func(*args, **kwargs)
|
||||
|
||||
|
||||
_slugify_strip_re = re.compile(r'[^\w\s-]')
|
||||
_slugify_hyphenate_re = re.compile(r'[-\s]+')
|
||||
|
||||
|
||||
# http://code.activestate.com/recipes/
|
||||
# 577257-slugify-make-a-string-usable-in-a-url-or-filename/
|
||||
def slugify(value):
|
||||
@@ -224,10 +220,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")
|
||||
|
Reference in New Issue
Block a user