Skip to content

Commit

Permalink
Make use of strutils.to_slug in slugify()
Browse files Browse the repository at this point in the history
Align with the change:
2070d42

Close-Bug #1241256

Change-Id: Idc16d75258baa1f5ee05ff48bfadc358c7655e55
  • Loading branch information
skuicloud committed Oct 22, 2013
1 parent 0127670 commit 5af5d6f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions troveclient/compat/utils.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand All @@ -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")

0 comments on commit 5af5d6f

Please sign in to comment.