python3: Fix unicode compatibility python2/python3
Python3 enforces the distinction between byte strings and text strings more rigorously than python2. So use six.text_type/six.u() where appropriate Change-Id: I890e19cb857e10f0292aabdaebaa8e7a7bd8db23 Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
parent
05ca996e67
commit
8c4e145b92
@ -39,8 +39,8 @@ source_suffix = '.rst'
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'python-novaclient'
|
||||
copyright = u'OpenStack Contributors'
|
||||
project = 'python-novaclient'
|
||||
copyright = 'OpenStack Contributors'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
@ -93,8 +93,8 @@ pygments_style = 'sphinx'
|
||||
# List of tuples 'sourcefile', 'target', u'title', u'Authors name', 'manual'
|
||||
|
||||
man_pages = [
|
||||
('man/nova', 'nova', u'OpenStack Nova command line client',
|
||||
[u'OpenStack Contributors'], 1),
|
||||
('man/nova', 'nova', 'OpenStack Nova command line client',
|
||||
['OpenStack Contributors'], 1),
|
||||
]
|
||||
|
||||
# -- Options for HTML output --------------------------------------------------
|
||||
@ -183,8 +183,8 @@ htmlhelp_basename = 'python-novaclientdoc'
|
||||
# (source start file, target name, title, author, documentclass [howto/manual])
|
||||
# .
|
||||
latex_documents = [
|
||||
('index', 'python-novaclient.tex', u'python-novaclient Documentation',
|
||||
u'Rackspace - based on work by Jacob Kaplan-Moss', 'manual'),
|
||||
('index', 'python-novaclient.tex', 'python-novaclient Documentation',
|
||||
'Rackspace - based on work by Jacob Kaplan-Moss', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
|
@ -26,10 +26,12 @@ import imp
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import pkg_resources
|
||||
import pkgutil
|
||||
import sys
|
||||
|
||||
import pkg_resources
|
||||
import six
|
||||
|
||||
HAS_KEYRING = False
|
||||
all_errors = ValueError
|
||||
try:
|
||||
@ -766,7 +768,8 @@ def main():
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(e, exc_info=1)
|
||||
print("ERROR: %s" % strutils.safe_encode(unicode(e)), file=sys.stderr)
|
||||
print("ERROR: %s" % strutils.safe_encode(six.text_type(e)),
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
from datetime import datetime
|
||||
import urlparse
|
||||
|
||||
import six
|
||||
|
||||
from novaclient import client as base_client
|
||||
from novaclient.v1_1 import client
|
||||
from novaclient.tests import fakes
|
||||
@ -1208,87 +1210,93 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
#
|
||||
def get_os_simple_tenant_usage(self, **kw):
|
||||
return (200, {},
|
||||
{u'tenant_usages': [{
|
||||
u'total_memory_mb_usage': 25451.762807466665,
|
||||
u'total_vcpus_usage': 49.71047423333333,
|
||||
u'total_hours': 49.71047423333333,
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'stop': u'2012-01-22 19:48:41.750722',
|
||||
u'server_usages': [{
|
||||
u'hours': 49.71047423333333,
|
||||
u'uptime': 27035,
|
||||
u'local_gb': 0,
|
||||
u'ended_at': None,
|
||||
u'name': u'f15image1',
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'vcpus': 1,
|
||||
u'memory_mb': 512,
|
||||
u'state': u'active',
|
||||
u'flavor': u'm1.tiny',
|
||||
u'started_at': u'2012-01-20 18:06:06.479998'}],
|
||||
u'start': u'2011-12-25 19:48:41.750687',
|
||||
u'total_local_gb_usage': 0.0}]})
|
||||
{six.u('tenant_usages'): [{
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035,
|
||||
six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('vcpus'): 1,
|
||||
six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'):
|
||||
six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}]})
|
||||
|
||||
def get_os_simple_tenant_usage_tenantfoo(self, **kw):
|
||||
return (200, {},
|
||||
{u'tenant_usage': {
|
||||
u'total_memory_mb_usage': 25451.762807466665,
|
||||
u'total_vcpus_usage': 49.71047423333333,
|
||||
u'total_hours': 49.71047423333333,
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'stop': u'2012-01-22 19:48:41.750722',
|
||||
u'server_usages': [{
|
||||
u'hours': 49.71047423333333,
|
||||
u'uptime': 27035, u'local_gb': 0,
|
||||
u'ended_at': None,
|
||||
u'name': u'f15image1',
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'vcpus': 1, u'memory_mb': 512,
|
||||
u'state': u'active',
|
||||
u'flavor': u'm1.tiny',
|
||||
u'started_at': u'2012-01-20 18:06:06.479998'}],
|
||||
u'start': u'2011-12-25 19:48:41.750687',
|
||||
u'total_local_gb_usage': 0.0}})
|
||||
{six.u('tenant_usage'): {
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035, six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('vcpus'): 1, six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'):
|
||||
six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}})
|
||||
|
||||
def get_os_simple_tenant_usage_test(self, **kw):
|
||||
return (200, {}, {u'tenant_usage': {
|
||||
u'total_memory_mb_usage': 25451.762807466665,
|
||||
u'total_vcpus_usage': 49.71047423333333,
|
||||
u'total_hours': 49.71047423333333,
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'stop': u'2012-01-22 19:48:41.750722',
|
||||
u'server_usages': [{
|
||||
u'hours': 49.71047423333333,
|
||||
u'uptime': 27035, u'local_gb': 0,
|
||||
u'ended_at': None,
|
||||
u'name': u'f15image1',
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'vcpus': 1, u'memory_mb': 512,
|
||||
u'state': u'active',
|
||||
u'flavor': u'm1.tiny',
|
||||
u'started_at': u'2012-01-20 18:06:06.479998'}],
|
||||
u'start': u'2011-12-25 19:48:41.750687',
|
||||
u'total_local_gb_usage': 0.0}})
|
||||
return (200, {}, {six.u('tenant_usage'): {
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035, six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('vcpus'): 1, six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'): six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}})
|
||||
|
||||
def get_os_simple_tenant_usage_tenant_id(self, **kw):
|
||||
return (200, {}, {u'tenant_usage': {
|
||||
u'total_memory_mb_usage': 25451.762807466665,
|
||||
u'total_vcpus_usage': 49.71047423333333,
|
||||
u'total_hours': 49.71047423333333,
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'stop': u'2012-01-22 19:48:41.750722',
|
||||
u'server_usages': [{
|
||||
u'hours': 49.71047423333333,
|
||||
u'uptime': 27035, u'local_gb': 0,
|
||||
u'ended_at': None,
|
||||
u'name': u'f15image1',
|
||||
u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869',
|
||||
u'vcpus': 1, u'memory_mb': 512,
|
||||
u'state': u'active',
|
||||
u'flavor': u'm1.tiny',
|
||||
u'started_at': u'2012-01-20 18:06:06.479998'}],
|
||||
u'start': u'2011-12-25 19:48:41.750687',
|
||||
u'total_local_gb_usage': 0.0}})
|
||||
return (200, {}, {six.u('tenant_usage'): {
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035, six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('vcpus'): 1, six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'): six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}})
|
||||
#
|
||||
# Certificates
|
||||
#
|
||||
|
@ -14,6 +14,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from novaclient.v1_1 import availability_zones
|
||||
from novaclient.v1_1 import shell
|
||||
from novaclient.tests.v1_1 import fakes
|
||||
@ -39,8 +41,8 @@ class AvailabilityZoneTest(utils.TestCase):
|
||||
|
||||
self.assertEqual(2, len(zones))
|
||||
|
||||
l0 = [u'zone-1', u'available']
|
||||
l1 = [u'zone-2', u'not available']
|
||||
l0 = [six.u('zone-1'), six.u('available')]
|
||||
l1 = [six.u('zone-2'), six.u('not available')]
|
||||
|
||||
z0 = shell._treeizeAvailabilityZone(zones[0])
|
||||
z1 = shell._treeizeAvailabilityZone(zones[1])
|
||||
@ -60,15 +62,18 @@ class AvailabilityZoneTest(utils.TestCase):
|
||||
|
||||
self.assertEqual(3, len(zones))
|
||||
|
||||
l0 = [u'zone-1', u'available']
|
||||
l1 = [u'|- fake_host-1', u'']
|
||||
l2 = [u'| |- nova-compute', u'enabled :-) 2012-12-26 14:45:25']
|
||||
l3 = [u'internal', u'available']
|
||||
l4 = [u'|- fake_host-1', u'']
|
||||
l5 = [u'| |- nova-sched', u'enabled :-) 2012-12-26 14:45:25']
|
||||
l6 = [u'|- fake_host-2', u'']
|
||||
l7 = [u'| |- nova-network', u'enabled XXX 2012-12-26 14:45:24']
|
||||
l8 = [u'zone-2', u'not available']
|
||||
l0 = [six.u('zone-1'), six.u('available')]
|
||||
l1 = [six.u('|- fake_host-1'), six.u('')]
|
||||
l2 = [six.u('| |- nova-compute'),
|
||||
six.u('enabled :-) 2012-12-26 14:45:25')]
|
||||
l3 = [six.u('internal'), six.u('available')]
|
||||
l4 = [six.u('|- fake_host-1'), six.u('')]
|
||||
l5 = [six.u('| |- nova-sched'),
|
||||
six.u('enabled :-) 2012-12-26 14:45:25')]
|
||||
l6 = [six.u('|- fake_host-2'), six.u('')]
|
||||
l7 = [six.u('| |- nova-network'),
|
||||
six.u('enabled XXX 2012-12-26 14:45:24')]
|
||||
l8 = [six.u('zone-2'), six.u('not available')]
|
||||
|
||||
z0 = shell._treeizeAvailabilityZone(zones[0])
|
||||
z1 = shell._treeizeAvailabilityZone(zones[1])
|
||||
|
@ -3,6 +3,7 @@
|
||||
import StringIO
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from novaclient import exceptions
|
||||
from novaclient.v1_1 import servers
|
||||
@ -108,7 +109,7 @@ class ServersTest(utils.TestCase):
|
||||
image=1,
|
||||
flavor=1,
|
||||
meta={'foo': 'bar'},
|
||||
userdata=u'こんにちは',
|
||||
userdata=six.u('こんにちは'),
|
||||
key_name="fakekey",
|
||||
files={
|
||||
'/etc/passwd': 'some data', # a file
|
||||
|
@ -6,6 +6,7 @@ import textwrap
|
||||
import uuid
|
||||
|
||||
import prettytable
|
||||
import six
|
||||
|
||||
from novaclient import exceptions
|
||||
from novaclient.openstack.common import strutils
|
||||
@ -339,9 +340,9 @@ def slugify(value):
|
||||
"""
|
||||
import unicodedata
|
||||
if not isinstance(value, unicode):
|
||||
value = unicode(value)
|
||||
value = six.text_type(value)
|
||||
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
|
||||
value = unicode(_slugify_strip_re.sub('', value).strip().lower())
|
||||
value = six.text_type(_slugify_strip_re.sub('', value).strip().lower())
|
||||
return _slugify_hyphenate_re.sub('-', value)
|
||||
|
||||
|
||||
|
@ -5,3 +5,4 @@ iso8601>=0.1.4
|
||||
prettytable>=0.6,<0.8
|
||||
requests>=0.8
|
||||
simplejson
|
||||
six
|
||||
|
Loading…
Reference in New Issue
Block a user