adaptation pour python2

This commit is contained in:
Benjamin Bohard 2021-12-06 10:45:52 +01:00
parent ee1dc26530
commit 1228dc1365
1 changed files with 16 additions and 1 deletions

View File

@ -68,6 +68,18 @@ import re
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
def yml_params_to_unicode(param):
def convert_param(param):
if isinstance(param, str):
return param.decode('utf-8')
if isinstance(param, list):
return [convert_param(p) for p in param]
if isinstance(param, dict):
return {convert_param(key): convert_param(value) for key,value in param.items()}
return param
return convert_param(param)
class ExpectationCollection:
def __init__(self):
self.expectations_lookup = {}
@ -160,6 +172,8 @@ class Expectation:
return False
context.reverse()
for index, c in enumerate(self.context[len(self.context)-2::-1]):
if sys.version_info < (3,):
c = c.decode('utf-8')
if c != ansi_escape.sub('', context[index]):
return False
return True
@ -289,6 +303,7 @@ def run_module():
changed=False,
module='',
msg='',
debug='',
)
# the AnsibleModule object will be our abstraction working with Ansible
@ -354,7 +369,7 @@ def run_module():
result['msg'] += "Module {} instanciated".format(result['module'])
module.exit_json(**result)
except Exception as err:
result['msg'] += err
result['msg'] += str(err)
result['changed'] = True
module.fail_json(**result)