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
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
import pecan
|
||||
import six
|
||||
from pecan import rest
|
||||
|
||||
from sm_api.api.controllers.v1 import base
|
||||
|
@ -110,7 +111,7 @@ class NodesController(rest.RestController):
|
|||
sort_dir=sort_dir)
|
||||
return nodes
|
||||
|
||||
@wsme_pecan.wsexpose(Nodes, unicode)
|
||||
@wsme_pecan.wsexpose(Nodes, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
try:
|
||||
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)
|
||||
|
||||
@wsme_pecan.wsexpose(NodesCollection, unicode, int,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(NodesCollection, six.text_type, int,
|
||||
six.text_type, six.text_type)
|
||||
def get_all(self, marker=None, limit=None,
|
||||
sort_key='name', sort_dir='asc'):
|
||||
"""Retrieve list of nodes."""
|
||||
|
@ -134,13 +135,13 @@ class NodesController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(NodesCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(NodesCommandResult, six.text_type,
|
||||
body=NodesCommand)
|
||||
def put(self, hostname, command):
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
@wsme_pecan.wsexpose(NodesCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(NodesCommandResult, six.text_type,
|
||||
body=NodesCommand)
|
||||
def patch(self, hostname, command):
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import wsme
|
|||
from wsme import types as wsme_types
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
import pecan
|
||||
import six
|
||||
from pecan import rest
|
||||
|
||||
from sm_api.api.controllers.v1 import base
|
||||
|
@ -124,7 +125,7 @@ class ServiceGroupController(rest.RestController):
|
|||
|
||||
return sm_sdas
|
||||
|
||||
@wsme_pecan.wsexpose(ServiceGroup, unicode)
|
||||
@wsme_pecan.wsexpose(ServiceGroup, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
try:
|
||||
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)
|
||||
|
||||
@wsme_pecan.wsexpose(ServiceGroupCollection, unicode, int,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(ServiceGroupCollection, six.text_type, int,
|
||||
six.text_type, six.text_type)
|
||||
def get_all(self, marker=None, limit=None,
|
||||
sort_key='name', sort_dir='asc'):
|
||||
"""Retrieve list of servicegroups."""
|
||||
|
@ -148,13 +149,13 @@ class ServiceGroupController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(ServiceGroupCommandResult, six.text_type,
|
||||
body=ServiceGroupCommand)
|
||||
def put(self, hostname, command):
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
@wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(ServiceGroupCommandResult, six.text_type,
|
||||
body=ServiceGroupCommand)
|
||||
def patch(self, hostname, command):
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
import pecan
|
||||
from pecan import rest
|
||||
import wsme
|
||||
import six
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
import socket
|
||||
|
@ -607,7 +608,7 @@ class ServiceNodeController(rest.RestController):
|
|||
else:
|
||||
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):
|
||||
|
||||
try:
|
||||
|
@ -642,7 +643,7 @@ class ServiceNodeController(rest.RestController):
|
|||
active_services=active_services,
|
||||
swactable_services=swactable_services)
|
||||
|
||||
@wsme_pecan.wsexpose(ServiceNodeCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(ServiceNodeCommandResult, six.text_type,
|
||||
body=ServiceNodeCommand)
|
||||
def patch(self, hostname, command):
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import wsme
|
|||
from wsme import types as wsme_types
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
import pecan
|
||||
import six
|
||||
from pecan import rest
|
||||
|
||||
from sm_api.api.controllers.v1 import base
|
||||
|
@ -109,7 +110,7 @@ class ServicesController(rest.RestController):
|
|||
sort_dir=sort_dir)
|
||||
return services
|
||||
|
||||
@wsme_pecan.wsexpose(Services, unicode)
|
||||
@wsme_pecan.wsexpose(Services, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
try:
|
||||
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)
|
||||
|
||||
@wsme_pecan.wsexpose(Services, unicode)
|
||||
@wsme_pecan.wsexpose(Services, six.text_type)
|
||||
def get_service(self, name):
|
||||
try:
|
||||
rpc_sg = objects.service.get_by_name(pecan.request.context, name)
|
||||
|
@ -126,8 +127,8 @@ class ServicesController(rest.RestController):
|
|||
return None
|
||||
return Services.convert_with_links(rpc_sg)
|
||||
|
||||
@wsme_pecan.wsexpose(ServicesCollection, unicode, int,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(ServicesCollection, six.text_type, int,
|
||||
six.text_type, six.text_type)
|
||||
def get_all(self, marker=None, limit=None,
|
||||
sort_key='name', sort_dir='asc'):
|
||||
"""Retrieve list of services."""
|
||||
|
@ -141,13 +142,13 @@ class ServicesController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(ServicesCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(ServicesCommandResult, six.text_type,
|
||||
body=ServicesCommand)
|
||||
def put(self, hostname, command):
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
@wsme_pecan.wsexpose(ServicesCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(ServicesCommandResult, six.text_type,
|
||||
body=ServicesCommand)
|
||||
def patch(self, hostname, command):
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import wsme
|
|||
from wsme import types as wsme_types
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
import pecan
|
||||
import six
|
||||
from pecan import rest
|
||||
|
||||
from sm_api.api.controllers.v1 import base
|
||||
|
@ -123,7 +124,7 @@ class SmSdaController(rest.RestController):
|
|||
|
||||
return sm_sdas
|
||||
|
||||
@wsme_pecan.wsexpose(SmSda, unicode)
|
||||
@wsme_pecan.wsexpose(SmSda, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
try:
|
||||
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)
|
||||
|
||||
@wsme_pecan.wsexpose(SmSdaCollection, unicode, int,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(SmSdaCollection, six.text_type, int,
|
||||
six.text_type, six.text_type)
|
||||
def get_all(self, marker=None, limit=None,
|
||||
sort_key='name', sort_dir='asc'):
|
||||
"""Retrieve list of sm_sdas."""
|
||||
|
@ -147,13 +148,13 @@ class SmSdaController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(SmSdaCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(SmSdaCommandResult, six.text_type,
|
||||
body=SmSdaCommand)
|
||||
def put(self, hostname, command):
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
@wsme_pecan.wsexpose(SmSdaCommandResult, unicode,
|
||||
@wsme_pecan.wsexpose(SmSdaCommandResult, six.text_type,
|
||||
body=SmSdaCommand)
|
||||
def patch(self, hostname, command):
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ SHOULD include dedicated exception logging.
|
|||
"""
|
||||
|
||||
import functools
|
||||
|
||||
import six
|
||||
from oslo_config import cfg
|
||||
|
||||
from sm_api.common import safe_utils
|
||||
|
@ -161,7 +161,7 @@ class SmApiException(Exception):
|
|||
if self.__class__.__name__.endswith('_Remote'):
|
||||
return self.args[0]
|
||||
else:
|
||||
return unicode(self)
|
||||
return six.text_type(self)
|
||||
|
||||
|
||||
class NotAuthorized(SmApiException):
|
||||
|
|
|
@ -404,7 +404,7 @@ def convert_to_list_dict(lst, label):
|
|||
|
||||
def sanitize_hostname(hostname):
|
||||
"""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 = re.sub('[ _]', '-', hostname)
|
||||
|
|
Loading…
Reference in New Issue