summaryrefslogtreecommitdiffstats
path: root/filter_plugins
diff options
context:
space:
mode:
authorRussell Teague <rteague@redhat.com>2017-03-31 15:03:39 -0400
committerRussell Teague <rteague@redhat.com>2017-04-03 14:39:35 -0400
commit203630f47e6d06e5575a9e3bb4db76cb12ead936 (patch)
tree8434ddd592d812ac0f70141aa9c962364c2fd965 /filter_plugins
parent0bac74c346bb5c620bdf1941b40c29ff3083e2b0 (diff)
downloadopenshift-203630f47e6d06e5575a9e3bb4db76cb12ead936.tar.gz
openshift-203630f47e6d06e5575a9e3bb4db76cb12ead936.tar.bz2
openshift-203630f47e6d06e5575a9e3bb4db76cb12ead936.tar.xz
openshift-203630f47e6d06e5575a9e3bb4db76cb12ead936.zip
Support unicode output when dumping yaml
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/oo_filters.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index a619f9ccb..b11fbc407 100644
--- a/filter_plugins/oo_filters.py
+++ b/filter_plugins/oo_filters.py
@@ -21,13 +21,16 @@ import pkg_resources
import yaml
from ansible import errors
-# pylint no-name-in-module and import-error disabled here because pylint
-# fails to properly detect the packages when installed in a virtualenv
-from ansible.compat.six import string_types # pylint:disable=no-name-in-module,import-error
-from ansible.compat.six.moves.urllib.parse import urlparse # pylint:disable=no-name-in-module,import-error
-from ansible.module_utils._text import to_text
from ansible.parsing.yaml.dumper import AnsibleDumper
+# ansible.compat.six goes away with Ansible 2.4
+try:
+ from ansible.compat.six import string_types, u
+ from ansible.compat.six.moves.urllib.parse import urlparse
+except ImportError:
+ from ansible.module_utils.six import string_types, u
+ from ansible.module_utils.six.moves.urllib.parse import urlparse
+
HAS_OPENSSL = False
try:
import OpenSSL.crypto
@@ -655,11 +658,11 @@ def to_padded_yaml(data, level=0, indent=2, **kw):
return ""
try:
- transformed = yaml.dump(data, indent=indent, allow_unicode=True,
- default_flow_style=False,
- Dumper=AnsibleDumper, **kw)
+ transformed = u(yaml.dump(data, indent=indent, allow_unicode=True,
+ default_flow_style=False,
+ Dumper=AnsibleDumper, **kw))
padded = "\n".join([" " * level * indent + line for line in transformed.splitlines()])
- return to_text("\n{0}".format(padded))
+ return "\n{0}".format(padded)
except Exception as my_e:
raise errors.AnsibleFilterError('Failed to convert: %s' % my_e)