From dcf4550f4ea437873e4ecd21fbada1204de9cb46 Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Wed, 4 Feb 2015 16:14:26 -0800 Subject: [PATCH] Cleanup FunctionWrapper --- salt/client/ssh/wrapper/__init__.py | 12 ++++++++++++ salt/renderers/yaml.py | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/salt/client/ssh/wrapper/__init__.py b/salt/client/ssh/wrapper/__init__.py index 0e22fe0177..0d36e3506d 100644 --- a/salt/client/ssh/wrapper/__init__.py +++ b/salt/client/ssh/wrapper/__init__.py @@ -45,6 +45,18 @@ class FunctionWrapper(object): self.fsclient = fsclient self.kwargs.update(kwargs) + def __contains__(self, key): + ''' + We need to implement a __contains__ method, othwerwise when someone + does a contains comparison python assumes this is a sequence, and does + __getitem__ keys 0 and up until IndexError + ''' + try: + self[key] + return True + except KeyError: + return False + def __getitem__(self, cmd): ''' Return the function call to simulate the salt local lookup system diff --git a/salt/renderers/yaml.py b/salt/renderers/yaml.py index c278f5c5c9..da20451b46 100644 --- a/salt/renderers/yaml.py +++ b/salt/renderers/yaml.py @@ -64,12 +64,11 @@ def render(yaml_data, saltenv='base', sls='', argline='', **kws): if not data: data = {} else: - try: + if 'config.get' in __salt__: if __salt__['config.get']('yaml_utf8', False): data = _yaml_result_unicode_to_utf8(data) - except KeyError: - if __opts__.get('yaml_utf8'): - data = _yaml_result_unicode_to_utf8(data) + elif __opts__.get('yaml_utf8'): + data = _yaml_result_unicode_to_utf8(data) log.debug('Results of YAML rendering: \n{0}'.format(data)) return data