true serialize for _children
authorEmmanuel Garette <egarette@cadoles.com>
Mon, 2 Sep 2013 19:29:41 +0000 (21:29 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Mon, 2 Sep 2013 19:29:41 +0000 (21:29 +0200)
tiramisu/option.py

index 67b2fa5..f5b171c 100644 (file)
@@ -98,7 +98,7 @@ class BaseOption(BaseInformation):
     """
     __slots__ = ('_name', '_requires', '_properties', '_readonly',
                  '_consistencies', '_calc_properties', '_state_consistencies',
-                 '_state_requires')
+                 '_state_requires', '_stated')
 
     def __init__(self, name, doc, requires, properties):
         if not valid_name(name):
@@ -200,15 +200,20 @@ class BaseOption(BaseInformation):
                 self._state_requires = new_value
 
     def _impl_getstate(self, descr):
+        self._stated = True
         self._impl_convert_consistencies(descr)
         self._impl_convert_requires(descr)
 
     def __getstate__(self, export=False):
+        try:
+            self._stated
+        except AttributeError:
+            raise SystemError(_('cannot serialize Option, only in OptionDescription'))
         slots = set()
         for subclass in self.__class__.__mro__:
             if subclass is not object:
                 slots.update(subclass.__slots__)
-        slots -= frozenset(['_children', '_cache_paths', '__weakref__'])
+        slots -= frozenset(['_cache_paths', '__weakref__'])
         states = {}
         for slot in slots:
             # remove variable if save variable converted in _state_xxxx variable
@@ -814,7 +819,7 @@ class OptionDescription(BaseOption):
                  '_state_group_type', '_properties', '_children',
                  '_consistencies', '_calc_properties', '__weakref__',
                  '_readonly', '_impl_informations', '_state_requires',
-                 '_state_consistencies')
+                 '_state_consistencies', '_stated')
     _opt_type = 'optiondescription'
 
     def __init__(self, name, doc, children, requires=None, properties=None):
@@ -1017,14 +1022,16 @@ class OptionDescription(BaseOption):
         for option in self.impl_getchildren():
             option._impl_getstate(descr)
 
-    def __getstate__(self, export=False):
-        if not export:
+    def __getstate__(self):
+        try:
+            del(self._stated)
+        except AttributeError:
+            # if cannot delete, _impl_getstate never launch
+            # launch it recursivement
+            # _stated prevent __getstate__ launch more than one time
+            # _stated is delete, if re-serialize, re-lauch _impl_getstate
             self._impl_getstate()
-        states = super(OptionDescription, self).__getstate__(True)
-        states['_state_children'] = []
-        for option in self.impl_getchildren():
-            states['_state_children'].append(option.__getstate__(True))
-        return states
+        return super(OptionDescription, self).__getstate__()
 
 
 def validate_requires_arg(requires, name):