diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-07-20 07:20:00 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-07-20 07:20:00 +0000 |
commit | cf32ac337062d76babb8efbf217c4045138b686a (patch) | |
tree | c14e84911cef66fe330d4a3fa2e044168d0dd814 | |
parent | 0cb26ef3ec68739a888f4295103210d301c2f9a8 (diff) | |
download | freeipa-cf32ac337062d76babb8efbf217c4045138b686a.tar.gz freeipa-cf32ac337062d76babb8efbf217c4045138b686a.tar.xz freeipa-cf32ac337062d76babb8efbf217c4045138b686a.zip |
16: Changed base2.WithObj.__set_obj() slightly so that its gets locked into read-only even when _obj is None
-rw-r--r-- | ipalib/base2.py | 25 | ||||
-rw-r--r-- | ipalib/tests/test_base2.py | 8 |
2 files changed, 24 insertions, 9 deletions
diff --git a/ipalib/base2.py b/ipalib/base2.py index fa5536bd0..98c0a1800 100644 --- a/ipalib/base2.py +++ b/ipalib/base2.py @@ -35,17 +35,23 @@ class Named(object): class WithObj(Named): _obj = None __obj = None + __obj_locked = False def __get_obj(self): return self.__obj def __set_obj(self, obj): - if self.__obj is not None: + if self.__obj_locked: raise exceptions.TwiceSetError(self.__class__.__name__, 'obj') - assert isinstance(obj, Named) - assert isinstance(self._obj, str) - assert obj.name == self._obj - self.__obj = obj - assert self.obj is obj + self.__obj_locked = True + if obj is None: + assert self.__obj is None + assert self.obj is None + else: + assert isinstance(obj, Named) + assert isinstance(self._obj, str) + assert obj.name == self._obj + self.__obj = obj + assert self.obj is obj obj = property(__get_obj, __set_obj) @@ -95,8 +101,9 @@ class Registrar(object): def finalize(self): for cmd in self.__tmp_commands.values(): if cmd._obj is None: - continue - obj = self.__tmp_objects[cmd._obj] - cmd.obj = obj + cmd.obj = None + else: + obj = self.__tmp_objects[cmd._obj] + cmd.obj = obj self.__objects = NameSpace(self.__tmp_objects) self.__commands = NameSpace(self.__tmp_commands) diff --git a/ipalib/tests/test_base2.py b/ipalib/tests/test_base2.py index cdf96bdb3..398f6c634 100644 --- a/ipalib/tests/test_base2.py +++ b/ipalib/tests/test_base2.py @@ -140,3 +140,11 @@ def test_Registar(): assert cmd.obj is obj assert r.commands.kinit.obj is None + + for cmd in r.commands(): + raised = False + try: + cmd.obj = None + except exceptions.TwiceSetError: + raised = True + assert raised |