From c0d052a743b7f35c229b1024cbdc47be142658d5 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Fri, 12 Jul 2013 13:47:30 -0400 Subject: python3: Add basic compatibility support. Add python2/python3 compatibility support: - Change basestring to use six.string_type so that six will either use str() or basestring(). - Use six.iteritems to replace dictionary.iteritems() on python2 or dictionary.items() on python3. Change-Id: I3a8eb1ba5b2fb2859169299d37ae6eeb9bb4cac0 Signed-off-by: Chuck Short --- openstack/common/scheduler/filters/capabilities_filter.py | 5 +++-- openstack/common/scheduler/filters/json_filter.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'openstack/common') diff --git a/openstack/common/scheduler/filters/capabilities_filter.py b/openstack/common/scheduler/filters/capabilities_filter.py index 89e2bdb..704ebe8 100644 --- a/openstack/common/scheduler/filters/capabilities_filter.py +++ b/openstack/common/scheduler/filters/capabilities_filter.py @@ -13,11 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. +import six + from openstack.common import log as logging from openstack.common.scheduler import filters from openstack.common.scheduler.filters import extra_specs_ops - LOG = logging.getLogger(__name__) @@ -32,7 +33,7 @@ class CapabilitiesFilter(filters.BaseHostFilter): if not extra_specs: return True - for key, req in extra_specs.iteritems(): + for key, req in six.iteritems(extra_specs): # Either not scope format, or in capabilities scope scope = key.split(':') if len(scope) > 1 and scope[0] != "capabilities": diff --git a/openstack/common/scheduler/filters/json_filter.py b/openstack/common/scheduler/filters/json_filter.py index bc4b4fd..6c90055 100644 --- a/openstack/common/scheduler/filters/json_filter.py +++ b/openstack/common/scheduler/filters/json_filter.py @@ -16,6 +16,8 @@ import operator +import six + from openstack.common import jsonutils from openstack.common.scheduler import filters @@ -117,7 +119,7 @@ class JsonFilter(filters.BaseHostFilter): for arg in query[1:]: if isinstance(arg, list): arg = self._process_filter(arg, host_state) - elif isinstance(arg, basestring): + elif isinstance(arg, six.string_types): arg = self._parse_string(arg, host_state) if arg is not None: cooked_args.append(arg) -- cgit