Merge "Remove unicode-related Python2-only code"
This commit is contained in:
commit
590f793c9f
@ -57,7 +57,7 @@ master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = 'python-glanceclient'
|
||||
copyright = u'OpenStack Foundation'
|
||||
copyright = 'OpenStack Foundation'
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
add_function_parentheses = True
|
||||
@ -83,8 +83,8 @@ htmlhelp_basename = '%sdoc' % project
|
||||
# -- Options for man page output ----------------------------------------------
|
||||
|
||||
# Grouping the document tree for man pages.
|
||||
# List of tuples 'sourcefile', 'target', u'title', u'Authors name', 'manual'
|
||||
# List of tuples 'sourcefile', 'target', 'title', 'Authors name', 'manual'
|
||||
man_pages = [
|
||||
('cli/glance', 'glance', u'Client for OpenStack Images API',
|
||||
[u'OpenStack Foundation'], 1),
|
||||
('cli/glance', 'glance', 'Client for OpenStack Images API',
|
||||
['OpenStack Foundation'], 1),
|
||||
]
|
||||
|
@ -271,34 +271,11 @@ def print_list(objs, fields, formatters=None, field_settings=None):
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, None) or ''
|
||||
row.append(data)
|
||||
count = 0
|
||||
# Converts unicode values in list to string
|
||||
for part in row:
|
||||
count = count + 1
|
||||
if isinstance(part, list):
|
||||
part = unicode_key_value_to_string(part)
|
||||
row[count - 1] = part
|
||||
pt.add_row(row)
|
||||
|
||||
print(encodeutils.safe_decode(pt.get_string()))
|
||||
|
||||
|
||||
def _encode(src):
|
||||
"""remove extra 'u' in PY2."""
|
||||
return src
|
||||
|
||||
|
||||
def unicode_key_value_to_string(src):
|
||||
"""Recursively converts dictionary keys to strings."""
|
||||
if isinstance(src, dict):
|
||||
return dict((_encode(k),
|
||||
_encode(unicode_key_value_to_string(v)))
|
||||
for k, v in src.items())
|
||||
if isinstance(src, list):
|
||||
return [unicode_key_value_to_string(l) for l in src]
|
||||
return _encode(src)
|
||||
|
||||
|
||||
def print_dict(d, max_column_width=80):
|
||||
pt = prettytable.PrettyTable(['Property', 'Value'], caching=False)
|
||||
pt.align = 'l'
|
||||
|
@ -66,7 +66,7 @@ class TestClient(testtools.TestCase):
|
||||
|
||||
self.endpoint = 'http://example.com:9292'
|
||||
self.ssl_endpoint = 'https://example.com:9292'
|
||||
self.token = u'abc123'
|
||||
self.token = 'abc123'
|
||||
|
||||
self.client = getattr(self, self.create_client)()
|
||||
|
||||
@ -80,7 +80,7 @@ class TestClient(testtools.TestCase):
|
||||
'X-Service-Catalog': 'service_catalog',
|
||||
}
|
||||
# with token
|
||||
kwargs = {'token': u'fake-token',
|
||||
kwargs = {'token': 'fake-token',
|
||||
'identity_headers': identity_headers}
|
||||
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
|
||||
self.assertEqual('auth_token', http_client_object.auth_token)
|
||||
@ -96,10 +96,10 @@ class TestClient(testtools.TestCase):
|
||||
'X-Service-Catalog': 'service_catalog',
|
||||
}
|
||||
# without X-Auth-Token in identity headers
|
||||
kwargs = {'token': u'fake-token',
|
||||
kwargs = {'token': 'fake-token',
|
||||
'identity_headers': identity_headers}
|
||||
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
|
||||
self.assertEqual(u'fake-token', http_client_object.auth_token)
|
||||
self.assertEqual('fake-token', http_client_object.auth_token)
|
||||
self.assertTrue(http_client_object.identity_headers.
|
||||
get('X-Auth-Token') is None)
|
||||
|
||||
@ -210,12 +210,12 @@ class TestClient(testtools.TestCase):
|
||||
self.mock.get(self.endpoint + path, text=text,
|
||||
headers={"Content-Type": "text/plain"})
|
||||
|
||||
headers = {"test": u'ni\xf1o'}
|
||||
headers = {"test": 'ni\xf1o'}
|
||||
resp, body = self.client.get(path, headers=headers)
|
||||
self.assertEqual(text, resp.text)
|
||||
|
||||
def test_headers_encoding(self):
|
||||
value = u'ni\xf1o'
|
||||
value = 'ni\xf1o'
|
||||
fake_location = b'http://web_server:80/images/fake.img'
|
||||
headers = {"test": value,
|
||||
"none-val": None,
|
||||
@ -262,7 +262,7 @@ class TestClient(testtools.TestCase):
|
||||
ksarqh = mock_ksarq.call_args[1]['headers']
|
||||
# Only one Content-Type header (of any text-type)
|
||||
self.assertEqual(1, [encodeutils.safe_decode(key)
|
||||
for key in ksarqh.keys()].count(u'Content-Type'))
|
||||
for key in ksarqh.keys()].count('Content-Type'))
|
||||
# And it's the one we set
|
||||
self.assertEqual(b"application/openstack-images-v2.1-json-patch",
|
||||
ksarqh[b"Content-Type"])
|
||||
@ -295,7 +295,7 @@ class TestClient(testtools.TestCase):
|
||||
|
||||
def test_parse_endpoint(self):
|
||||
endpoint = 'http://example.com:9292'
|
||||
test_client = http.HTTPClient(endpoint, token=u'adc123')
|
||||
test_client = http.HTTPClient(endpoint, token='adc123')
|
||||
actual = test_client.parse_endpoint(endpoint)
|
||||
expected = parse.SplitResult(scheme='http',
|
||||
netloc='example.com:9292', path='',
|
||||
@ -304,7 +304,7 @@ class TestClient(testtools.TestCase):
|
||||
|
||||
def test_get_connections_kwargs_http(self):
|
||||
endpoint = 'http://example.com:9292'
|
||||
test_client = http.HTTPClient(endpoint, token=u'adc123')
|
||||
test_client = http.HTTPClient(endpoint, token='adc123')
|
||||
self.assertEqual(600.0, test_client.timeout)
|
||||
|
||||
def test__chunk_body_exact_size_chunk(self):
|
||||
@ -321,7 +321,7 @@ class TestClient(testtools.TestCase):
|
||||
path = '/v1/images/'
|
||||
self.mock.post(self.endpoint + path, text=text)
|
||||
|
||||
headers = {"test": u'chunked_request'}
|
||||
headers = {"test": 'chunked_request'}
|
||||
resp, body = self.client.post(path, headers=headers, data=data)
|
||||
self.assertIsInstance(self.mock.last_request.body, types.GeneratorType)
|
||||
self.assertEqual(text, resp.text)
|
||||
@ -332,7 +332,7 @@ class TestClient(testtools.TestCase):
|
||||
text = 'OK'
|
||||
self.mock.post(self.endpoint + path, text=text)
|
||||
|
||||
headers = {"test": u'chunked_request'}
|
||||
headers = {"test": 'chunked_request'}
|
||||
resp, body = self.client.post(path, headers=headers, data=data)
|
||||
|
||||
self.assertEqual(text, resp.text)
|
||||
@ -487,7 +487,7 @@ class TestClient(testtools.TestCase):
|
||||
headers = self.mock.last_request.headers
|
||||
self.assertEqual(refreshed_token, headers['X-Auth-Token'])
|
||||
# regression check for bug 1448080
|
||||
unicode_token = u'ni\xf1o+=='
|
||||
unicode_token = 'ni\xf1o+=='
|
||||
http_client.auth_token = unicode_token
|
||||
http_client.get(path)
|
||||
headers = self.mock.last_request.headers
|
||||
|
@ -122,7 +122,7 @@ class TestUtils(testtools.TestCase):
|
||||
# test for removing 'u' from lists in print_list output
|
||||
columns = ['ID', 'Tags']
|
||||
images = [Struct(**{'id': 'b8e1c57e-907a-4239-aed8-0df8e54b8d2d',
|
||||
'tags': [u'Name1', u'Tag_123', u'veeeery long']})]
|
||||
'tags': ['Name1', 'Tag_123', 'veeeery long']})]
|
||||
saved_stdout = sys.stdout
|
||||
try:
|
||||
sys.stdout = output_list = io.StringIO()
|
||||
@ -178,12 +178,6 @@ class TestUtils(testtools.TestCase):
|
||||
''',
|
||||
output_list.getvalue())
|
||||
|
||||
def test_unicode_key_value_to_string(self):
|
||||
src = {u'key': u'\u70fd\u7231\u5a77'}
|
||||
# u'xxxx' in PY3 is str, we will not get extra 'u' from cli
|
||||
# output in PY3
|
||||
self.assertEqual(src, utils.unicode_key_value_to_string(src))
|
||||
|
||||
def test_schema_args_with_list_types(self):
|
||||
# NOTE(flaper87): Regression for bug
|
||||
# https://bugs.launchpad.net/python-glanceclient/+bug/1401032
|
||||
|
@ -504,7 +504,7 @@ class ImageManagerTest(testtools.TestCase):
|
||||
self.assertEqual(False, image.is_public)
|
||||
self.assertEqual(False, image.protected)
|
||||
self.assertEqual(False, image.deleted)
|
||||
self.assertEqual({u'arch': u'x86_64'}, image.properties)
|
||||
self.assertEqual({'arch': 'x86_64'}, image.properties)
|
||||
|
||||
def test_get_int(self):
|
||||
image = self.mgr.get(1)
|
||||
@ -515,7 +515,7 @@ class ImageManagerTest(testtools.TestCase):
|
||||
self.assertEqual(False, image.is_public)
|
||||
self.assertEqual(False, image.protected)
|
||||
self.assertEqual(False, image.deleted)
|
||||
self.assertEqual({u'arch': u'x86_64'}, image.properties)
|
||||
self.assertEqual({'arch': 'x86_64'}, image.properties)
|
||||
|
||||
def test_get_encoding(self):
|
||||
image = self.mgr.get('3')
|
||||
|
@ -550,10 +550,10 @@ data_fixtures = {
|
||||
{
|
||||
'id': 'a2b83adc-888e-11e3-8872-78acc0b951d8',
|
||||
'name': 'image-location-tests',
|
||||
'locations': [{u'url': u'http://foo.com/',
|
||||
u'metadata': {u'foo': u'foometa'}},
|
||||
{u'url': u'http://bar.com/',
|
||||
u'metadata': {u'bar': u'barmeta'}}],
|
||||
'locations': [{'url': 'http://foo.com/',
|
||||
'metadata': {'foo': 'foometa'}},
|
||||
{'url': 'http://bar.com/',
|
||||
'metadata': {'bar': 'barmeta'}}],
|
||||
},
|
||||
),
|
||||
'PATCH': (
|
||||
|
@ -854,7 +854,7 @@ class ShellV2Test(testtools.TestCase):
|
||||
|
||||
@mock.patch('sys.stdin', autospec=True)
|
||||
def test_do_image_create_with_unicode(self, mock_stdin):
|
||||
name = u'\u041f\u0420\u0418\u0412\u0415\u0422\u0418\u041a'
|
||||
name = '\u041f\u0420\u0418\u0412\u0415\u0422\u0418\u041a'
|
||||
|
||||
args = self._make_args({'name': name,
|
||||
'file': None})
|
||||
|
@ -55,8 +55,8 @@ source_suffix = '.rst'
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'glanceclient Release Notes'
|
||||
copyright = u'2016, Glance Developers'
|
||||
project = 'glanceclient Release Notes'
|
||||
copyright = '2016, Glance Developers'
|
||||
|
||||
openstackdocs_repo_name = 'openstack/python-glanceclient'
|
||||
openstackdocs_bug_project = 'python-glanceclient'
|
||||
@ -206,8 +206,8 @@ latex_elements = {
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
('index', 'glanceclientReleaseNotes.tex',
|
||||
u'glanceclient Release Notes Documentation',
|
||||
u'Glance Developers', 'manual'),
|
||||
'glanceclient Release Notes Documentation',
|
||||
'Glance Developers', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
@ -237,8 +237,8 @@ latex_documents = [
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'glanceclientreleasenotes',
|
||||
u'glanceclient Release Notes Documentation',
|
||||
[u'Glance Developers'], 1)
|
||||
'glanceclient Release Notes Documentation',
|
||||
['Glance Developers'], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
@ -252,8 +252,8 @@ man_pages = [
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'glanceclientReleaseNotes',
|
||||
u'glanceclient Release Notes Documentation',
|
||||
u'Glance Developers', 'glanceclientReleaseNotes',
|
||||
'glanceclient Release Notes Documentation',
|
||||
'Glance Developers', 'glanceclientReleaseNotes',
|
||||
'Python bindings for the OpenStack Image service.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user