浏览代码

Use ansible.module_utils._text.to_text instead of ansible.utils.unicode.to_unicode.

Andrew Butcher 8 年之前
父节点
当前提交
70dd1bb1e9
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10 2
      filter_plugins/oo_filters.py

+ 10 - 2
filter_plugins/oo_filters.py

@@ -17,9 +17,17 @@ import re
 import json
 import yaml
 from ansible.parsing.yaml.dumper import AnsibleDumper
-from ansible.utils.unicode import to_unicode
 from urlparse import urlparse
 
+try:
+    # ansible-2.2
+    # ansible.utils.unicode.to_unicode is deprecated in ansible-2.2,
+    # ansible.module_utils._text.to_text should be used instead.
+    from ansible.module_utils._text import to_text
+except ImportError:
+    # ansible-2.1
+    from ansible.utils.unicode import to_unicode as to_text
+
 # Disabling too-many-public-methods, since filter methods are necessarily
 # public
 # pylint: disable=too-many-public-methods
@@ -626,7 +634,7 @@ class FilterModule(object):
                                     default_flow_style=False,
                                     Dumper=AnsibleDumper, **kw)
             padded = "\n".join([" " * level * indent + line for line in transformed.splitlines()])
-            return to_unicode("\n{0}".format(padded))
+            return to_text("\n{0}".format(padded))
         except Exception as my_e:
             raise errors.AnsibleFilterError('Failed to convert: %s' % my_e)