From 3dbab161bed7659eb976f0961ae5226da34b16f9 Mon Sep 17 00:00:00 2001 From: Chris Buccella Date: Sat, 4 Jan 2014 22:56:09 +0000 Subject: [PATCH] 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 --- novaclient/base.py | 2 +- novaclient/utils.py | 22 ---------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/novaclient/base.py b/novaclient/base.py index 38434c282..517d13779 100644 --- a/novaclient/base.py +++ b/novaclient/base.py @@ -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): diff --git a/novaclient/utils.py b/novaclient/utils.py index e7e848173..7668ebfd0 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -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."""