From b592b42aa1a8a9683af40fa1c011c7cd1665b45a Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Tue, 27 May 2014 23:54:03 +0200 Subject: [PATCH] Use strutils.to_slug() instead of utils.slugify() Oslo provides a function, to_slug() in strutils that is substantially similar to slugify() provided in utils by python-troveclient. Remove slugify() and use to_slug() instead. Change-Id: I97bc7cfc2c0e7d14e7617037bff431cdc1eee50f Closes-Bug: #1266127 Author: Christian Berendt --- troveclient/compat/base.py | 5 ++++- troveclient/compat/utils.py | 17 ----------------- troveclient/tests/test_utils.py | 8 -------- troveclient/utils.py | 16 ---------------- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/troveclient/compat/base.py b/troveclient/compat/base.py index 3e894aea..24d681ce 100644 --- a/troveclient/compat/base.py +++ b/troveclient/compat/base.py @@ -22,7 +22,10 @@ Base utilities to build API operation managers and objects on top of. import contextlib import hashlib import os + from oslo_utils import reflection +from oslo_utils import strutils + from troveclient.compat import exceptions from troveclient.compat import utils @@ -239,7 +242,7 @@ class Resource(object): def human_id(self): """Provides a pretty ID which can be used for bash completion.""" if 'name' in self.__dict__ and self.HUMAN_ID: - return utils.slugify(self.name) + return strutils.to_slug(self.name) return None def _add_details(self, info): diff --git a/troveclient/compat/utils.py b/troveclient/compat/utils.py index f81a1b56..0b3f6a72 100644 --- a/troveclient/compat/utils.py +++ b/troveclient/compat/utils.py @@ -14,8 +14,6 @@ import os -from oslo_utils import strutils - class HookableMixin(object): """Mixin so classes can register and run hooks.""" @@ -46,18 +44,3 @@ def env(*vars, **kwargs): if value: return value return kwargs.get('default', '') - - -# http://code.activestate.com/recipes/ -# 577257-slugify-make-a-string-usable-in-a-url-or-filename/ -def slugify(value): - """Converts a string usable in a url or filename. - - Normalizes string, converts to lowercase, removes non-alpha characters, - and converts spaces to hyphens. - - From Django's "django/template/defaultfilters.py". - - Make use of strutils.to_slug from openstack common - """ - return strutils.to_slug(value, incoming=None, errors="strict") diff --git a/troveclient/tests/test_utils.py b/troveclient/tests/test_utils.py index b7ebb08e..266b2385 100644 --- a/troveclient/tests/test_utils.py +++ b/troveclient/tests/test_utils.py @@ -17,7 +17,6 @@ import Crypto.Random import os -import six import tempfile import testtools @@ -50,13 +49,6 @@ class UtilsTest(testtools.TestCase): self.assertEqual('passing', utils.env('test_abc')) self.assertEqual('', utils.env('test_abcd')) - def test_slugify(self): - import unicodedata # noqa - - self.assertEqual('not_unicode', utils.slugify('not_unicode')) - self.assertEqual('unicode', utils.slugify(six.u('unicode'))) - self.assertEqual('slugify-test', utils.slugify('SLUGIFY% test!')) - def test_encode_decode_data(self): text_data_str = 'This is a text string' try: diff --git a/troveclient/utils.py b/troveclient/utils.py index b5b05046..65acceff 100644 --- a/troveclient/utils.py +++ b/troveclient/utils.py @@ -26,7 +26,6 @@ import prettytable import six from oslo_utils import encodeutils -from oslo_utils import strutils from troveclient.openstack.common.apiclient import exceptions @@ -278,21 +277,6 @@ def safe_issubclass(*args): return False -# http://code.activestate.com/recipes/ -# 577257-slugify-make-a-string-usable-in-a-url-or-filename/ -def slugify(value): - """Converts a string usable in a url or filename. - - Normalizes string, converts to lowercase, removes non-alpha characters, - and converts spaces to hyphens. - - From Django's "django/template/defaultfilters.py". - - Make use strutils.to_slug from openstack common - """ - return strutils.to_slug(value, incoming=None, errors="strict") - - def is_uuid_like(val): """Returns validation of a value as a UUID.