2020-03-23 22:56:05 +00:00
|
|
|
from abc import ABC, abstractmethod
|
2021-01-24 19:53:51 +00:00
|
|
|
from owrx.property.validators import Validator
|
2021-02-23 23:09:57 +00:00
|
|
|
from owrx.property.filter import Filter, ByPropertyName
|
2020-03-21 21:40:39 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2021-01-30 15:03:35 +00:00
|
|
|
class PropertyError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-02-26 00:12:03 +00:00
|
|
|
class PropertyDeletion(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# a special object that will be sent in events when a deletion occured
|
|
|
|
# it can also represent deletion of a key in internal storage, but should not be return from standard dict apis
|
|
|
|
PropertyDeleted = PropertyDeletion()
|
|
|
|
|
|
|
|
|
2020-03-21 21:40:39 +00:00
|
|
|
class Subscription(object):
|
2020-03-23 22:56:05 +00:00
|
|
|
def __init__(self, subscriptee, name, subscriber):
|
2020-03-21 21:40:39 +00:00
|
|
|
self.subscriptee = subscriptee
|
2020-03-23 22:56:05 +00:00
|
|
|
self.name = name
|
2020-03-21 21:40:39 +00:00
|
|
|
self.subscriber = subscriber
|
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
def getName(self):
|
|
|
|
return self.name
|
|
|
|
|
2020-03-21 21:40:39 +00:00
|
|
|
def call(self, *args, **kwargs):
|
|
|
|
self.subscriber(*args, **kwargs)
|
|
|
|
|
|
|
|
def cancel(self):
|
|
|
|
self.subscriptee.unwire(self)
|
|
|
|
|
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
class PropertyManager(ABC):
|
|
|
|
def __init__(self):
|
2020-03-21 21:40:39 +00:00
|
|
|
self.subscribers = []
|
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
@abstractmethod
|
|
|
|
def __getitem__(self, item):
|
|
|
|
pass
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
@abstractmethod
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def __contains__(self, item):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def __dict__(self):
|
|
|
|
pass
|
|
|
|
|
2020-05-14 20:56:49 +00:00
|
|
|
@abstractmethod
|
|
|
|
def __delitem__(self, key):
|
|
|
|
pass
|
|
|
|
|
2020-03-24 19:36:26 +00:00
|
|
|
@abstractmethod
|
|
|
|
def keys(self):
|
|
|
|
pass
|
|
|
|
|
2021-03-06 22:34:27 +00:00
|
|
|
@abstractmethod
|
|
|
|
def values(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-02-23 22:23:37 +00:00
|
|
|
def items(self):
|
2021-03-06 22:34:27 +00:00
|
|
|
pass
|
2021-02-23 22:23:37 +00:00
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return self.__dict__().__len__()
|
|
|
|
|
2020-03-24 21:16:11 +00:00
|
|
|
def filter(self, *props):
|
2021-02-23 23:09:57 +00:00
|
|
|
return PropertyFilter(self, ByPropertyName(*props))
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2021-01-30 15:03:35 +00:00
|
|
|
def readonly(self):
|
|
|
|
return PropertyReadOnly(self)
|
|
|
|
|
2020-03-21 21:40:39 +00:00
|
|
|
def wire(self, callback):
|
2020-03-23 22:56:05 +00:00
|
|
|
sub = Subscription(self, None, callback)
|
2020-03-21 21:40:39 +00:00
|
|
|
self.subscribers.append(sub)
|
2020-03-23 22:56:05 +00:00
|
|
|
return sub
|
|
|
|
|
|
|
|
def wireProperty(self, name, callback):
|
|
|
|
sub = Subscription(self, name, callback)
|
|
|
|
self.subscribers.append(sub)
|
|
|
|
if name in self:
|
|
|
|
sub.call(self[name])
|
2020-03-21 21:40:39 +00:00
|
|
|
return sub
|
|
|
|
|
|
|
|
def unwire(self, sub):
|
|
|
|
try:
|
|
|
|
self.subscribers.remove(sub)
|
|
|
|
except ValueError:
|
|
|
|
# happens when already removed before
|
|
|
|
pass
|
|
|
|
return self
|
|
|
|
|
2020-12-30 16:14:06 +00:00
|
|
|
def _fireCallbacks(self, changes):
|
|
|
|
if not changes:
|
|
|
|
return
|
2021-04-07 14:20:10 +00:00
|
|
|
subscribers = self.subscribers.copy()
|
|
|
|
for c in subscribers:
|
2020-03-23 22:56:05 +00:00
|
|
|
try:
|
|
|
|
if c.getName() is None:
|
2020-12-30 16:14:06 +00:00
|
|
|
c.call(changes)
|
|
|
|
except Exception:
|
|
|
|
logger.exception("exception while firing changes")
|
|
|
|
for name in changes:
|
2021-04-07 14:20:10 +00:00
|
|
|
for c in subscribers:
|
2020-12-30 16:14:06 +00:00
|
|
|
try:
|
|
|
|
if c.getName() == name:
|
|
|
|
c.call(changes[name])
|
|
|
|
except Exception:
|
|
|
|
logger.exception("exception while firing changes")
|
2020-03-21 21:40:39 +00:00
|
|
|
|
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
class PropertyLayer(PropertyManager):
|
2021-02-11 18:31:44 +00:00
|
|
|
def __init__(self, **kwargs):
|
2020-03-23 22:56:05 +00:00
|
|
|
super().__init__()
|
2021-02-11 18:31:44 +00:00
|
|
|
# copy, don't re-use
|
|
|
|
self.properties = {k: v for k, v in kwargs.items()}
|
2020-03-21 21:40:39 +00:00
|
|
|
|
|
|
|
def __contains__(self, name):
|
2020-03-23 22:56:05 +00:00
|
|
|
return name in self.properties
|
2020-03-21 21:40:39 +00:00
|
|
|
|
|
|
|
def __getitem__(self, name):
|
2020-03-23 22:56:05 +00:00
|
|
|
return self.properties[name]
|
2020-03-21 21:40:39 +00:00
|
|
|
|
|
|
|
def __setitem__(self, name, value):
|
2020-03-23 23:18:10 +00:00
|
|
|
if name in self.properties and self.properties[name] == value:
|
|
|
|
return
|
2020-03-23 22:56:05 +00:00
|
|
|
self.properties[name] = value
|
2020-12-30 16:14:06 +00:00
|
|
|
self._fireCallbacks({name: value})
|
2020-03-21 21:40:39 +00:00
|
|
|
|
|
|
|
def __dict__(self):
|
2020-03-23 22:56:05 +00:00
|
|
|
return {k: v for k, v in self.properties.items()}
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2020-05-14 20:56:49 +00:00
|
|
|
def __delitem__(self, key):
|
2021-02-26 00:12:03 +00:00
|
|
|
self.properties.__delitem__(key)
|
|
|
|
self._fireCallbacks({key: PropertyDeleted})
|
2020-05-14 20:56:49 +00:00
|
|
|
|
2020-03-24 19:36:26 +00:00
|
|
|
def keys(self):
|
|
|
|
return self.properties.keys()
|
|
|
|
|
2021-03-06 22:34:27 +00:00
|
|
|
def values(self):
|
|
|
|
return self.properties.values()
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return self.properties.items()
|
|
|
|
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
class PropertyFilter(PropertyManager):
|
2021-02-23 23:09:57 +00:00
|
|
|
def __init__(self, pm: PropertyManager, filter: Filter):
|
2020-03-23 22:56:05 +00:00
|
|
|
super().__init__()
|
|
|
|
self.pm = pm
|
2021-02-23 23:09:57 +00:00
|
|
|
self._filter = filter
|
2020-03-23 22:56:05 +00:00
|
|
|
self.pm.wire(self.receiveEvent)
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2020-12-30 16:14:06 +00:00
|
|
|
def receiveEvent(self, changes):
|
2021-02-23 23:09:57 +00:00
|
|
|
changesToForward = {name: value for name, value in changes.items() if self._filter.apply(name)}
|
2020-12-30 16:14:06 +00:00
|
|
|
self._fireCallbacks(changesToForward)
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
def __getitem__(self, item):
|
2021-02-23 23:09:57 +00:00
|
|
|
if not self._filter.apply(item):
|
2020-03-23 22:56:05 +00:00
|
|
|
raise KeyError(item)
|
|
|
|
return self.pm.__getitem__(item)
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
def __setitem__(self, key, value):
|
2021-02-23 23:09:57 +00:00
|
|
|
if not self._filter.apply(key):
|
2020-03-23 22:56:05 +00:00
|
|
|
raise KeyError(key)
|
|
|
|
return self.pm.__setitem__(key, value)
|
2020-03-21 21:40:39 +00:00
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
def __contains__(self, item):
|
2021-02-23 23:09:57 +00:00
|
|
|
if not self._filter.apply(item):
|
2020-03-23 22:56:05 +00:00
|
|
|
return False
|
|
|
|
return self.pm.__contains__(item)
|
|
|
|
|
|
|
|
def __dict__(self):
|
2021-02-23 23:09:57 +00:00
|
|
|
return {k: v for k, v in self.pm.__dict__().items() if self._filter.apply(k)}
|
2020-03-22 20:51:49 +00:00
|
|
|
|
2020-05-14 20:56:49 +00:00
|
|
|
def __delitem__(self, key):
|
2021-02-23 23:09:57 +00:00
|
|
|
if not self._filter.apply(key):
|
2020-05-14 20:56:49 +00:00
|
|
|
raise KeyError(key)
|
|
|
|
return self.pm.__delitem__(key)
|
|
|
|
|
2020-03-24 19:36:26 +00:00
|
|
|
def keys(self):
|
2021-02-23 23:09:57 +00:00
|
|
|
return [k for k in self.pm.keys() if self._filter.apply(k)]
|
2020-03-24 19:36:26 +00:00
|
|
|
|
2021-03-06 22:34:27 +00:00
|
|
|
def values(self):
|
|
|
|
return [v for k, v in self.pm.items() if self._filter.apply(k)]
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return self.__dict__().items()
|
|
|
|
|
2020-03-22 20:51:49 +00:00
|
|
|
|
2021-01-30 15:03:35 +00:00
|
|
|
class PropertyDelegator(PropertyManager):
|
|
|
|
def __init__(self, pm: PropertyManager):
|
|
|
|
self.pm = pm
|
2021-02-28 23:26:56 +00:00
|
|
|
self.subscription = self.pm.wire(self._fireCallbacks)
|
2021-01-30 15:03:35 +00:00
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def __getitem__(self, item):
|
|
|
|
return self.pm.__getitem__(item)
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
return self.pm.__setitem__(key, value)
|
|
|
|
|
|
|
|
def __contains__(self, item):
|
|
|
|
return self.pm.__contains__(item)
|
|
|
|
|
|
|
|
def __dict__(self):
|
|
|
|
return self.pm.__dict__()
|
|
|
|
|
|
|
|
def __delitem__(self, key):
|
|
|
|
return self.pm.__delitem__(key)
|
|
|
|
|
|
|
|
def keys(self):
|
|
|
|
return self.pm.keys()
|
|
|
|
|
2021-03-06 22:34:27 +00:00
|
|
|
def values(self):
|
|
|
|
return self.pm.values()
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return self.pm.items()
|
|
|
|
|
2021-01-30 15:03:35 +00:00
|
|
|
|
|
|
|
class PropertyValidationError(PropertyError):
|
2021-01-24 20:19:45 +00:00
|
|
|
def __init__(self, key, value):
|
|
|
|
super().__init__('Invalid value for property "{key}": "{value}"'.format(key=key, value=str(value)))
|
|
|
|
|
|
|
|
|
2021-01-30 15:03:35 +00:00
|
|
|
class PropertyValidator(PropertyDelegator):
|
2021-01-24 20:19:45 +00:00
|
|
|
def __init__(self, pm: PropertyManager, validators=None):
|
2021-01-30 15:03:35 +00:00
|
|
|
super().__init__(pm)
|
2021-01-24 20:19:45 +00:00
|
|
|
if validators is None:
|
|
|
|
self.validators = {}
|
|
|
|
else:
|
|
|
|
self.validators = {k: Validator.of(v) for k, v in validators.items()}
|
|
|
|
|
|
|
|
def validate(self, key, value):
|
|
|
|
if key not in self.validators:
|
|
|
|
return
|
|
|
|
if not self.validators[key].isValid(value):
|
|
|
|
raise PropertyValidationError(key, value)
|
|
|
|
|
|
|
|
def setValidator(self, key, validator):
|
|
|
|
self.validators[key] = Validator.of(validator)
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
self.validate(key, value)
|
|
|
|
return self.pm.__setitem__(key, value)
|
|
|
|
|
|
|
|
|
2021-01-30 15:03:35 +00:00
|
|
|
class PropertyWriteError(PropertyError):
|
|
|
|
def __init__(self, key):
|
|
|
|
super().__init__('Key "{key}" is not writeable'.format(key=key))
|
2021-01-24 20:19:45 +00:00
|
|
|
|
|
|
|
|
2021-01-30 15:03:35 +00:00
|
|
|
class PropertyReadOnly(PropertyDelegator):
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
raise PropertyWriteError(key)
|
2021-01-24 20:19:45 +00:00
|
|
|
|
2021-03-19 23:54:45 +00:00
|
|
|
def __delitem__(self, key):
|
|
|
|
raise PropertyWriteError(key)
|
|
|
|
|
2021-01-24 20:19:45 +00:00
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
class PropertyStack(PropertyManager):
|
2020-03-22 20:51:49 +00:00
|
|
|
def __init__(self):
|
2020-03-23 22:56:05 +00:00
|
|
|
super().__init__()
|
2020-03-22 20:51:49 +00:00
|
|
|
self.layers = []
|
|
|
|
|
|
|
|
def addLayer(self, priority: int, pm: PropertyManager):
|
|
|
|
"""
|
|
|
|
highest priority = 0
|
|
|
|
"""
|
2020-12-30 16:14:06 +00:00
|
|
|
self._fireCallbacks(self._addLayer(priority, pm))
|
2020-03-24 21:11:54 +00:00
|
|
|
|
|
|
|
def _addLayer(self, priority: int, pm: PropertyManager):
|
|
|
|
changes = {}
|
2020-03-24 19:36:26 +00:00
|
|
|
for key in pm.keys():
|
|
|
|
if key not in self or self[key] != pm[key]:
|
2020-03-24 21:11:54 +00:00
|
|
|
changes[key] = pm[key]
|
2020-03-22 20:51:49 +00:00
|
|
|
|
2020-12-30 16:14:06 +00:00
|
|
|
def eventClosure(changes):
|
|
|
|
self.receiveEvent(pm, changes)
|
2020-03-23 23:08:48 +00:00
|
|
|
|
2020-03-24 21:11:54 +00:00
|
|
|
sub = pm.wire(eventClosure)
|
2020-03-23 23:08:48 +00:00
|
|
|
|
2020-03-24 21:11:54 +00:00
|
|
|
self.layers.append({"priority": priority, "props": pm, "sub": sub})
|
|
|
|
|
|
|
|
return changes
|
2020-03-23 23:08:48 +00:00
|
|
|
|
2021-03-20 23:14:18 +00:00
|
|
|
def removeLayerByPriority(self, priority):
|
|
|
|
for layer in self.layers:
|
|
|
|
if layer["priority"] == priority:
|
|
|
|
self.removeLayer(layer["props"])
|
|
|
|
|
2020-03-22 20:51:49 +00:00
|
|
|
def removeLayer(self, pm: PropertyManager):
|
|
|
|
for layer in self.layers:
|
|
|
|
if layer["props"] == pm:
|
2020-12-30 16:14:06 +00:00
|
|
|
self._fireCallbacks(self._removeLayer(layer))
|
2020-03-24 21:11:54 +00:00
|
|
|
|
|
|
|
def _removeLayer(self, layer):
|
|
|
|
layer["sub"].cancel()
|
|
|
|
self.layers.remove(layer)
|
|
|
|
changes = {}
|
|
|
|
pm = layer["props"]
|
|
|
|
for key in pm.keys():
|
|
|
|
if key in self:
|
|
|
|
if self[key] != pm[key]:
|
|
|
|
changes[key] = self[key]
|
|
|
|
else:
|
2021-02-26 00:12:03 +00:00
|
|
|
changes[key] = PropertyDeleted
|
2020-03-24 21:11:54 +00:00
|
|
|
return changes
|
|
|
|
|
|
|
|
def replaceLayer(self, priority: int, pm: PropertyManager):
|
|
|
|
layers = [x for x in self.layers if x["priority"] == priority]
|
|
|
|
|
2020-03-25 16:59:00 +00:00
|
|
|
originalState = self.__dict__()
|
|
|
|
|
|
|
|
changes = self._removeLayer(layers[0]) if layers else {}
|
|
|
|
changes = {**changes, **self._addLayer(priority, pm)}
|
|
|
|
changes = {k: v for k, v in changes.items() if k not in originalState or originalState[k] != v}
|
2020-03-24 21:11:54 +00:00
|
|
|
|
2020-12-30 16:14:06 +00:00
|
|
|
self._fireCallbacks(changes)
|
2020-03-24 21:11:54 +00:00
|
|
|
|
2020-12-30 16:14:06 +00:00
|
|
|
def receiveEvent(self, layer, changes):
|
|
|
|
changesToForward = {name: value for name, value in changes.items() if layer == self._getTopLayer(name)}
|
2021-03-06 22:48:31 +00:00
|
|
|
# deletions need to be handled separately:
|
|
|
|
# * send a deletion if the key was deleted in all layers
|
|
|
|
# * send lower value if the key is still present in a lower layer
|
2021-02-26 00:12:03 +00:00
|
|
|
deletionsToForward = {
|
2021-03-06 22:48:31 +00:00
|
|
|
name: PropertyDeleted if self._getTopLayer(name, False) is None else self[name]
|
2021-02-26 00:12:03 +00:00
|
|
|
for name, value in changes.items()
|
2021-03-06 22:48:31 +00:00
|
|
|
if value is PropertyDeleted
|
2021-02-26 00:12:03 +00:00
|
|
|
}
|
|
|
|
self._fireCallbacks({**changesToForward, **deletionsToForward})
|
|
|
|
|
|
|
|
def _getTopLayer(self, item, fallback=True):
|
2020-03-22 20:51:49 +00:00
|
|
|
layers = [la["props"] for la in sorted(self.layers, key=lambda l: l["priority"])]
|
|
|
|
for m in layers:
|
|
|
|
if item in m:
|
2020-03-23 22:56:05 +00:00
|
|
|
return m
|
2021-02-26 00:12:03 +00:00
|
|
|
# return top layer as fallback
|
|
|
|
if fallback and layers:
|
2020-03-24 19:36:26 +00:00
|
|
|
return layers[0]
|
2020-03-23 22:56:05 +00:00
|
|
|
|
|
|
|
def __getitem__(self, item):
|
2020-03-23 23:08:48 +00:00
|
|
|
layer = self._getTopLayer(item)
|
2020-03-23 22:56:05 +00:00
|
|
|
return layer.__getitem__(item)
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
2020-03-23 23:08:48 +00:00
|
|
|
layer = self._getTopLayer(key)
|
2020-03-23 22:56:05 +00:00
|
|
|
return layer.__setitem__(key, value)
|
|
|
|
|
|
|
|
def __contains__(self, item):
|
2020-03-23 23:08:48 +00:00
|
|
|
layer = self._getTopLayer(item)
|
2020-03-24 19:36:26 +00:00
|
|
|
if layer:
|
|
|
|
return layer.__contains__(item)
|
|
|
|
return False
|
2020-03-23 22:56:05 +00:00
|
|
|
|
|
|
|
def __dict__(self):
|
2020-03-24 19:36:26 +00:00
|
|
|
return {k: self.__getitem__(k) for k in self.keys()}
|
|
|
|
|
2020-05-14 20:56:49 +00:00
|
|
|
def __delitem__(self, key):
|
|
|
|
for layer in self.layers:
|
2021-02-11 18:31:44 +00:00
|
|
|
if layer["props"].__contains__(key):
|
|
|
|
layer["props"].__delitem__(key)
|
2020-05-14 20:56:49 +00:00
|
|
|
|
2020-03-24 19:36:26 +00:00
|
|
|
def keys(self):
|
|
|
|
return set([key for l in self.layers for key in l["props"].keys()])
|
2021-02-28 23:26:56 +00:00
|
|
|
|
2021-03-06 22:34:27 +00:00
|
|
|
def values(self):
|
|
|
|
return [self.__getitem__(k) for k in self.keys()]
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return self.__dict__().items()
|
|
|
|
|
2021-02-28 23:26:56 +00:00
|
|
|
|
|
|
|
class PropertyCarousel(PropertyDelegator):
|
|
|
|
def __init__(self):
|
|
|
|
# start with an empty dummy layer
|
2021-03-05 18:09:51 +00:00
|
|
|
self.emptyLayer = PropertyLayer().readonly()
|
|
|
|
super().__init__(self.emptyLayer)
|
2021-02-28 23:26:56 +00:00
|
|
|
self.layers = {}
|
|
|
|
|
2021-03-05 18:09:51 +00:00
|
|
|
def _getDefaultLayer(self):
|
|
|
|
return self.emptyLayer
|
|
|
|
|
2021-02-28 23:26:56 +00:00
|
|
|
def addLayer(self, key, value):
|
2021-03-06 21:20:47 +00:00
|
|
|
if key in self.layers and self.layers[key] is self.pm:
|
|
|
|
self.layers[key] = value
|
|
|
|
# switch after introducing the new value
|
|
|
|
self.switch(key)
|
|
|
|
else:
|
|
|
|
self.layers[key] = value
|
2021-03-05 17:57:09 +00:00
|
|
|
|
|
|
|
def removeLayer(self, key):
|
2021-03-05 18:09:51 +00:00
|
|
|
if key in self.layers and self.layers[key] is self.pm:
|
|
|
|
self.switch()
|
2021-03-05 17:57:09 +00:00
|
|
|
del self.layers[key]
|
|
|
|
|
2021-03-05 18:09:51 +00:00
|
|
|
def switch(self, key=None):
|
2021-02-28 23:26:56 +00:00
|
|
|
before = self.pm
|
|
|
|
self.subscription.cancel()
|
2021-03-05 18:09:51 +00:00
|
|
|
self.pm = self._getDefaultLayer() if key is None else self.layers[key]
|
2021-02-28 23:26:56 +00:00
|
|
|
self.subscription = self.pm.wire(self._fireCallbacks)
|
|
|
|
changes = {}
|
|
|
|
for key in set(list(before.keys()) + list(self.keys())):
|
|
|
|
if key not in self:
|
|
|
|
changes[key] = PropertyDeleted
|
|
|
|
else:
|
|
|
|
if key not in before or before[key] != self[key]:
|
|
|
|
changes[key] = self[key]
|
|
|
|
self._fireCallbacks(changes)
|