From 5af5d6f30dab4fd707ed589e33c16a8965d94031 Mon Sep 17 00:00:00 2001 From: Kui Shi Date: Fri, 18 Oct 2013 00:03:53 +0800 Subject: [PATCH] Make use of strutils.to_slug in slugify() Align with the change: 2070d4267c2a88b3493400b358003c8fa13778a6 Close-Bug #1241256 Change-Id: Idc16d75258baa1f5ee05ff48bfadc358c7655e55 --- troveclient/compat/utils.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/troveclient/compat/utils.py b/troveclient/compat/utils.py index dd15fea6..06d3c640 100644 --- a/troveclient/compat/utils.py +++ b/troveclient/compat/utils.py @@ -15,6 +15,8 @@ import os import re +from troveclient.openstack.common import strutils + class HookableMixin(object): """Mixin so classes can register and run hooks.""" @@ -46,10 +48,6 @@ def env(*vars, **kwargs): return kwargs.get('default', '') -_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): @@ -58,10 +56,7 @@ def slugify(value): and converts spaces to hyphens. From Django's "django/template/defaultfilters.py". + + Make use of 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")