|
|
@ -56,6 +56,26 @@ __all__ = ['UnsafeProxy', 'AnsibleUnsafe', 'wrap_var']
|
|
|
|
class AnsibleUnsafe(object):
|
|
|
|
class AnsibleUnsafe(object):
|
|
|
|
__UNSAFE__ = True
|
|
|
|
__UNSAFE__ = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
unicode
|
|
|
|
|
|
|
|
except NameError:
|
|
|
|
|
|
|
|
# Python 3
|
|
|
|
|
|
|
|
class AnsibleUnsafeBytes(bytes, AnsibleUnsafe):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnsibleUnsafeStr(str, AnsibleUnsafe):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnsafeProxy(object):
|
|
|
|
|
|
|
|
def __new__(cls, obj, *args, **kwargs):
|
|
|
|
|
|
|
|
if obj.__class__ == str:
|
|
|
|
|
|
|
|
return AnsibleUnsafeStr(obj)
|
|
|
|
|
|
|
|
elif obj.__class__ == bytes:
|
|
|
|
|
|
|
|
return AnsibleUnsafeBytes(obj)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# Python 2
|
|
|
|
class AnsibleUnsafeStr(str, AnsibleUnsafe):
|
|
|
|
class AnsibleUnsafeStr(str, AnsibleUnsafe):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
@ -71,18 +91,21 @@ class UnsafeProxy(object):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return obj
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _wrap_dict(v):
|
|
|
|
def _wrap_dict(v):
|
|
|
|
for k in v.keys():
|
|
|
|
for k in v.keys():
|
|
|
|
if v[k] is not None:
|
|
|
|
if v[k] is not None:
|
|
|
|
v[k] = wrap_var(v[k])
|
|
|
|
v[k] = wrap_var(v[k])
|
|
|
|
return v
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _wrap_list(v):
|
|
|
|
def _wrap_list(v):
|
|
|
|
for idx, item in enumerate(v):
|
|
|
|
for idx, item in enumerate(v):
|
|
|
|
if item is not None:
|
|
|
|
if item is not None:
|
|
|
|
v[idx] = wrap_var(item)
|
|
|
|
v[idx] = wrap_var(item)
|
|
|
|
return v
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def wrap_var(v):
|
|
|
|
def wrap_var(v):
|
|
|
|
if isinstance(v, dict):
|
|
|
|
if isinstance(v, dict):
|
|
|
|
v = _wrap_dict(v)
|
|
|
|
v = _wrap_dict(v)
|
|
|
|