Python 3: use six.iteritems and six.string_types
six.iteritems() replaces dictionary.iteritems() on Python 2 and dictionary.items() on Python 3. six.string_types replaces basestring() in Python 2 and str in Python 3. Change-Id: Ia18510d167df35caec83626718010228e2140bc0
This commit is contained in:
@@ -162,8 +162,8 @@ class HTTPClient(object):
|
|||||||
:returns: Dictionary with encoded headers'
|
:returns: Dictionary with encoded headers'
|
||||||
names and values
|
names and values
|
||||||
"""
|
"""
|
||||||
to_str = strutils.safe_encode
|
return dict((strutils.safe_encode(h), strutils.safe_encode(v))
|
||||||
return dict([(to_str(h), to_str(v)) for h, v in headers.iteritems()])
|
for h, v in six.iteritems(headers))
|
||||||
|
|
||||||
def _http_request(self, url, method, **kwargs):
|
def _http_request(self, url, method, **kwargs):
|
||||||
"""Send an http request with the specified characteristics.
|
"""Send an http request with the specified characteristics.
|
||||||
@@ -178,7 +178,7 @@ class HTTPClient(object):
|
|||||||
kwargs['headers'].setdefault('X-Auth-Token', self.auth_token)
|
kwargs['headers'].setdefault('X-Auth-Token', self.auth_token)
|
||||||
|
|
||||||
if self.identity_headers:
|
if self.identity_headers:
|
||||||
for k, v in self.identity_headers.iteritems():
|
for k, v in six.iteritems(self.identity_headers):
|
||||||
kwargs['headers'].setdefault(k, v)
|
kwargs['headers'].setdefault(k, v)
|
||||||
|
|
||||||
self.log_curl_request(method, url, kwargs)
|
self.log_curl_request(method, url, kwargs)
|
||||||
|
@@ -20,6 +20,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
import msvcrt
|
import msvcrt
|
||||||
else:
|
else:
|
||||||
@@ -63,7 +65,7 @@ def schema_args(schema_getter, omit=[]):
|
|||||||
kwargs))
|
kwargs))
|
||||||
else:
|
else:
|
||||||
properties = schema.get('properties', {})
|
properties = schema.get('properties', {})
|
||||||
for name, property in properties.iteritems():
|
for name, property in six.iteritems(properties):
|
||||||
if name in omit:
|
if name in omit:
|
||||||
continue
|
continue
|
||||||
param = '--' + name.replace('_', '-')
|
param = '--' + name.replace('_', '-')
|
||||||
@@ -123,7 +125,7 @@ def print_dict(d, max_column_width=80):
|
|||||||
pt = prettytable.PrettyTable(['Property', 'Value'], caching=False)
|
pt = prettytable.PrettyTable(['Property', 'Value'], caching=False)
|
||||||
pt.align = 'l'
|
pt.align = 'l'
|
||||||
pt.max_width = max_column_width
|
pt.max_width = max_column_width
|
||||||
[pt.add_row(list(r)) for r in d.iteritems()]
|
[pt.add_row(list(r)) for r in six.iteritems(d)]
|
||||||
print(strutils.safe_encode(pt.get_string(sortby='Property')))
|
print(strutils.safe_encode(pt.get_string(sortby='Property')))
|
||||||
|
|
||||||
|
|
||||||
|
@@ -83,7 +83,7 @@ class ImageManager(base.Manager):
|
|||||||
# headers will be encoded later, before the
|
# headers will be encoded later, before the
|
||||||
# request is sent.
|
# request is sent.
|
||||||
def to_str(value):
|
def to_str(value):
|
||||||
if not isinstance(value, basestring):
|
if not isinstance(value, six.string_types):
|
||||||
return str(value)
|
return str(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ class ImageManager(base.Manager):
|
|||||||
|
|
||||||
owner = qp.pop('owner', None)
|
owner = qp.pop('owner', None)
|
||||||
for param, value in six.iteritems(qp):
|
for param, value in six.iteritems(qp):
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, six.string_types):
|
||||||
# Note(flaper87) Url encoding should
|
# Note(flaper87) Url encoding should
|
||||||
# be moved inside http utils, at least
|
# be moved inside http utils, at least
|
||||||
# shouldn't be here.
|
# shouldn't be here.
|
||||||
|
@@ -57,11 +57,11 @@ class Controller(object):
|
|||||||
tags_url_params = []
|
tags_url_params = []
|
||||||
|
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
if isinstance(tag, basestring):
|
if isinstance(tag, six.string_types):
|
||||||
tags_url_params.append({'tag': strutils.safe_encode(tag)})
|
tags_url_params.append({'tag': strutils.safe_encode(tag)})
|
||||||
|
|
||||||
for param, value in six.iteritems(filters):
|
for param, value in six.iteritems(filters):
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, six.string_types):
|
||||||
filters[param] = strutils.safe_encode(value)
|
filters[param] = strutils.safe_encode(value)
|
||||||
|
|
||||||
url = '/v2/images?%s' % urllib.urlencode(filters)
|
url = '/v2/images?%s' % urllib.urlencode(filters)
|
||||||
|
Reference in New Issue
Block a user