From 30595e3ff7bbc9f30d57d195634a554c367df9e4 Mon Sep 17 00:00:00 2001 From: Colton Myers Date: Mon, 4 May 2015 16:39:23 -0600 Subject: [PATCH] Backport FunctionWrapper.__contains__ Otherwise `if 'config.get' in __salt__` fails becaues it tries to iterate over a list (starting with 0, 1, 2, etc) --- salt/client/ssh/wrapper/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/salt/client/ssh/wrapper/__init__.py b/salt/client/ssh/wrapper/__init__.py index 50b04f9dd2..95ff8dafde 100644 --- a/salt/client/ssh/wrapper/__init__.py +++ b/salt/client/ssh/wrapper/__init__.py @@ -40,6 +40,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] # pylint: disable=W0104 + return True + except KeyError: + return False + def __getitem__(self, cmd): ''' Return the function call to simulate the salt local lookup system