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 <berendt@b1-systems.de>
This commit is contained in:
Christian Berendt 2014-05-27 23:54:03 +02:00 committed by Masaki Matsushita
parent 599171ade4
commit b592b42aa1
4 changed files with 4 additions and 42 deletions

View File

@ -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):

View File

@ -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")

View File

@ -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:

View File

@ -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.