option's name shall not have an api's method name

This commit is contained in:
gwen
2013-02-25 11:33:20 +01:00
parent 8f4efe6b00
commit 7b4f3b5d36
4 changed files with 75 additions and 10 deletions

View File

@ -21,6 +21,7 @@
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from copy import copy
from inspect import getmembers, ismethod
from tiramisu.error import (PropertiesOptionError, ConfigError, NotFoundError,
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
MandatoryError, MethodCallError, NoValueReturned)
@ -65,6 +66,10 @@ class Config(object):
"warnings are a great idea, let's make up a better use of it"
self._cfgimpl_warnings = []
self._cfgimpl_toplevel = self._cfgimpl_get_toplevel()
# some api members shall not be used as option's names !
methods = getmembers(self, ismethod)
self._cfgimpl_slots = [key for key, value in methods \
if not key.startswith("_")]
self._cfgimpl_build()
def cfgimpl_get_settings(self):
@ -96,17 +101,22 @@ class Config(object):
if self._cfgimpl_descr.group_type == groups.master:
mastername = self._cfgimpl_descr._name
masteropt = getattr(self._cfgimpl_descr, mastername)
self._cfgimpl_values.masters[masteropt] = []
self._cfgimpl_context._cfgimpl_values.masters[masteropt] = []
for child in self._cfgimpl_descr._children:
if isinstance(child, OptionDescription):
self._validate_duplicates(child._children)
self._cfgimpl_subconfigs[child] = Config(child, parent=self,
context=self._cfgimpl_context)
else:
if child._name in self._cfgimpl_slots:
raise NameError("invalid name for the option:"
" {0}".format(child._name))
if (self._cfgimpl_descr.group_type == groups.master and
child != masteropt):
self._cfgimpl_values.slaves[child] = masteropt
self._cfgimpl_values.masters[masteropt].append(child)
self._cfgimpl_context._cfgimpl_values.slaves[child] = masteropt
self._cfgimpl_context._cfgimpl_values.masters[masteropt].append(child)
# ____________________________________________________________
# attribute methods
@ -120,6 +130,9 @@ class Config(object):
return setattr(homeconfig, name, value)
if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
self._validate(name, getattr(self._cfgimpl_descr, name))
if name in self._cfgimpl_slots:
raise NameError("invalid name for the option:"
" {0}".format(name))
self.setoption(name, value)
def _validate(self, name, opt_or_descr, permissive=False):

View File

@ -20,7 +20,7 @@
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from tiramisu.error import NoValueReturned, MandatoryError
from tiramisu.error import NoValueReturned, MandatoryError, MultiTypeError
from tiramisu.setting import owners, multitypes
class Values(object):
@ -138,16 +138,16 @@ class Values(object):
def __setitem__(self, opt, value):
if opt in self.masters:
masterlen = len(value)
for slave in masters[opt]:
for slave in self.masters[opt]:
if len(self._get_value(slave)) != masterlen:
raise MultiTypeError("invalid len for the slave: {0}"
"which has {1} as master".format(slave._name,
master._name))
" which has {1} as master".format(slave._name,
opt._name))
elif opt in self.slaves:
if len(self._get_value(self.slaves[opt])) != len(value):
raise MultiTypeError("invalid len for the slave: {0}"
"which has {1} as master".format(slave._name,
master._name))
" which has {1} as master".format(opt._name,
self.slaves[opt]._name))
self.setitem(opt, value)
def setitem(self, opt, value):