modifications concerning the usage of __specialmethods__ made

This commit is contained in:
Sebastian Wehling 2014-02-19 13:07:39 +01:00
parent 45999de6d2
commit 270e3b6d00

View File

@ -87,38 +87,40 @@ class AutoPickParameter(object):
return self.__parameter
def __getitem__(self, key):
return self.getParam(key)
def getParam(self, *args):
try:
for param in args:
try:
return self.__parameter[param]
except KeyError, e:
self._printParameterError(e)
except TypeError:
try:
return self.__parameter[args]
except KeyError, e:
self._printParameterError(e)
return self.__parameter[key]
def __setitem__(self, key, value):
kwargs = {}
kwargs[key] = value
kwargs['directcall'] = True
self.setParam(**kwargs)
self.__parameter[key] = value
def setParam(self, directcall=None, **kwargs):
for param, value in kwargs.iteritems():
try:
self.__parameter[param] = value
except KeyError, e:
self._printParameterError(e)
if not directcall:
print self
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.__getitem__[param]
except KeyError, e:
self._printParameterError(e)
except TypeError:
try:
return self.__getitem__[args]
except KeyError, e:
self._printParameterError(e)
def setParam(self, **kwargs):
for param, value in kwargs.iteritems():
try:
self.__setitem__[param] = value
except KeyError, e:
self._printParameterError(e)
print self
def _printParameterError(self, errmsg):
print 'ParameterError:\n non-existent parameter %s' % errmsg