From 8fd7f4b121388b063940fc3aa3ffa85c2c50306c Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 2 Feb 2015 19:11:12 -0800 Subject: [PATCH] Wrap some filters so they return unicode. The rules are -- if the filter returns str type and the str may contain non-ascii characters then wrap it to convert to unicode type. Not needed if the function already returns unicode type or only returns ascii characters --- lib/ansible/runner/filter_plugins/core.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/ansible/runner/filter_plugins/core.py b/lib/ansible/runner/filter_plugins/core.py index f14364b441e..7a96179ff0c 100644 --- a/lib/ansible/runner/filter_plugins/core.py +++ b/lib/ansible/runner/filter_plugins/core.py @@ -27,6 +27,7 @@ import collections import crypt import hashlib import string +from functools import partial import operator as py_operator from random import SystemRandom, shuffle import uuid @@ -37,6 +38,7 @@ from distutils.version import LooseVersion, StrictVersion from ansible import errors from ansible.utils.hashing import md5s, checksum_s +from ansible.utils.unicode import unicode_wrap UUID_NAMESPACE_ANSIBLE = uuid.UUID('361E6D51-FAEC-444A-9079-341386DA8E2E') @@ -310,8 +312,8 @@ class FilterModule(object): def filters(self): return { # base 64 - 'b64decode': base64.b64decode, - 'b64encode': base64.b64encode, + 'b64decode': partial(unicode_wrap, base64.b64decode), + 'b64encode': partial(unicode_wrap, base64.b64encode), # uuid 'to_uuid': to_uuid, @@ -327,11 +329,11 @@ class FilterModule(object): 'from_yaml': yaml.safe_load, # path - 'basename': os.path.basename, - 'dirname': os.path.dirname, - 'expanduser': os.path.expanduser, - 'realpath': os.path.realpath, - 'relpath': os.path.relpath, + 'basename': unicode_wrap(os.path.basename), + 'dirname': unicode_wrap(os.path.dirname), + 'expanduser': unicode_wrap(os.path.expanduser), + 'realpath': unicode_wrap(os.path.realpath), + 'relpath': unicode_wrap(os.path.relpath), # failure testing 'failed' : failed,