From 270e3b6d009246411825a725d4b2e0414c5c8ac5 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling Date: Wed, 19 Feb 2014 13:07:39 +0100 Subject: [PATCH] modifications concerning the usage of __specialmethods__ made --- pylot/core/readinput/types.py | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pylot/core/readinput/types.py b/pylot/core/readinput/types.py index 50e527bc..2658be46 100644 --- a/pylot/core/readinput/types.py +++ b/pylot/core/readinput/types.py @@ -87,38 +87,40 @@ class AutoPickParameter(object): return self.__parameter def __getitem__(self, key): - return self.getParam(key) + return self.__parameter[key] - def getParam(self, *args): + def __setitem__(self, key, value): + self.__parameter[key] = value + + def __delitem__(self, key): + del self.__parameter[key] + + def __iter__(self): + return iter(self.__parameter) + + def __len__(self): + return len(self.__parameter.keys()) + + def getParam(self, *args): try: for param in args: try: - return self.__parameter[param] + return self.__getitem__[param] except KeyError, e: self._printParameterError(e) except TypeError: try: - return self.__parameter[args] + return self.__getitem__[args] except KeyError, e: self._printParameterError(e) - def __setitem__(self, key, value): - kwargs = {} - kwargs[key] = value - kwargs['directcall'] = True - self.setParam(**kwargs) - - def setParam(self, directcall=None, **kwargs): + def setParam(self, **kwargs): for param, value in kwargs.iteritems(): try: - self.__parameter[param] = value + self.__setitem__[param] = value except KeyError, e: self._printParameterError(e) - if not directcall: - print self - - def __len__(self): - return len(self.__parameter.keys()) - + print self + def _printParameterError(self, errmsg): print 'ParameterError:\n non-existent parameter %s' % errmsg