Merge branch 'master' into metaconfig
[tiramisu.git] / tiramisu / config.py
index d024159..2c1a6b1 100644 (file)
@@ -156,7 +156,15 @@ class SubConfig(object):
     __repr__ = __str__
 
     def _cfgimpl_get_context(self):
-        return self._impl_context()
+        """context could be None, we need to test it
+        context is None only if all reference to `Config` object is deleted
+        (for example we delete a `Config` and we manipulate a reference to
+        old `SubConfig`, `Values`, `Multi` or `Settings`)
+        """
+        context = self._impl_context()
+        if context is None:
+            raise ConfigError(_('the context does not exist anymore'))
+        return context
 
     def cfgimpl_get_description(self):
         if self._impl_descr is None:
@@ -250,7 +258,8 @@ class SubConfig(object):
                 force_properties=force_properties,
                 force_permissive=force_permissive)
 
-    def find(self, bytype=None, byname=None, byvalue=None, type_='option'):
+    def find(self, bytype=None, byname=None, byvalue=None, type_='option',
+             check_properties=True):
         """
             finds a list of options recursively in the config
 
@@ -262,11 +271,11 @@ class SubConfig(object):
         return self._cfgimpl_get_context()._find(bytype, byname, byvalue,
                                                  first=False,
                                                  type_=type_,
-                                                 _subpath=self.cfgimpl_get_path()
-                                                 )
+                                                 _subpath=self.cfgimpl_get_path(),
+                                                 check_properties=check_properties)
 
     def find_first(self, bytype=None, byname=None, byvalue=None,
-                   type_='option', display_error=True):
+                   type_='option', display_error=True, check_properties=True):
         """
             finds an option recursively in the config
 
@@ -277,7 +286,8 @@ class SubConfig(object):
         """
         return self._cfgimpl_get_context()._find(
             bytype, byname, byvalue, first=True, type_=type_,
-            _subpath=self.cfgimpl_get_path(), display_error=display_error)
+            _subpath=self.cfgimpl_get_path(), display_error=display_error,
+            check_properties=check_properties)
 
     def _find(self, bytype, byname, byvalue, first, type_='option',
               _subpath=None, check_properties=True, display_error=True):
@@ -734,4 +744,6 @@ def mandatory_warnings(config):
         except PropertiesOptionError as err:
             if err.proptype == ['mandatory']:
                 yield path
+        except ConfigError:
+            pass
     config.cfgimpl_reset_cache(only=('values',))