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

View file

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