true serialize for _children
This commit is contained in:
parent
84b7ec7b37
commit
cc3a33ef4f
1 changed files with 17 additions and 10 deletions
|
@ -98,7 +98,7 @@ class BaseOption(BaseInformation):
|
||||||
"""
|
"""
|
||||||
__slots__ = ('_name', '_requires', '_properties', '_readonly',
|
__slots__ = ('_name', '_requires', '_properties', '_readonly',
|
||||||
'_consistencies', '_calc_properties', '_state_consistencies',
|
'_consistencies', '_calc_properties', '_state_consistencies',
|
||||||
'_state_requires')
|
'_state_requires', '_stated')
|
||||||
|
|
||||||
def __init__(self, name, doc, requires, properties):
|
def __init__(self, name, doc, requires, properties):
|
||||||
if not valid_name(name):
|
if not valid_name(name):
|
||||||
|
@ -200,15 +200,20 @@ class BaseOption(BaseInformation):
|
||||||
self._state_requires = new_value
|
self._state_requires = new_value
|
||||||
|
|
||||||
def _impl_getstate(self, descr):
|
def _impl_getstate(self, descr):
|
||||||
|
self._stated = True
|
||||||
self._impl_convert_consistencies(descr)
|
self._impl_convert_consistencies(descr)
|
||||||
self._impl_convert_requires(descr)
|
self._impl_convert_requires(descr)
|
||||||
|
|
||||||
def __getstate__(self, export=False):
|
def __getstate__(self, export=False):
|
||||||
|
try:
|
||||||
|
self._stated
|
||||||
|
except AttributeError:
|
||||||
|
raise SystemError(_('cannot serialize Option, only in OptionDescription'))
|
||||||
slots = set()
|
slots = set()
|
||||||
for subclass in self.__class__.__mro__:
|
for subclass in self.__class__.__mro__:
|
||||||
if subclass is not object:
|
if subclass is not object:
|
||||||
slots.update(subclass.__slots__)
|
slots.update(subclass.__slots__)
|
||||||
slots -= frozenset(['_children', '_cache_paths', '__weakref__'])
|
slots -= frozenset(['_cache_paths', '__weakref__'])
|
||||||
states = {}
|
states = {}
|
||||||
for slot in slots:
|
for slot in slots:
|
||||||
# remove variable if save variable converted in _state_xxxx variable
|
# remove variable if save variable converted in _state_xxxx variable
|
||||||
|
@ -814,7 +819,7 @@ class OptionDescription(BaseOption):
|
||||||
'_state_group_type', '_properties', '_children',
|
'_state_group_type', '_properties', '_children',
|
||||||
'_consistencies', '_calc_properties', '__weakref__',
|
'_consistencies', '_calc_properties', '__weakref__',
|
||||||
'_readonly', '_impl_informations', '_state_requires',
|
'_readonly', '_impl_informations', '_state_requires',
|
||||||
'_state_consistencies')
|
'_state_consistencies', '_stated')
|
||||||
_opt_type = 'optiondescription'
|
_opt_type = 'optiondescription'
|
||||||
|
|
||||||
def __init__(self, name, doc, children, requires=None, properties=None):
|
def __init__(self, name, doc, children, requires=None, properties=None):
|
||||||
|
@ -1017,14 +1022,16 @@ class OptionDescription(BaseOption):
|
||||||
for option in self.impl_getchildren():
|
for option in self.impl_getchildren():
|
||||||
option._impl_getstate(descr)
|
option._impl_getstate(descr)
|
||||||
|
|
||||||
def __getstate__(self, export=False):
|
def __getstate__(self):
|
||||||
if not export:
|
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()
|
self._impl_getstate()
|
||||||
states = super(OptionDescription, self).__getstate__(True)
|
return super(OptionDescription, self).__getstate__()
|
||||||
states['_state_children'] = []
|
|
||||||
for option in self.impl_getchildren():
|
|
||||||
states['_state_children'].append(option.__getstate__(True))
|
|
||||||
return states
|
|
||||||
|
|
||||||
|
|
||||||
def validate_requires_arg(requires, name):
|
def validate_requires_arg(requires, name):
|
||||||
|
|
Loading…
Reference in a new issue