add permissive in config

This commit is contained in:
Garette Emmanuel 2013-03-14 11:31:44 +01:00
parent 783e982c9b
commit 15beeda0f0
2 changed files with 18 additions and 7 deletions

View file

@ -50,6 +50,7 @@ class Config(object):
# sub option descriptions # sub option descriptions
self._cfgimpl_subconfigs = {} self._cfgimpl_subconfigs = {}
self._cfgimpl_parent = parent self._cfgimpl_parent = parent
self._cfgimpl_permissive = []
if context is None: if context is None:
self._cfgimpl_context = self self._cfgimpl_context = self
else: else:
@ -168,14 +169,12 @@ class Config(object):
if not isinstance(opt_or_descr, Option) and \ if not isinstance(opt_or_descr, Option) and \
not isinstance(opt_or_descr, OptionDescription): not isinstance(opt_or_descr, OptionDescription):
raise TypeError('Unexpected object: {0}'.format(repr(opt_or_descr))) raise TypeError('Unexpected object: {0}'.format(repr(opt_or_descr)))
properties = copy(opt_or_descr.properties) properties = set(copy(opt_or_descr.properties))
for proper in copy(properties): properties = properties & set(self._cfgimpl_context._cfgimpl_settings.get_properties())
if not self._cfgimpl_context._cfgimpl_settings.has_property(proper):
properties.remove(proper)
if permissive: if permissive:
for perm in self._cfgimpl_context._cfgimpl_settings.permissive: properties = properties - set(self._cfgimpl_context._cfgimpl_settings.get_permissive())
if perm in properties: properties = properties - set(self._cfgimpl_permissive)
properties.remove(perm) properties = list(properties)
if properties != []: if properties != []:
raise PropertiesOptionError("trying to access" raise PropertiesOptionError("trying to access"
" to an option named: {0} with properties" " to an option named: {0} with properties"
@ -415,6 +414,11 @@ class Config(object):
except: except:
pass pass
# ______________________________________________________________________ # ______________________________________________________________________
def cfgimpl_set_permissive(self, permissive):
if not isinstance(permissive, list):
raise TypeError('permissive must be a list')
self._cfgimpl_permissive = permissive
# ______________________________________________________________________
def __str__(self): def __str__(self):
"Config's string representation" "Config's string representation"
lines = [] lines = []

View file

@ -137,6 +137,10 @@ class Setting():
"has properties means the Config's properties attribute is not empty" "has properties means the Config's properties attribute is not empty"
return bool(len(self.properties)) return bool(len(self.properties))
def get_properties(self):
return self.properties
def has_property(self, propname): def has_property(self, propname):
"""has property propname in the Config's properties attribute """has property propname in the Config's properties attribute
:param property: string wich is the name of the property""" :param property: string wich is the name of the property"""
@ -152,6 +156,9 @@ class Setting():
if self.has_property(propname): if self.has_property(propname):
self.properties.remove(propname) self.properties.remove(propname)
#____________________________________________________________ #____________________________________________________________
def get_permissive(self):
return self.permissive
def set_permissive(self, permissive): def set_permissive(self, permissive):
if not isinstance(permissive, list): if not isinstance(permissive, list):
raise TypeError('permissive must be a list') raise TypeError('permissive must be a list')