Fix unicode issues with Python 3
In Python 3, all strings are unicode and the unicode() function has been removed. For compatibility with both Python 2 and 3, use six.text_type() instead. Partially implements: blueprint python-3 Change-Id: I0934e546d0309ddc986fd48b0f13fa5631813dc8
This commit is contained in:
parent
e8e249e083
commit
b25f60ff43
|
@ -28,6 +28,7 @@ from cliff import commandmanager
|
|||
from keystoneclient import client as keystone_client
|
||||
from keystoneclient import exceptions as keystone_exceptions
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
|
||||
from blazarclient import client as blazar_client
|
||||
from blazarclient import exception
|
||||
|
@ -321,10 +322,10 @@ class BlazarShell(app.App):
|
|||
|
||||
except Exception as err:
|
||||
if self.options.debug:
|
||||
self.log.exception(unicode(err))
|
||||
self.log.exception(six.text_type(err))
|
||||
raise
|
||||
else:
|
||||
self.log.error(unicode(err))
|
||||
self.log.error(six.text_type(err))
|
||||
return 1
|
||||
if self.interactive_mode:
|
||||
_argv = [sys.argv[0]]
|
||||
|
@ -347,16 +348,17 @@ class BlazarShell(app.App):
|
|||
return run_command(cmd, cmd_parser, sub_argv)
|
||||
except Exception as err:
|
||||
if self.options.debug:
|
||||
self.log.exception(unicode(err))
|
||||
self.log.exception(six.text_type(err))
|
||||
else:
|
||||
self.log.error(unicode(err))
|
||||
self.log.error(six.text_type(err))
|
||||
try:
|
||||
self.clean_up(cmd, result, err)
|
||||
except Exception as err2:
|
||||
if self.options.debug:
|
||||
self.log.exception(unicode(err2))
|
||||
self.log.exception(six.text_type(err2))
|
||||
else:
|
||||
self.log.error('Could not clean up: %s', unicode(err2))
|
||||
self.log.error('Could not clean up: %s',
|
||||
six.text_type(err2))
|
||||
if self.options.debug:
|
||||
raise
|
||||
else:
|
||||
|
@ -364,9 +366,10 @@ class BlazarShell(app.App):
|
|||
self.clean_up(cmd, result, None)
|
||||
except Exception as err3:
|
||||
if self.options.debug:
|
||||
self.log.exception(unicode(err3))
|
||||
self.log.exception(six.text_type(err3))
|
||||
else:
|
||||
self.log.error('Could not clean up: %s', unicode(err3))
|
||||
self.log.error('Could not clean up: %s',
|
||||
six.text_type(err3))
|
||||
return result
|
||||
|
||||
def authenticate_user(self):
|
||||
|
@ -446,7 +449,7 @@ class BlazarShell(app.App):
|
|||
def clean_up(self, cmd, result, err):
|
||||
self.log.debug('clean_up %s', cmd.__class__.__name__)
|
||||
if err:
|
||||
self.log.debug('got an error: %s', unicode(err))
|
||||
self.log.debug('got an error: %s', six.text_type(err))
|
||||
|
||||
def configure_logging(self):
|
||||
"""Create logging handlers for any log output."""
|
||||
|
@ -480,7 +483,7 @@ def main(argv=sys.argv[1:]):
|
|||
except exception.BlazarClientException:
|
||||
return 1
|
||||
except Exception as e:
|
||||
print(unicode(e))
|
||||
print(six.text_type(e))
|
||||
return 1
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue