I think for now I'll just not use dunder setter (#22336)

This commit is contained in:
Tim Rupp 2017-03-07 01:36:13 -08:00 committed by John R Barker
parent 5357a67607
commit c2180888f7

View file

@ -287,7 +287,22 @@ class AnsibleF5Parameters(object):
self._values = defaultdict(lambda: None) self._values = defaultdict(lambda: None)
if params: if params:
for k,v in iteritems(params): for k,v in iteritems(params):
setattr(self, k, v) try:
# Handle weird API parameters like `dns.proxy.__iter__` by
# using a map provided by the module developer
setattr(self, self.api_params[k], v)
except (KeyError, TypeError):
# Otherwise set things to attributes as normal
setattr(self, k, v)
except AttributeError:
# If all else fails, stash them in a dictionary. For
# instance, if the module developer forgot a map.
self._values[k] = v
def __getattr__(self, item):
# Ensures that properties that weren't defined, and therefore stashed
# in the `_values` dict, will be retrievable.
return self._values[item]
@property @property
def partition(self): def partition(self):
@ -295,15 +310,6 @@ class AnsibleF5Parameters(object):
return 'Common' return 'Common'
return self._values['partition'].strip('/') return self._values['partition'].strip('/')
def __getattr__(self, item):
return self._values[item]
def __setattr__(self, key, value):
if key == '_values':
self.__dict__['_values'] = value
else:
super(AnsibleF5Parameters, self).__setattr__(key, value)
@partition.setter @partition.setter
def partition(self, value): def partition(self, value):
self._values['partition'] = value self._values['partition'] = value
@ -312,6 +318,5 @@ class AnsibleF5Parameters(object):
return dict((k, v) for k, v in iteritems(params) if v is not None) return dict((k, v) for k, v in iteritems(params) if v is not None)
class F5ModuleError(Exception): class F5ModuleError(Exception):
pass pass