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:

committed by
Masaki Matsushita

parent
599171ade4
commit
b592b42aa1
@@ -22,7 +22,10 @@ Base utilities to build API operation managers and objects on top of.
|
|||||||
import contextlib
|
import contextlib
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from oslo_utils import reflection
|
from oslo_utils import reflection
|
||||||
|
from oslo_utils import strutils
|
||||||
|
|
||||||
from troveclient.compat import exceptions
|
from troveclient.compat import exceptions
|
||||||
from troveclient.compat import utils
|
from troveclient.compat import utils
|
||||||
|
|
||||||
@@ -239,7 +242,7 @@ class Resource(object):
|
|||||||
def human_id(self):
|
def human_id(self):
|
||||||
"""Provides a pretty ID which can be used for bash completion."""
|
"""Provides a pretty ID which can be used for bash completion."""
|
||||||
if 'name' in self.__dict__ and self.HUMAN_ID:
|
if 'name' in self.__dict__ and self.HUMAN_ID:
|
||||||
return utils.slugify(self.name)
|
return strutils.to_slug(self.name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _add_details(self, info):
|
def _add_details(self, info):
|
||||||
|
@@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from oslo_utils import strutils
|
|
||||||
|
|
||||||
|
|
||||||
class HookableMixin(object):
|
class HookableMixin(object):
|
||||||
"""Mixin so classes can register and run hooks."""
|
"""Mixin so classes can register and run hooks."""
|
||||||
@@ -46,18 +44,3 @@ def env(*vars, **kwargs):
|
|||||||
if value:
|
if value:
|
||||||
return value
|
return value
|
||||||
return kwargs.get('default', '')
|
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")
|
|
||||||
|
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import Crypto.Random
|
import Crypto.Random
|
||||||
import os
|
import os
|
||||||
import six
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@@ -50,13 +49,6 @@ class UtilsTest(testtools.TestCase):
|
|||||||
self.assertEqual('passing', utils.env('test_abc'))
|
self.assertEqual('passing', utils.env('test_abc'))
|
||||||
self.assertEqual('', utils.env('test_abcd'))
|
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):
|
def test_encode_decode_data(self):
|
||||||
text_data_str = 'This is a text string'
|
text_data_str = 'This is a text string'
|
||||||
try:
|
try:
|
||||||
|
@@ -26,7 +26,6 @@ import prettytable
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import strutils
|
|
||||||
|
|
||||||
from troveclient.openstack.common.apiclient import exceptions
|
from troveclient.openstack.common.apiclient import exceptions
|
||||||
|
|
||||||
@@ -278,21 +277,6 @@ def safe_issubclass(*args):
|
|||||||
return False
|
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):
|
def is_uuid_like(val):
|
||||||
"""Returns validation of a value as a UUID.
|
"""Returns validation of a value as a UUID.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user