1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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)
if params:
for k,v in iteritems(params):
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
def partition(self):
@ -295,15 +310,6 @@ class AnsibleF5Parameters(object):
return 'Common'
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
def partition(self, 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)
class F5ModuleError(Exception):
pass