list is Multi now which enables us to implement item access

This commit is contained in:
gwen 2012-07-13 09:35:46 +02:00
parent 05f5b0ccbc
commit a5be1b5591
2 changed files with 14 additions and 11 deletions

View File

@ -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

View File

@ -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"