value owners can be lists
authorgwen <gremond@cadoles.com>
Mon, 9 Jul 2012 15:34:39 +0000 (17:34 +0200)
committergwen <gremond@cadoles.com>
Mon, 9 Jul 2012 15:34:39 +0000 (17:34 +0200)
config.py
option.py
test/test_option_setting.py

index c591707..6688218 100644 (file)
--- a/config.py
+++ b/config.py
@@ -104,7 +104,6 @@ class Config(object):
             if homeconfig._cfgimpl_value_owners[name] in special_owners:
                 raise SpecialOwnersError("cannot override option: {0} because "
                                             "of its special owner".format(name))
-            # FIXME and ['default'] if is_multi
             homeconfig.setoption(name, value, 'default')
 
     def cfgimpl_set_owner(self, owner):
@@ -152,18 +151,9 @@ class Config(object):
         if self._cfgimpl_frozen and getattr(self, name) != value:
             raise TypeError("trying to change a value in a frozen config"
                                                 ": {0} {1}".format(name, value))
-        opt = getattr(self._cfgimpl_descr, name)
-        if type(opt) != SymLinkOption:
+        if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
             self._validate(name, getattr(self._cfgimpl_descr, name))
-            if not opt.is_multi():
-                self.setoption(name, value, self._cfgimpl_owner)
-            else:
-                if type(value) != list:
-                    raise ConfigError("invalid value for multi "
-                        "with option: {0}".format(name))
-                self.setoption(name, value, [self._cfgimpl_owner for i in range(len(value))])
-        else:
-            self.setoption(name, value, self._cfgimpl_owner)
+        self.setoption(name, value, self._cfgimpl_owner)
             
     def _validate(self, name, opt_or_descr):
         if not type(opt_or_descr) == OptionDescription:
@@ -294,12 +284,22 @@ class Config(object):
         self._cfgimpl_values[name] = getattr(opt, 'default', None)
 
     def setoption(self, name, value, who=None):
+        "who is **not necessarily** a owner, because it cannot be a list"
         child = getattr(self._cfgimpl_descr, name)
         if who == None:
             if child.is_multi():
-                who = [self._cfgimpl_owner for i in range(len(value))] 
+                newowner = [self._cfgimpl_owner for i in range(len(value))] 
             else:
-                who == self._cfgimpl_owner
+                newowner = self._cfgimpl_owner
+        else:
+            if type(child) != SymLinkOption:
+                if child.is_multi():
+                    if type(value) != list:
+                        raise ConfigError("invalid value for option:"
+                                       " {0} that is set to multi".format(name))
+                    newowner = [who for i in range(len(value))]
+                else:
+                    newowner = who 
         if type(child) != SymLinkOption:
             if name not in self._cfgimpl_values:
                 raise AttributeError('unknown option %s' % (name,))
@@ -318,7 +318,7 @@ class Config(object):
             if who == 'auto':
                 if not child._is_hidden():
                     child.hide()
-            self._cfgimpl_value_owners[name] = who
+            self._cfgimpl_value_owners[name] = newowner
         else:
             homeconfig = self._cfgimpl_get_toplevel()
             child.setoption(homeconfig, value, who)
index f79f0ee..b144b63 100644 (file)
--- a/option.py
+++ b/option.py
@@ -95,35 +95,39 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
     def getcallback_params(self):
         return self.callback_params
 
-    def setowner(self, config, who):
+    def setowner(self, config, owner):
+        # owner is a **real* owner, a list is actually allowable here
         name = self._name
         if self._frozen:
             raise TypeError("trying to change a frozen option's owner: %s" % name)
-        if who in special_owners:
+        if owner in special_owners:
             if self.callback == None:
                 raise SpecialOwnersError("no callback specified for" 
                                                       "option {0}".format(name))
         if self.is_multi():
-            if not type(who) == list:
+            if not type(owner) == list:
                 raise ConfigError("invalid owner for multi "
                     "option: {0}".format(self._name))
-        config._cfgimpl_value_owners[name] = who
+        config._cfgimpl_value_owners[name] = owner
 
     def setoption(self, config, value, who):
+        "who is **not necessarily** a owner because it cannot be a list"
         name = self._name
         if self._frozen:
             raise TypeError('trying to change a frozen option object: %s' % name)
         # we want the possibility to reset everything
-        if (not self.multi and who == "default" or self.multi and "default" in who)\
-            and value is None:
+#        if (not self.multi and who == "default" or self.multi and "default" in who)\
+#            and value is None:
+        if who == "default" and value is None:
             self.default = None
             return
 
         if not self.validate(value):
             raise ConfigError('invalid value %s for option %s' % (value, name))
 
-        if (self.multi and "default" in who) or \
-           (not self.multi and who == "default"):
+#        if (self.multi and "default" in who) or \
+#           (not self.multi and who == "default"):
+        if who == "default":
             # changes the default value (and therefore resets the previous value)
             if self._validate(value):
                 self.default = value
index 4b5278c..d05edb2 100644 (file)
@@ -68,6 +68,8 @@ def test_access_with_multi_default():
     config.string = ["foo", "bar"]
     assert config.string == ["foo", "bar"]
     assert config._cfgimpl_value_owners["string"] == ['user', 'user']
+    print config._cfgimpl_value_owners["string"]
+    # FIXME gwen haha 
 #    assert config.string[
 
 #def test_attribute_access_with_multi2():