mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
16: Changed base2.WithObj.__set_obj() slightly so that its gets locked into read-only even when _obj is None
This commit is contained in:
parent
0cb26ef3ec
commit
cf32ac3370
@ -35,12 +35,18 @@ class Named(object):
|
|||||||
class WithObj(Named):
|
class WithObj(Named):
|
||||||
_obj = None
|
_obj = None
|
||||||
__obj = None
|
__obj = None
|
||||||
|
__obj_locked = False
|
||||||
|
|
||||||
def __get_obj(self):
|
def __get_obj(self):
|
||||||
return self.__obj
|
return self.__obj
|
||||||
def __set_obj(self, obj):
|
def __set_obj(self, obj):
|
||||||
if self.__obj is not None:
|
if self.__obj_locked:
|
||||||
raise exceptions.TwiceSetError(self.__class__.__name__, 'obj')
|
raise exceptions.TwiceSetError(self.__class__.__name__, '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(obj, Named)
|
||||||
assert isinstance(self._obj, str)
|
assert isinstance(self._obj, str)
|
||||||
assert obj.name == self._obj
|
assert obj.name == self._obj
|
||||||
@ -95,7 +101,8 @@ class Registrar(object):
|
|||||||
def finalize(self):
|
def finalize(self):
|
||||||
for cmd in self.__tmp_commands.values():
|
for cmd in self.__tmp_commands.values():
|
||||||
if cmd._obj is None:
|
if cmd._obj is None:
|
||||||
continue
|
cmd.obj = None
|
||||||
|
else:
|
||||||
obj = self.__tmp_objects[cmd._obj]
|
obj = self.__tmp_objects[cmd._obj]
|
||||||
cmd.obj = obj
|
cmd.obj = obj
|
||||||
self.__objects = NameSpace(self.__tmp_objects)
|
self.__objects = NameSpace(self.__tmp_objects)
|
||||||
|
@ -140,3 +140,11 @@ def test_Registar():
|
|||||||
assert cmd.obj is obj
|
assert cmd.obj is obj
|
||||||
|
|
||||||
assert r.commands.kinit.obj is None
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user