sync with oslo-incubator
- py3 compatibility fixes - Only pass non-None sortby to PrettyTable.get_string fix synced with commit-id: 0d2546b228f13a42355bc54e82256bf17a2eb478 Change-Id: Ic70eba1a10339ad5407541446cd37c9229836965
This commit is contained in:
		@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2013 OpenStack Foundation
 | 
					# Copyright 2013 OpenStack Foundation
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2013 OpenStack Foundation
 | 
					# Copyright 2013 OpenStack Foundation
 | 
				
			||||||
# Copyright 2013 Spanish National Research Council.
 | 
					# Copyright 2013 Spanish National Research Council.
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
@@ -23,8 +21,8 @@ import abc
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import six
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import six
 | 
				
			||||||
from stevedore import extension
 | 
					from stevedore import extension
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ceilometerclient.openstack.common.apiclient import exceptions
 | 
					from ceilometerclient.openstack.common.apiclient import exceptions
 | 
				
			||||||
@@ -76,7 +74,7 @@ def load_plugin(auth_system):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def load_plugin_from_args(args):
 | 
					def load_plugin_from_args(args):
 | 
				
			||||||
    """Load requred plugin and populate it with options.
 | 
					    """Load required plugin and populate it with options.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Try to guess auth system if it is not specified. Systems are tried in
 | 
					    Try to guess auth system if it is not specified. Systems are tried in
 | 
				
			||||||
    alphabetical order.
 | 
					    alphabetical order.
 | 
				
			||||||
@@ -91,7 +89,7 @@ def load_plugin_from_args(args):
 | 
				
			|||||||
        plugin.sufficient_options()
 | 
					        plugin.sufficient_options()
 | 
				
			||||||
        return plugin
 | 
					        return plugin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for plugin_auth_system in sorted(_discovered_plugins.iterkeys()):
 | 
					    for plugin_auth_system in sorted(six.iterkeys(_discovered_plugins)):
 | 
				
			||||||
        plugin_class = _discovered_plugins[plugin_auth_system]
 | 
					        plugin_class = _discovered_plugins[plugin_auth_system]
 | 
				
			||||||
        plugin = plugin_class()
 | 
					        plugin = plugin_class()
 | 
				
			||||||
        plugin.parse_opts(args)
 | 
					        plugin.parse_opts(args)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2010 Jacob Kaplan-Moss
 | 
					# Copyright 2010 Jacob Kaplan-Moss
 | 
				
			||||||
# Copyright 2011 OpenStack Foundation
 | 
					# Copyright 2011 OpenStack Foundation
 | 
				
			||||||
# Copyright 2012 Grid Dynamics
 | 
					# Copyright 2012 Grid Dynamics
 | 
				
			||||||
@@ -26,9 +24,10 @@ Base utilities to build API operation managers and objects on top of.
 | 
				
			|||||||
# pylint: disable=E1102
 | 
					# pylint: disable=E1102
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import abc
 | 
					import abc
 | 
				
			||||||
import six
 | 
					 | 
				
			||||||
import urllib
 | 
					import urllib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import six
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ceilometerclient.openstack.common.apiclient import exceptions
 | 
					from ceilometerclient.openstack.common.apiclient import exceptions
 | 
				
			||||||
from ceilometerclient.openstack.common import strutils
 | 
					from ceilometerclient.openstack.common import strutils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2010 Jacob Kaplan-Moss
 | 
					# Copyright 2010 Jacob Kaplan-Moss
 | 
				
			||||||
# Copyright 2011 OpenStack Foundation
 | 
					# Copyright 2011 OpenStack Foundation
 | 
				
			||||||
# Copyright 2011 Piston Cloud Computing, Inc.
 | 
					# Copyright 2011 Piston Cloud Computing, Inc.
 | 
				
			||||||
