Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3: use six.text_type instead of unicode #12244

Merged
merged 2 commits into from
Sep 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions contrib/inventory/apache-libcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from time import time
import ConfigParser

from six import iteritems
from six import iteritems, string_types
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
import libcloud.security as sec
Expand Down Expand Up @@ -260,11 +260,11 @@ def get_host_info(self):
key = self.to_safe('ec2_' + key)

# Handle complex types
if type(value) in [int, bool]:
if isinstance(value, (int, bool)):
instance_vars[key] = value
elif type(value) in [str, unicode]:
elif isinstance(value, string_types):
instance_vars[key] = value.strip()
elif type(value) == type(None):
elif value is None:
instance_vars[key] = ''
elif key == 'ec2_region':
instance_vars[key] = value.name
Expand Down
4 changes: 3 additions & 1 deletion contrib/inventory/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import time
import ConfigParser

from six import text_type

# Disable logging message trigged by pSphere/suds.
try:
from logging import NullHandler
Expand Down Expand Up @@ -149,7 +151,7 @@ def _get_obj_info(self, obj, depth=99, seen=None):
seen = seen or set()
if isinstance(obj, ManagedObject):
try:
obj_unicode = unicode(getattr(obj, 'name'))
obj_unicode = text_type(getattr(obj, 'name'))
except AttributeError:
obj_unicode = ()
if obj in seen:
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/executor/process/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
__metaclass__ = type

from six.moves import queue
from six import iteritems
from six import iteritems, text_type

import multiprocessing
import os
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, final_q, workers):
super(ResultProcess, self).__init__()

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)
debug("done sending result")

Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os

from yaml import load, YAMLError
from six import text_type

from ansible.errors import AnsibleParserError
from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR
Expand Down Expand Up @@ -80,7 +81,7 @@ def load(self, data, file_name='<string>', show_content=True):
# they are unable to cope with our subclass.
# Unwrap and re-wrap the unicode so we can keep track of line
# numbers
new_data = unicode(data)
new_data = text_type(data)
else:
new_data = data
try:
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/playbook/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from inspect import getmembers
from io import FileIO

from six import iteritems, string_types
from six import iteritems, string_types, text_type

from jinja2.exceptions import UndefinedError

Expand Down Expand Up @@ -291,7 +291,7 @@ def post_validate(self, templar):
# and make sure the attribute is of the type it should be
if value is not None:
if attribute.isa == 'string':
value = unicode(value)
value = text_type(value)
elif attribute.isa == 'int':
value = int(value)
elif attribute.isa == 'float':
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/playbook/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
__metaclass__ = type

from jinja2.exceptions import UndefinedError
from six import text_type

from ansible.errors import *
from ansible.playbook.attribute import FieldAttribute
Expand Down Expand Up @@ -82,7 +83,7 @@ def _check_conditional(self, conditional, templar, all_vars):
if conditional is None or conditional == '':
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]

# make sure the templar is using the variables specifed to this method
Expand Down
4 changes: 3 additions & 1 deletion lib/ansible/plugins/shell/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import time
import random

from six import text_type

_USER_HOME_PATH_RE = re.compile(r'^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$')

class ShellModule(object):
Expand All @@ -40,7 +42,7 @@ def env_prefix(self, **kwargs):
LC_MESSAGES = C.DEFAULT_MODULE_LANG,
)
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):
return os.path.join(*args)
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/strategies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
__metaclass__ = type

from six.moves import queue as Queue
from six import iteritems
from six import iteritems, text_type

import time

Expand Down Expand Up @@ -168,7 +168,7 @@ def _process_pending_results(self, iterator):
while not self._final_q.empty() and not self._tqm._terminated:
try:
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)
if result[0] in ('host_task_ok', 'host_task_failed', 'host_task_skipped', 'host_unreachable'):
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/strategies/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from six import iteritems
from six import iteritems, text_type

from ansible.errors import AnsibleError
from ansible.executor.play_iterator import PlayIterator
Expand Down Expand Up @@ -221,7 +221,7 @@ def run(self, iterator, play_context):
saved_name = task.name
display.debug("done copying, going to template now")
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")
except:
# just ignore any errors during task name templating,
Expand Down