From a5be1b5591170a2a8e44e4945e4bfcbf07b4b35d Mon Sep 17 00:00:00 2001 From: gwen Date: Fri, 13 Jul 2012 09:35:46 +0200 Subject: [PATCH] list is Multi now which enables us to implement item access --- config.py | 6 ++++-- option.py | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index dfec6e7..f4fabdd 100644 --- a/config.py +++ b/config.py @@ -25,9 +25,11 @@ from error import (HiddenOptionError, ConfigError, NotFoundError, SpecialOwnersError, MandatoryError, MethodCallError, DisabledOptionError, ModeOptionError) from option import (OptionDescription, Option, SymLinkOption, group_types, - default_owner ,Multi, apply_requires, modes) -import autolib + Multi, apply_requires, modes) from autolib import special_owners, special_owner_factory +# ______________________________________________________________________ +# generic owner. 'default' is the general config owner after init time +default_owner = 'user' # ____________________________________________________________ class Config(object): _cfgimpl_hidden = True diff --git a/option.py b/option.py index d32101d..9339e12 100644 --- a/option.py +++ b/option.py @@ -28,8 +28,6 @@ available_actions = ['hide', 'show', 'enable', 'disable'] reverse_actions = {'hide': 'show', 'show': 'hide', 'disable':'enable', 'enable': 'disable'} # ____________________________________________________________ -# generic owner. 'default' is the general config owner after init time -default_owner = 'user' # OptionDescription authorized group_type values group_types = ['default', 'family', 'group', 'master'] # multi types @@ -49,25 +47,28 @@ class Multi(list): if value is None: owner = 'default' else: - owner = default_owner - self.child.setowner(self.config, owner) + owner = self.config._cfgimpl_owner + oldowner = self.child.getowner(self.config) + oldowner[key] = owner + self.child.setowner(self.config, oldowner) if value != None and not self.child._validate(value): raise ConfigError("invalid value {0} " "for option {1}".format(str(value), self.child._name)) - # FIXME : and if value is None ??? return super(Multi, self).__setitem__(key, value) def append(self, value): if value is None: owner = 'default' else: - owner = default_owner - self.child.setowner(self.config, owner) + owner = self.config._cfgimpl_owner + oldowner = self.child.getowner(self.config) + oldowner.append(owner) + self.child.setowner(self.config, oldowner) # changer dans la config la valeur par défaut et le owner if value != None and not self.child._validate(value): raise ConfigError("invalid value {0} " "for option {1}".format(str(value), self.child._name)) - self.config._cfgimpl_values[child._name].append(value) + super(Multi, self).append(value) # def pop(self): # pass @@ -163,7 +164,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType): def getowner(self, config): # config *must* be only the **parent** config (not the toplevel config) - return config._cfgimpl_owner[self._name] + return config._cfgimpl_value_owners[self._name] def setoption(self, config, value, who): "who is **not necessarily** a owner because it cannot be a list"