adaptation pour python2
This commit is contained in:
parent
ee1dc26530
commit
1228dc1365
|
@ -68,6 +68,18 @@ import re
|
||||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
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:
|
class ExpectationCollection:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.expectations_lookup = {}
|
self.expectations_lookup = {}
|
||||||
|
@ -160,6 +172,8 @@ class Expectation:
|
||||||
return False
|
return False
|
||||||
context.reverse()
|
context.reverse()
|
||||||
for index, c in enumerate(self.context[len(self.context)-2::-1]):
|
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]):
|
if c != ansi_escape.sub('', context[index]):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -289,6 +303,7 @@ def run_module():
|
||||||
changed=False,
|
changed=False,
|
||||||
module='',
|
module='',
|
||||||
msg='',
|
msg='',
|
||||||
|
debug='',
|
||||||
)
|
)
|
||||||
|
|
||||||
# the AnsibleModule object will be our abstraction working with Ansible
|
# the AnsibleModule object will be our abstraction working with Ansible
|
||||||
|
@ -354,7 +369,7 @@ def run_module():
|
||||||
result['msg'] += "Module {} instanciated".format(result['module'])
|
result['msg'] += "Module {} instanciated".format(result['module'])
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
result['msg'] += err
|
result['msg'] += str(err)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
module.fail_json(**result)
|
module.fail_json(**result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue