qubes: fix None serialisation for VMProperty

Note that None != default (no attribute in XML at all).

This is reworked
  27eddcb WIP core: fix deserializing None for VMProperty
by Marek.
This commit is contained in:
Wojtek Porczyk 2016-02-24 12:22:20 +01:00
parent 843cf68c1a
commit c531b0eac2

View File

@ -1028,6 +1028,8 @@ class VMProperty(property):
and ``setter`` and ``setter``
''' '''
_none_value = ''
def __init__(self, name, vmclass=qubes.vm.BaseVM, allow_none=False, def __init__(self, name, vmclass=qubes.vm.BaseVM, allow_none=False,
**kwargs): **kwargs):
if 'type' in kwargs: if 'type' in kwargs:
@ -1043,13 +1045,16 @@ class VMProperty(property):
"'vmclass' should specify a subclass of qubes.vm.BaseVM") "'vmclass' should specify a subclass of qubes.vm.BaseVM")
super(VMProperty, self).__init__(name, super(VMProperty, self).__init__(name,
saver=(lambda self, prop, value: value.name if value else 'None'), saver=(lambda self_, prop, value:
self._none_value if value is None else value.name),
**kwargs) **kwargs)
self.vmclass = vmclass self.vmclass = vmclass
self.allow_none = allow_none self.allow_none = allow_none
def __set__(self, instance, value): def __set__(self, instance, value):
if value == self._none_value:
value = None
if value is None: if value is None:
if self.allow_none: if self.allow_none:
super(VMProperty, self).__set__(instance, value) super(VMProperty, self).__set__(instance, value)