summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-02-02 19:11:12 -0800
committerJames Cammarata <jimi@sngx.net>2015-02-17 14:19:59 -0600
commitb30cb192e86aa590f7d7c89d85460555b91ebe8f (patch)
treeabe9be8ffa77bcfbb4ef5f3975981f0658ee5002
parenta1a69d6dc5c08ac4167d387722c6dddd4b5af919 (diff)
downloadansible-b30cb192e86aa590f7d7c89d85460555b91ebe8f.tar.gz
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 Conflicts: lib/ansible/runner/filter_plugins/core.py
-rw-r--r--lib/ansible/runner/filter_plugins/core.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/ansible/runner/filter_plugins/core.py b/lib/ansible/runner/filter_plugins/core.py
index 966d3876d8..14c5fddfdd 100644
--- a/lib/ansible/runner/filter_plugins/core.py
+++ b/lib/ansible/runner/filter_plugins/core.py
@@ -24,12 +24,16 @@ import pipes
import glob
import re
import collections
+from functools import partial
import operator as py_operator
-from ansible import errors
-from ansible.utils import md5s, checksum_s
from distutils.version import LooseVersion, StrictVersion
from random import SystemRandom, shuffle
from jinja2.filters import environmentfilter
+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
def to_nice_yaml(*a, **kw):
@@ -249,8 +253,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),
# json
'to_json': to_json,
@@ -263,11 +267,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,