* config herite from BaseInformation class
[tiramisu.git] / tiramisu / setting.py
index 533fd46..9c3c313 100644 (file)
@@ -21,6 +21,7 @@
 # the whole pypy projet is under MIT licence
 # ____________________________________________________________
 from time import time
+from copy import copy
 from tiramisu.error import RequirementRecursionError, PropertiesOptionError
 from tiramisu.i18n import _
 
@@ -152,22 +153,21 @@ class Property(object):
         self._properties = prop
 
     def append(self, propname):
-        if not propname in self._properties:
-            self._properties.append(propname)
-            self._setting._set_properties(self._properties, self._opt)
+        self._properties.add(propname)
+        self._setting._set_properties(self._properties, self._opt)
         self._setting.context.cfgimpl_reset_cache()
 
     def remove(self, propname):
         if propname in self._properties:
             self._properties.remove(propname)
             self._setting._set_properties(self._properties, self._opt)
-        self._setting.context.cfgimpl_reset_cache()
+            self._setting.context.cfgimpl_reset_cache()
 
     def __contains__(self, propname):
         return propname in self._properties
 
     def __repr__(self):
-        return str(self._properties)
+        return str(list(self._properties))
 
 
 #____________________________________________________________
@@ -178,7 +178,7 @@ class Setting(object):
     def __init__(self, context):
         # properties attribute: the name of a property enables this property
         # key is None for global properties
-        self._properties = {None: ['expire']}
+        self._properties = {None: set(('expire',))}
         # permissive properties
         self._permissives = {}
         # generic owner
@@ -192,7 +192,7 @@ class Setting(object):
         return propname in self._get_properties()
 
     def __repr__(self):
-        return str(self._get_properties())
+        return str(list(self._get_properties()))
 
     def __getitem__(self, opt):
         return Property(self, self._get_properties(opt), opt)
@@ -202,7 +202,7 @@ class Setting(object):
 
     def _get_properties(self, opt=None, is_apply_req=True):
         if opt is None:
-            props = self._properties.get(opt, [])
+            props = self._properties.get(opt, set())
         else:
             exp = None
             if opt in self._cache:
@@ -212,8 +212,7 @@ class Setting(object):
                     return props
             if is_apply_req:
                 apply_requires(opt, self.context)
-            default = list(opt._properties)
-            props = self._properties.get(opt, default)
+            props = self._properties.get(opt, opt._properties)
             self._set_cache(opt, props, exp)
         return props
 
@@ -243,24 +242,23 @@ class Setting(object):
                             value=None, force_permissive=False,
                             force_properties=None):
         #opt properties
-        properties = set(self._get_properties(opt_or_descr))
+        properties = copy(self._get_properties(opt_or_descr))
         #remove opt permissive
-        properties -= frozenset(self._get_permissive(opt_or_descr))
+        properties -= self._get_permissive(opt_or_descr)
         #remove global permissive if need
-        self_properties = self._get_properties()
+        self_properties = copy(self._get_properties())
         if force_permissive is True or 'permissive' in self_properties:
-            properties -= frozenset(self._get_permissive())
+            properties -= self._get_permissive()
 
         #global properties
-        set_properties = set(self_properties)
         if force_properties is not None:
-            set_properties.update(frozenset(force_properties))
+            self_properties.update(force_properties)
 
         #calc properties
-        properties &= set_properties
+        properties &= self_properties
         #mandatory and frozen are special properties
         if is_descr:
-            properties -= frozenset(['mandatory', 'frozen'])
+            properties -= frozenset(('mandatory', 'frozen'))
         else:
             if 'mandatory' in properties and \
                     not self.context.cfgimpl_get_values()._is_empty(opt_or_descr,
@@ -281,12 +279,12 @@ class Setting(object):
                                         list(properties))
 
     def _get_permissive(self, opt=None):
-        return self._permissives.get(opt, [])
+        return self._permissives.get(opt, frozenset())
 
     def set_permissive(self, permissive, opt=None):
         if not isinstance(permissive, tuple):
             raise TypeError(_('permissive must be a tuple'))
-        self._permissives[opt] = permissive
+        self._permissives[opt] = frozenset(permissive)
 
     #____________________________________________________________
     def setowner(self, owner):
@@ -347,7 +345,7 @@ def apply_requires(opt, config):
         setting = Property(settings, settings._get_properties(opt, False), opt)
         trigger_actions = build_actions(opt._requires)
         descr = config.cfgimpl_get_context().cfgimpl_get_description()
-        optpath = descr.optimpl_get_path_by_opt(opt)
+        optpath = descr.impl_get_path_by_opt(opt)
         for requires in trigger_actions.values():
             matches = False
             for require in requires:
@@ -356,7 +354,7 @@ def apply_requires(opt, config):
                     inverse = False
                 elif len(require) == 4:
                     option, expected, action, inverse = require
-                path = descr.optimpl_get_path_by_opt(option)
+                path = descr.impl_get_path_by_opt(option)
                 if path == optpath or path.startswith(optpath + '.'):
                     raise RequirementRecursionError(_("malformed requirements "
                                                     "imbrication detected for option: '{0}' "