summaryrefslogtreecommitdiff
path: root/lib/ansible/utils/unsafe_proxy.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/utils/unsafe_proxy.py')
-rw-r--r--lib/ansible/utils/unsafe_proxy.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/ansible/utils/unsafe_proxy.py b/lib/ansible/utils/unsafe_proxy.py
index 683f6e27..b3e73836 100644
--- a/lib/ansible/utils/unsafe_proxy.py
+++ b/lib/ansible/utils/unsafe_proxy.py
@@ -53,9 +53,13 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
+import sys
+import types
+import warnings
+from sys import intern as _sys_intern
from collections.abc import Mapping, Set
-from ansible.module_utils._text import to_bytes, to_text
+from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible.module_utils.common.collections import is_sequence
from ansible.utils.native_jinja import NativeJinjaText
@@ -369,3 +373,20 @@ def to_unsafe_text(*args, **kwargs):
def _is_unsafe(obj):
return getattr(obj, '__UNSAFE__', False) is True
+
+
+def _intern(string):
+ """This is a monkey patch for ``sys.intern`` that will strip
+ the unsafe wrapper prior to interning the string.
+
+ This will not exist in future versions.
+ """
+ if isinstance(string, AnsibleUnsafeText):
+ string = string._strip_unsafe()
+ return _sys_intern(string)
+
+
+if isinstance(sys.intern, types.BuiltinFunctionType):
+ sys.intern = _intern
+else:
+ warnings.warn("skipped sys.intern patch; appears to have already been patched", RuntimeWarning)