Code cleanup: use oslo's to_slug() instead of slugify()

The bash completion code is the sole user of the slugify() function
in utils, which is substantially similar to to_slug() provided in
strutils from oslo.

Change-Id: Ib4eb7e4c0fa0e9bc5c4a0856f6391911d8f8fd3b
Closes-bug: #1266118
This commit is contained in:
Chris Buccella 2014-01-04 22:56:09 +00:00
parent ab32e406c8
commit 3dbab161be
2 changed files with 1 additions and 23 deletions

View File

@ -442,7 +442,7 @@ class Resource(object):
for bash completion.
"""
if self.NAME_ATTR in self.__dict__ and self.HUMAN_ID:
return utils.slugify(getattr(self, self.NAME_ATTR))
return strutils.to_slug(getattr(self, self.NAME_ATTR))
return None
def _add_details(self, info):

View File

@ -14,7 +14,6 @@
import json
import os
import pkg_resources
import re
import sys
import textwrap
import uuid
@ -381,27 +380,6 @@ def import_class(import_str):
__import__(mod_str)
return getattr(sys.modules[mod_str], class_str)
_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):
"""
Normalizes string, converts to lowercase, removes non-alpha characters,
and converts spaces to hyphens.
From Django's "django/template/defaultfilters.py".
"""
import unicodedata
if not isinstance(value, six.text_type):
value = six.text_type(value)
value = unicodedata.normalize('NFKD', value).encode('ascii',
'ignore').decode("ascii")
value = six.text_type(_slugify_strip_re.sub('', value).strip().lower())
return _slugify_hyphenate_re.sub('-', value)
def _load_entry_point(ep_name, name=None):
"""Try to load the entry point ep_name that matches name."""