Fix unicode issue for Python 2/3 compatible code.
replace unicode with six.text_type Story: 2003430 Task: 26517 Change-Id: I43db85ad34defeb708da1ad6c6c1ccce730818eb Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
parent
eed120abcb
commit
481b44f8a7
|
@ -9,6 +9,7 @@ import wsme
|
||||||
from wsme import types as wsme_types
|
from wsme import types as wsme_types
|
||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
import pecan
|
import pecan
|
||||||
|
import six
|
||||||
from pecan import rest
|
from pecan import rest
|
||||||
|
|
||||||
from sm_api.api.controllers.v1 import base
|
from sm_api.api.controllers.v1 import base
|
||||||
|
@ -110,7 +111,7 @@ class NodesController(rest.RestController):
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(Nodes, unicode)
|
@wsme_pecan.wsexpose(Nodes, six.text_type)
|
||||||
def get_one(self, uuid):
|
def get_one(self, uuid):
|
||||||
try:
|
try:
|
||||||
rpc_sg = objects.sm_node.get_by_uuid(pecan.request.context, uuid)
|
rpc_sg = objects.sm_node.get_by_uuid(pecan.request.context, uuid)
|
||||||
|
@ -119,8 +120,8 @@ class NodesController(rest.RestController):
|
||||||
|
|
||||||
return Nodes.convert_with_links(rpc_sg)
|
return Nodes.convert_with_links(rpc_sg)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(NodesCollection, unicode, int,
|
@wsme_pecan.wsexpose(NodesCollection, six.text_type, int,
|
||||||
unicode, unicode)
|
six.text_type, six.text_type)
|
||||||
def get_all(self, marker=None, limit=None,
|
def get_all(self, marker=None, limit=None,
|
||||||
sort_key='name', sort_dir='asc'):
|
sort_key='name', sort_dir='asc'):
|
||||||
"""Retrieve list of nodes."""
|
"""Retrieve list of nodes."""
|
||||||
|
@ -134,13 +135,13 @@ class NodesController(rest.RestController):
|
||||||
sort_key=sort_key,
|
sort_key=sort_key,
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(NodesCommandResult, unicode,
|
@wsme_pecan.wsexpose(NodesCommandResult, six.text_type,
|
||||||
body=NodesCommand)
|
body=NodesCommand)
|
||||||
def put(self, hostname, command):
|
def put(self, hostname, command):
|
||||||
|
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(NodesCommandResult, unicode,
|
@wsme_pecan.wsexpose(NodesCommandResult, six.text_type,
|
||||||
body=NodesCommand)
|
body=NodesCommand)
|
||||||
def patch(self, hostname, command):
|
def patch(self, hostname, command):
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import wsme
|
||||||
from wsme import types as wsme_types
|
from wsme import types as wsme_types
|
||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
import pecan
|
import pecan
|
||||||
|
import six
|
||||||
from pecan import rest
|
from pecan import rest
|
||||||
|
|
||||||
from sm_api.api.controllers.v1 import base
|
from sm_api.api.controllers.v1 import base
|
||||||
|
@ -124,7 +125,7 @@ class ServiceGroupController(rest.RestController):
|
||||||
|
|
||||||
return sm_sdas
|
return sm_sdas
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServiceGroup, unicode)
|
@wsme_pecan.wsexpose(ServiceGroup, six.text_type)
|
||||||
def get_one(self, uuid):
|
def get_one(self, uuid):
|
||||||
try:
|
try:
|
||||||
rpc_sg = objects.sm_sda.get_by_uuid(pecan.request.context, uuid)
|
rpc_sg = objects.sm_sda.get_by_uuid(pecan.request.context, uuid)
|
||||||
|
@ -133,8 +134,8 @@ class ServiceGroupController(rest.RestController):
|
||||||
|
|
||||||
return ServiceGroup.convert_with_links(rpc_sg)
|
return ServiceGroup.convert_with_links(rpc_sg)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServiceGroupCollection, unicode, int,
|
@wsme_pecan.wsexpose(ServiceGroupCollection, six.text_type, int,
|
||||||
unicode, unicode)
|
six.text_type, six.text_type)
|
||||||
def get_all(self, marker=None, limit=None,
|
def get_all(self, marker=None, limit=None,
|
||||||
sort_key='name', sort_dir='asc'):
|
sort_key='name', sort_dir='asc'):
|
||||||
"""Retrieve list of servicegroups."""
|
"""Retrieve list of servicegroups."""
|
||||||
|
@ -148,13 +149,13 @@ class ServiceGroupController(rest.RestController):
|
||||||
sort_key=sort_key,
|
sort_key=sort_key,
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode,
|
@wsme_pecan.wsexpose(ServiceGroupCommandResult, six.text_type,
|
||||||
body=ServiceGroupCommand)
|
body=ServiceGroupCommand)
|
||||||
def put(self, hostname, command):
|
def put(self, hostname, command):
|
||||||
|
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode,
|
@wsme_pecan.wsexpose(ServiceGroupCommandResult, six.text_type,
|
||||||
body=ServiceGroupCommand)
|
body=ServiceGroupCommand)
|
||||||
def patch(self, hostname, command):
|
def patch(self, hostname, command):
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
import pecan
|
import pecan
|
||||||
from pecan import rest
|
from pecan import rest
|
||||||
import wsme
|
import wsme
|
||||||
|
import six
|
||||||
from wsme import types as wtypes
|
from wsme import types as wtypes
|
||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
import socket
|
import socket
|
||||||
|
@ -607,7 +608,7 @@ class ServiceNodeController(rest.RestController):
|
||||||
else:
|
else:
|
||||||
raise wsme.exc.InvalidInput('action', command.action, "unknown")
|
raise wsme.exc.InvalidInput('action', command.action, "unknown")
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServiceNode, unicode)
|
@wsme_pecan.wsexpose(ServiceNode, six.text_type)
|
||||||
def get_one(self, hostname):
|
def get_one(self, hostname):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -642,7 +643,7 @@ class ServiceNodeController(rest.RestController):
|
||||||
active_services=active_services,
|
active_services=active_services,
|
||||||
swactable_services=swactable_services)
|
swactable_services=swactable_services)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServiceNodeCommandResult, unicode,
|
@wsme_pecan.wsexpose(ServiceNodeCommandResult, six.text_type,
|
||||||
body=ServiceNodeCommand)
|
body=ServiceNodeCommand)
|
||||||
def patch(self, hostname, command):
|
def patch(self, hostname, command):
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import wsme
|
||||||
from wsme import types as wsme_types
|
from wsme import types as wsme_types
|
||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
import pecan
|
import pecan
|
||||||
|
import six
|
||||||
from pecan import rest
|
from pecan import rest
|
||||||
|
|
||||||
from sm_api.api.controllers.v1 import base
|
from sm_api.api.controllers.v1 import base
|
||||||
|
@ -109,7 +110,7 @@ class ServicesController(rest.RestController):
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
return services
|
return services
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(Services, unicode)
|
@wsme_pecan.wsexpose(Services, six.text_type)
|
||||||
def get_one(self, uuid):
|
def get_one(self, uuid):
|
||||||
try:
|
try:
|
||||||
rpc_sg = objects.service.get_by_uuid(pecan.request.context, uuid)
|
rpc_sg = objects.service.get_by_uuid(pecan.request.context, uuid)
|
||||||
|
@ -118,7 +119,7 @@ class ServicesController(rest.RestController):
|
||||||
|
|
||||||
return Services.convert_with_links(rpc_sg)
|
return Services.convert_with_links(rpc_sg)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(Services, unicode)
|
@wsme_pecan.wsexpose(Services, six.text_type)
|
||||||
def get_service(self, name):
|
def get_service(self, name):
|
||||||
try:
|
try:
|
||||||
rpc_sg = objects.service.get_by_name(pecan.request.context, name)
|
rpc_sg = objects.service.get_by_name(pecan.request.context, name)
|
||||||
|
@ -126,8 +127,8 @@ class ServicesController(rest.RestController):
|
||||||
return None
|
return None
|
||||||
return Services.convert_with_links(rpc_sg)
|
return Services.convert_with_links(rpc_sg)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServicesCollection, unicode, int,
|
@wsme_pecan.wsexpose(ServicesCollection, six.text_type, int,
|
||||||
unicode, unicode)
|
six.text_type, six.text_type)
|
||||||
def get_all(self, marker=None, limit=None,
|
def get_all(self, marker=None, limit=None,
|
||||||
sort_key='name', sort_dir='asc'):
|
sort_key='name', sort_dir='asc'):
|
||||||
"""Retrieve list of services."""
|
"""Retrieve list of services."""
|
||||||
|
@ -141,13 +142,13 @@ class ServicesController(rest.RestController):
|
||||||
sort_key=sort_key,
|
sort_key=sort_key,
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServicesCommandResult, unicode,
|
@wsme_pecan.wsexpose(ServicesCommandResult, six.text_type,
|
||||||
body=ServicesCommand)
|
body=ServicesCommand)
|
||||||
def put(self, hostname, command):
|
def put(self, hostname, command):
|
||||||
|
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(ServicesCommandResult, unicode,
|
@wsme_pecan.wsexpose(ServicesCommandResult, six.text_type,
|
||||||
body=ServicesCommand)
|
body=ServicesCommand)
|
||||||
def patch(self, hostname, command):
|
def patch(self, hostname, command):
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import wsme
|
||||||
from wsme import types as wsme_types
|
from wsme import types as wsme_types
|
||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
import pecan
|
import pecan
|
||||||
|
import six
|
||||||
from pecan import rest
|
from pecan import rest
|
||||||
|
|
||||||
from sm_api.api.controllers.v1 import base
|
from sm_api.api.controllers.v1 import base
|
||||||
|
@ -123,7 +124,7 @@ class SmSdaController(rest.RestController):
|
||||||
|
|
||||||
return sm_sdas
|
return sm_sdas
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(SmSda, unicode)
|
@wsme_pecan.wsexpose(SmSda, six.text_type)
|
||||||
def get_one(self, uuid):
|
def get_one(self, uuid):
|
||||||
try:
|
try:
|
||||||
rpc_sda = objects.sm_sda.get_by_uuid(pecan.request.context, uuid)
|
rpc_sda = objects.sm_sda.get_by_uuid(pecan.request.context, uuid)
|
||||||
|
@ -132,8 +133,8 @@ class SmSdaController(rest.RestController):
|
||||||
|
|
||||||
return SmSda.convert_with_links(rpc_sda)
|
return SmSda.convert_with_links(rpc_sda)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(SmSdaCollection, unicode, int,
|
@wsme_pecan.wsexpose(SmSdaCollection, six.text_type, int,
|
||||||
unicode, unicode)
|
six.text_type, six.text_type)
|
||||||
def get_all(self, marker=None, limit=None,
|
def get_all(self, marker=None, limit=None,
|
||||||
sort_key='name', sort_dir='asc'):
|
sort_key='name', sort_dir='asc'):
|
||||||
"""Retrieve list of sm_sdas."""
|
"""Retrieve list of sm_sdas."""
|
||||||
|
@ -147,13 +148,13 @@ class SmSdaController(rest.RestController):
|
||||||
sort_key=sort_key,
|
sort_key=sort_key,
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(SmSdaCommandResult, unicode,
|
@wsme_pecan.wsexpose(SmSdaCommandResult, six.text_type,
|
||||||
body=SmSdaCommand)
|
body=SmSdaCommand)
|
||||||
def put(self, hostname, command):
|
def put(self, hostname, command):
|
||||||
|
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(SmSdaCommandResult, unicode,
|
@wsme_pecan.wsexpose(SmSdaCommandResult, six.text_type,
|
||||||
body=SmSdaCommand)
|
body=SmSdaCommand)
|
||||||
def patch(self, hostname, command):
|
def patch(self, hostname, command):
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ SHOULD include dedicated exception logging.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
import six
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from sm_api.common import safe_utils
|
from sm_api.common import safe_utils
|
||||||
|
@ -161,7 +161,7 @@ class SmApiException(Exception):
|
||||||
if self.__class__.__name__.endswith('_Remote'):
|
if self.__class__.__name__.endswith('_Remote'):
|
||||||
return self.args[0]
|
return self.args[0]
|
||||||
else:
|
else:
|
||||||
return unicode(self)
|
return six.text_type(self)
|
||||||
|
|
||||||
|
|
||||||
class NotAuthorized(SmApiException):
|
class NotAuthorized(SmApiException):
|
||||||
|
|
|
@ -404,7 +404,7 @@ def convert_to_list_dict(lst, label):
|
||||||
|
|
||||||
def sanitize_hostname(hostname):
|
def sanitize_hostname(hostname):
|
||||||
"""Return a hostname which conforms to RFC-952 and RFC-1123 specs."""
|
"""Return a hostname which conforms to RFC-952 and RFC-1123 specs."""
|
||||||
if isinstance(hostname, unicode):
|
if isinstance(hostname, six.text_type):
|
||||||
hostname = hostname.encode('latin-1', 'ignore')
|
hostname = hostname.encode('latin-1', 'ignore')
|
||||||
|
|
||||||
hostname = re.sub('[ _]', '-', hostname)
|
hostname = re.sub('[ _]', '-', hostname)
|
||||||
|
|
Loading…
Reference in New Issue