Migrate basestring to a python3 compatible type (#17199)

This commit is contained in:
Toshio Kuratomi 2016-08-23 13:13:44 -07:00 committed by GitHub
commit a22909c226
28 changed files with 137 additions and 101 deletions

View file

@ -30,6 +30,7 @@ import urllib
from urllib2 import quote as urlquote, HTTPError
import ansible.constants as C
from ansible.compat.six import string_types
from ansible.errors import AnsibleError
from ansible.module_utils.urls import open_url
from ansible.galaxy.token import GalaxyToken
@ -41,22 +42,24 @@ except ImportError:
from ansible.utils.display import Display
display = Display()
def g_connect(method):
''' wrapper to lazily initialize connection info to galaxy '''
def wrapped(self, *args, **kwargs):
if not self.initialized:
display.vvvv("Initial connection to galaxy_server: %s" % self._api_server)
server_version = self._get_server_api_version()
if not server_version in self.SUPPORTED_VERSIONS:
if server_version not in self.SUPPORTED_VERSIONS:
raise AnsibleError("Unsupported Galaxy server API version: %s" % server_version)
self.baseurl = '%s/api/%s' % (self._api_server, server_version)
self.version = server_version # for future use
self.version = server_version # for future use
display.vvvv("Base API: %s" % self.baseurl)
self.initialized = True
return method(self, *args, **kwargs)
return wrapped
class GalaxyAPI(object):
''' This class is meant to be used as a API client for an Ansible Galaxy server '''
@ -77,7 +80,6 @@ class GalaxyAPI(object):
if galaxy.options.api_server != C.GALAXY_SERVER:
self._api_server = galaxy.options.api_server
def __auth_header(self):
token = self.token.get()
if token is None:
@ -112,7 +114,7 @@ class GalaxyAPI(object):
"""
url = '%s/api/' % self._api_server
try:
return_data =open_url(url, validate_certs=self._validate_certs)
return_data = open_url(url, validate_certs=self._validate_certs)
except Exception as e:
raise AnsibleError("Failed to get data from the API server (%s): %s " % (url, to_str(e)))
@ -121,7 +123,7 @@ class GalaxyAPI(object):
except Exception as e:
raise AnsibleError("Could not process data from the API server (%s): %s " % (url, to_str(e)))
if not 'current_version' in data:
if 'current_version' not in data:
raise AnsibleError("missing required 'current_version' from server response (%s)" % url)
return data['current_version']
@ -159,9 +161,9 @@ class GalaxyAPI(object):
Check the status of an import task.
"""
url = '%s/imports/' % self.baseurl
if not task_id is None:
if task_id is not None:
url = "%s?id=%d" % (url,task_id)
elif not github_user is None and not github_repo is None:
elif github_user is not None and github_repo is not None:
url = "%s?github_user=%s&github_repo=%s" % (url,github_user,github_repo)
else:
raise AnsibleError("Expected task_id or github_user and github_repo")
@ -249,11 +251,11 @@ class GalaxyAPI(object):
page_size = kwargs.get('page_size', None)
author = kwargs.get('author', None)
if tags and isinstance(tags, basestring):
if tags and isinstance(tags, string_types):
tags = tags.split(',')
search_url += '&tags_autocomplete=' + '+'.join(tags)
if platforms and isinstance(platforms, basestring):
if platforms and isinstance(platforms, string_types):
platforms = platforms.split(',')
search_url += '&platforms_autocomplete=' + '+'.join(platforms)