@@ -52,7 +50,7 @@ class HTTPClient(object):
 | 
				
			|||||||
      services (e.g., for compute and image clients);
 | 
					      services (e.g., for compute and image clients);
 | 
				
			||||||
    - reissue authentication request for expired tokens;
 | 
					    - reissue authentication request for expired tokens;
 | 
				
			||||||
    - encode/decode JSON bodies;
 | 
					    - encode/decode JSON bodies;
 | 
				
			||||||
    - raise exeptions on HTTP errors;
 | 
					    - raise exceptions on HTTP errors;
 | 
				
			||||||
    - pluggable authentication;
 | 
					    - pluggable authentication;
 | 
				
			||||||
    - store authentication information in a keyring;
 | 
					    - store authentication information in a keyring;
 | 
				
			||||||
    - store time spent for requests;
 | 
					    - store time spent for requests;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2010 Jacob Kaplan-Moss
 | 
					# Copyright 2010 Jacob Kaplan-Moss
 | 
				
			||||||
# Copyright 2011 Nebula, Inc.
 | 
					# Copyright 2011 Nebula, Inc.
 | 
				
			||||||
# Copyright 2013 Alessio Ababilov
 | 
					# Copyright 2013 Alessio Ababilov
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2013 OpenStack Foundation
 | 
					# Copyright 2013 OpenStack Foundation
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
@@ -27,11 +25,11 @@ places where actual behavior differs from the spec.
 | 
				
			|||||||
# pylint: disable=W0102
 | 
					# pylint: disable=W0102
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
import urlparse
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ceilometerclient.openstack.common.apiclient import client
 | 
					from ceilometerclient.openstack.common.apiclient import client
 | 
				
			||||||
 | 
					from ceilometerclient.openstack.common.py3kcompat import urlutils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def assert_has_keys(dct, required=[], optional=[]):
 | 
					def assert_has_keys(dct, required=[], optional=[]):
 | 
				
			||||||
@@ -146,7 +144,7 @@ class FakeHTTPClient(client.HTTPClient):
 | 
				
			|||||||
                                 "text": fixture[1]})
 | 
					                                 "text": fixture[1]})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Call the method
 | 
					        # Call the method
 | 
				
			||||||
        args = urlparse.parse_qsl(urlparse.urlparse(url)[4])
 | 
					        args = urlutils.parse_qsl(urlutils.urlparse(url)[4])
 | 
				
			||||||
        kwargs.update(args)
 | 
					        kwargs.update(args)
 | 
				
			||||||
        munged_url = url.rsplit('?', 1)[0]
 | 
					        munged_url = url.rsplit('?', 1)[0]
 | 
				
			||||||
        munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
 | 
					        munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2012 Red Hat, Inc.
 | 
					# Copyright 2012 Red Hat, Inc.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
					#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
				
			||||||
@@ -25,6 +23,8 @@ import sys
 | 
				
			|||||||
import textwrap
 | 
					import textwrap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import prettytable
 | 
					import prettytable
 | 
				
			||||||
 | 
					import six
 | 
				
			||||||
 | 
					from six import moves
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ceilometerclient.openstack.common.apiclient import exceptions
 | 
					from ceilometerclient.openstack.common.apiclient import exceptions
 | 
				
			||||||
from ceilometerclient.openstack.common import strutils
 | 
					from ceilometerclient.openstack.common import strutils
 | 
				
			||||||
