Merge pull request #12244 from mgedmin/py3k

Python 3: use six.text_type instead of unicode
pull/12243/merge
Toshio Kuratomi 9 years ago
commit a6de4b86a8

@ -37,7 +37,7 @@ import re
from time import time from time import time
import ConfigParser import ConfigParser
from six import iteritems from six import iteritems, string_types
from libcloud.compute.types import Provider from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver from libcloud.compute.providers import get_driver
import libcloud.security as sec import libcloud.security as sec
@ -260,11 +260,11 @@ class LibcloudInventory(object):
key = self.to_safe('ec2_' + key) key = self.to_safe('ec2_' + key)
# Handle complex types # Handle complex types
if type(value) in [int, bool]: if isinstance(value, (int, bool)):
instance_vars[key] = value instance_vars[key] = value
elif type(value) in [str, unicode]: elif isinstance(value, string_types):
instance_vars[key] = value.strip() instance_vars[key] = value.strip()
elif type(value) == type(None): elif value is None:
instance_vars[key] = '' instance_vars[key] = ''
elif key == 'ec2_region': elif key == 'ec2_region':
instance_vars[key] = value.name instance_vars[key] = value.name

@ -39,6 +39,8 @@ import sys
import time import time
import ConfigParser import ConfigParser
from six import text_type
# Disable logging message trigged by pSphere/suds. # Disable logging message trigged by pSphere/suds.
try: try:
from logging import NullHandler from logging import NullHandler
@ -149,7 +151,7 @@ class VMwareInventory(object):
seen = seen or set() seen = seen or set()
if isinstance(obj, ManagedObject): if isinstance(obj, ManagedObject):
try: try:
obj_unicode = unicode(getattr(obj, 'name')) obj_unicode = text_type(getattr(obj, 'name'))
except AttributeError: except AttributeError:
obj_unicode = () obj_unicode = ()
if obj in seen: if obj in seen:

@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
from six.moves import queue from six.moves import queue
from six import iteritems from six import iteritems, text_type
import multiprocessing import multiprocessing
import os import os
@ -62,7 +62,7 @@ class ResultProcess(multiprocessing.Process):
super(ResultProcess, self).__init__() super(ResultProcess, self).__init__()
def _send_result(self, result): def _send_result(self, result):
debug(u"sending result: %s" % ([unicode(x) for x in result],)) debug(u"sending result: %s" % ([text_type(x) for x in result],))
self._final_q.put(result, block=False) self._final_q.put(result, block=False)
debug("done sending result") debug("done sending result")

@ -24,6 +24,7 @@ import json
import os import os
from yaml import load, YAMLError from yaml import load, YAMLError
from six import text_type
from ansible.errors import AnsibleParserError from ansible.errors import AnsibleParserError
from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR
@ -80,7 +81,7 @@ class DataLoader():
# they are unable to cope with our subclass. # they are unable to cope with our subclass.
# Unwrap and re-wrap the unicode so we can keep track of line # Unwrap and re-wrap the unicode so we can keep track of line
# numbers # numbers
new_data = unicode(data) new_data = text_type(data)
else: else:
new_data = data new_data = data
try: try:

@ -27,7 +27,7 @@ from functools import partial
from inspect import getmembers from inspect import getmembers
from io import FileIO from io import FileIO
from six import iteritems, string_types from six import iteritems, string_types, text_type
from jinja2.exceptions import UndefinedError from jinja2.exceptions import UndefinedError
@ -291,7 +291,7 @@ class Base:
# and make sure the attribute is of the type it should be # and make sure the attribute is of the type it should be
if value is not None: if value is not None:
if attribute.isa == 'string': if attribute.isa == 'string':
value = unicode(value) value = text_type(value)
elif attribute.isa == 'int': elif attribute.isa == 'int':
value = int(value) value = int(value)
elif attribute.isa == 'float': elif attribute.isa == 'float':

@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
from jinja2.exceptions import UndefinedError from jinja2.exceptions import UndefinedError
from six import text_type
from ansible.errors import * from ansible.errors import *
from ansible.playbook.attribute import FieldAttribute from ansible.playbook.attribute import FieldAttribute
@ -82,7 +83,7 @@ class Conditional:
if conditional is None or conditional == '': if conditional is None or conditional == '':
return True return True
if conditional in all_vars and '-' not in unicode(all_vars[conditional]): if conditional in all_vars and '-' not in text_type(all_vars[conditional]):
conditional = all_vars[conditional] conditional = all_vars[conditional]
# make sure the templar is using the variables specifed to this method # make sure the templar is using the variables specifed to this method

@ -24,6 +24,8 @@ import ansible.constants as C
import time import time
import random import random
from six import text_type
_USER_HOME_PATH_RE = re.compile(r'^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$') _USER_HOME_PATH_RE = re.compile(r'^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$')
class ShellModule(object): class ShellModule(object):
@ -40,7 +42,7 @@ class ShellModule(object):
LC_MESSAGES = C.DEFAULT_MODULE_LANG, LC_MESSAGES = C.DEFAULT_MODULE_LANG,
) )
env.update(kwargs) env.update(kwargs)
return ' '.join(['%s=%s' % (k, pipes.quote(unicode(v))) for k,v in env.items()]) return ' '.join(['%s=%s' % (k, pipes.quote(text_type(v))) for k,v in env.items()])
def join_path(self, *args): def join_path(self, *args):
return os.path.join(*args) return os.path.join(*args)

@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
from six.moves import queue as Queue from six.moves import queue as Queue
from six import iteritems from six import iteritems, text_type
import time import time
@ -168,7 +168,7 @@ class StrategyBase:
while not self._final_q.empty() and not self._tqm._terminated: while not self._final_q.empty() and not self._tqm._terminated:
try: try:
result = self._final_q.get(block=False) result = self._final_q.get(block=False)
self._display.debug("got result from result worker: %s" % ([unicode(x) for x in result],)) self._display.debug("got result from result worker: %s" % ([text_type(x) for x in result],))
# all host status messages contain 2 entries: (msg, task_result) # all host status messages contain 2 entries: (msg, task_result)
if result[0] in ('host_task_ok', 'host_task_failed', 'host_task_skipped', 'host_unreachable'): if result[0] in ('host_task_ok', 'host_task_failed', 'host_task_skipped', 'host_unreachable'):

@ -19,7 +19,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
from six import iteritems from six import iteritems, text_type
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.executor.play_iterator import PlayIterator from ansible.executor.play_iterator import PlayIterator
@ -221,7 +221,7 @@ class StrategyModule(StrategyBase):
saved_name = task.name saved_name = task.name
display.debug("done copying, going to template now") display.debug("done copying, going to template now")
try: try:
task.name = unicode(templar.template(task.name, fail_on_undefined=False)) task.name = text_type(templar.template(task.name, fail_on_undefined=False))
display.debug("done templating") display.debug("done templating")
except: except:
# just ignore any errors during task name templating, # just ignore any errors during task name templating,

Loading…
Cancel
Save