add getowner method

This commit is contained in:
gwen 2012-07-11 15:31:59 +02:00
parent 4ec7dff6c4
commit 736a1c77b6
2 changed files with 10 additions and 6 deletions

View file

@ -104,6 +104,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
return self.callback_params return self.callback_params
def setowner(self, config, owner): def setowner(self, config, owner):
# config *must* be only the **parent** config (not the toplevel config)
# owner is a **real* owner, a list is actually allowable here # owner is a **real* owner, a list is actually allowable here
name = self._name name = self._name
if self._frozen: if self._frozen:
@ -118,6 +119,10 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
"option: {0}".format(self._name)) "option: {0}".format(self._name))
config._cfgimpl_value_owners[name] = owner config._cfgimpl_value_owners[name] = owner
def getowner(self, config):
# config *must* be only the **parent** config (not the toplevel config)
return config._cfgimpl_owner[self._name]
def setoption(self, config, value, who): def setoption(self, config, value, who):
"who is **not necessarily** a owner because it cannot be a list" "who is **not necessarily** a owner because it cannot be a list"
name = self._name name = self._name

View file

@ -37,14 +37,13 @@ def test_attribute_access():
assert config.string == "foo" assert config.string == "foo"
def test_setitem(): def test_setitem():
s = StrOption("string", "", default=["string", None, "sdfsdf"], default_multi="prout", multi=True) s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
config = Config(descr) config = Config(descr)
config._cfgimpl_values['string'].append("eggs") print config.string[1]
# config.string = ["string"].append("eggs") config.string[1] = "titi"
print config.string print config.string[1]
# config.string[1] = "titi"
def test_reset(): def test_reset():
"if value is None, resets to default owner" "if value is None, resets to default owner"
s = StrOption("string", "", default="string") s = StrOption("string", "", default="string")