@@ -141,9 +141,9 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
 | 
				
			|||||||
    formatters = formatters or {}
 | 
					    formatters = formatters or {}
 | 
				
			||||||
    mixed_case_fields = mixed_case_fields or []
 | 
					    mixed_case_fields = mixed_case_fields or []
 | 
				
			||||||
    if sortby_index is None:
 | 
					    if sortby_index is None:
 | 
				
			||||||
        sortby = None
 | 
					        kwargs = {}
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        sortby = fields[sortby_index]
 | 
					        kwargs = {'sortby': fields[sortby_index]}
 | 
				
			||||||
    pt = prettytable.PrettyTable(fields, caching=False)
 | 
					    pt = prettytable.PrettyTable(fields, caching=False)
 | 
				
			||||||
    pt.align = 'l'
 | 
					    pt.align = 'l'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -161,7 +161,7 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
 | 
				
			|||||||
                row.append(data)
 | 
					                row.append(data)
 | 
				
			||||||
        pt.add_row(row)
 | 
					        pt.add_row(row)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    print(strutils.safe_encode(pt.get_string(sortby=sortby)))
 | 
					    print(strutils.safe_encode(pt.get_string(**kwargs)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def print_dict(dct, dict_property="Property", wrap=0):
 | 
					def print_dict(dct, dict_property="Property", wrap=0):
 | 
				
			||||||
@@ -181,7 +181,7 @@ def print_dict(dct, dict_property="Property", wrap=0):
 | 
				
			|||||||
            v = textwrap.fill(str(v), wrap)
 | 
					            v = textwrap.fill(str(v), wrap)
 | 
				
			||||||
        # if value has a newline, add in multiple rows
 | 
					        # if value has a newline, add in multiple rows
 | 
				
			||||||
        # e.g. fault with stacktrace
 | 
					        # e.g. fault with stacktrace
 | 
				
			||||||
        if v and isinstance(v, basestring) and r'\n' in v:
 | 
					        if v and isinstance(v, six.string_types) and r'\n' in v:
 | 
				
			||||||
            lines = v.strip().split(r'\n')
 | 
					            lines = v.strip().split(r'\n')
 | 
				
			||||||
            col1 = k
 | 
					            col1 = k
 | 
				
			||||||
            for line in lines:
 | 
					            for line in lines:
 | 
				
			||||||
@@ -199,7 +199,7 @@ def get_password(max_password_prompts=3):
 | 
				
			|||||||
    if hasattr(sys.stdin, "isatty") and sys.stdin.isatty():
 | 
					    if hasattr(sys.stdin, "isatty") and sys.stdin.isatty():
 | 
				
			||||||
        # Check for Ctrl-D
 | 
					        # Check for Ctrl-D
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            for _ in xrange(max_password_prompts):
 | 
					            for _ in moves.range(max_password_prompts):
 | 
				
			||||||
                pw1 = getpass.getpass("OS Password: ")
 | 
					                pw1 = getpass.getpass("OS Password: ")
 | 
				
			||||||
                if verify:
 | 
					                if verify:
 | 
				
			||||||
                    pw2 = getpass.getpass("Please verify: ")
 | 
					                    pw2 = getpass.getpass("Please verify: ")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2012 Red Hat, Inc.
 | 
					# Copyright 2012 Red Hat, Inc.
 | 
				
			||||||
# Copyright 2013 IBM Corp.
 | 
					# Copyright 2013 IBM Corp.
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
@@ -317,7 +315,7 @@ def get_available_languages(domain):
 | 
				
			|||||||
    # NOTE(luisg): Babel <1.0 used a function called list(), which was
 | 
					    # NOTE(luisg): Babel <1.0 used a function called list(), which was
 | 
				
			||||||
    # renamed to locale_identifiers() in >=1.0, the requirements master list
 | 
					    # renamed to locale_identifiers() in >=1.0, the requirements master list
 | 
				
			||||||
    # requires >=0.9.6, uncapped, so defensively work with both. We can remove
 | 
					    # requires >=0.9.6, uncapped, so defensively work with both. We can remove
 | 
				
			||||||
    # this check when the master list updates to >=1.0, and all projects udpate
 | 
					    # this check when the master list updates to >=1.0, and update all projects
 | 
				
			||||||
    list_identifiers = (getattr(localedata, 'list', None) or
 | 
					    list_identifiers = (getattr(localedata, 'list', None) or
 | 
				
			||||||
                        getattr(localedata, 'locale_identifiers'))
 | 
					                        getattr(localedata, 'locale_identifiers'))
 | 
				
			||||||
    locale_identifiers = list_identifiers()
 | 
					    locale_identifiers = list_identifiers()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2011 OpenStack Foundation.
 | 
					# Copyright 2011 OpenStack Foundation.
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Copyright 2013 Canonical Ltd.
 | 
					# Copyright 2013 Canonical Ltd.
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Copyright 2013 Canonical Ltd.
 | 
					# Copyright 2013 Canonical Ltd.
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
@@ -36,6 +35,7 @@ if six.PY3:
 | 
				
			|||||||
    urlparse = urllib.parse.urlparse
 | 
					    urlparse = urllib.parse.urlparse
 | 
				
			||||||
    urlsplit = urllib.parse.urlsplit
 | 
					    urlsplit = urllib.parse.urlsplit
 | 
				
			||||||
    urlunsplit = urllib.parse.urlunsplit
 | 
					    urlunsplit = urllib.parse.urlunsplit
 | 
				
			||||||
 | 
					    SplitResult = urllib.parse.SplitResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    urlopen = urllib.request.urlopen
 | 
					    urlopen = urllib.request.urlopen
 | 
				
			||||||
    URLError = urllib.error.URLError
 | 
					    URLError = urllib.error.URLError
 | 
				
			||||||
@@ -56,6 +56,7 @@ else:
 | 
				
			|||||||
    urlparse = parse.urlparse
 | 
					    urlparse = parse.urlparse
 | 
				
			||||||
    urlsplit = parse.urlsplit
 | 
					    urlsplit = parse.urlsplit
 | 
				
			||||||
    urlunsplit = parse.urlunsplit
 | 
					    urlunsplit = parse.urlunsplit
 | 
				
			||||||
 | 
					    SplitResult = parse.SplitResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    urlopen = urllib2.urlopen
 | 
					    urlopen = urllib2.urlopen
 | 
				
			||||||
    URLError = urllib2.URLError
 | 
					    URLError = urllib2.URLError
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2011 OpenStack Foundation.
 | 
					# Copyright 2011 OpenStack Foundation.
 | 
				
			||||||
# All Rights Reserved.
 | 
					# All Rights Reserved.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
@@ -101,7 +99,7 @@ def safe_decode(text, incoming=None, errors='strict'):
 | 
				
			|||||||
        values http://docs.python.org/2/library/codecs.html
 | 
					        values http://docs.python.org/2/library/codecs.html
 | 
				
			||||||
    :returns: text or a unicode `incoming` encoded
 | 
					    :returns: text or a unicode `incoming` encoded
 | 
				
			||||||
                representation of it.
 | 
					                representation of it.
 | 
				
			||||||
    :raises TypeError: If text is not an isntance of str
 | 
					    :raises TypeError: If text is not an instance of str
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    if not isinstance(text, six.string_types):
 | 
					    if not isinstance(text, six.string_types):
 | 
				
			||||||
        raise TypeError("%s can't be decoded" % type(text))
 | 
					        raise TypeError("%s can't be decoded" % type(text))
 | 
				
			||||||
@@ -144,7 +142,7 @@ def safe_encode(text, incoming=None,
 | 
				
			|||||||
        values http://docs.python.org/2/library/codecs.html
 | 
					        values http://docs.python.org/2/library/codecs.html
 | 
				
			||||||
    :returns: text or a bytestring `encoding` encoded
 | 
					    :returns: text or a bytestring `encoding` encoded
 | 
				
			||||||
                representation of it.
 | 
					                representation of it.
 | 
				
			||||||
    :raises TypeError: If text is not an isntance of str
 | 
					    :raises TypeError: If text is not an instance of str
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    if not isinstance(text, six.string_types):
 | 
					    if not isinstance(text, six.string_types):
 | 
				
			||||||
        raise TypeError("%s can't be encoded" % type(text))
 | 
					        raise TypeError("%s can't be encoded" % type(text))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,3 @@
 | 
				
			|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Copyright 2013 OpenStack Foundation
 | 
					# Copyright 2013 OpenStack Foundation
 | 
				
			||||||
# Copyright 2013 IBM Corp.
 | 
					# Copyright 2013 IBM Corp.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user