

class ENotifer(object):
    def notify(self, notification):
        notification.notifier = notification.notifier or self
        for listener in self._eternal_listener + self.listeners:
            listener.notifyChanged(notification)


def enum(enumName, *listValueNames):
    """Clever implementation of an enum like in python

    Shameless copy from: http://sametmax.com/faire-des-enums-en-python/
    """
    listValueNumbers = range(len(listValueNames))
    dictAttrib = dict(zip(listValueNames, listValueNumbers))
    dictReverse = dict(zip(listValueNumbers, listValueNames))
    dictAttrib["dictReverse"] = dictReverse
    mainType = type(enumName, (), dictAttrib)
    return mainType


Kind = enum('Kind',
            'ADD',
            'ADD_MANY',
            'MOVE',
            'REMOVE',
            'REMOVE_MANY',
            'SET',
            'UNSET')


class Notification(object):
    def __init__(self, notifier=None, kind=None, old=None, new=None,
                 feature=None):
        self.notifier = notifier
        self.kind = kind
        self.old = old
        self.new = new
        self.feature = feature

    def __repr__(self):
        return ('[{0}] old={1} new={2} obj={3} #{4}'
                .format(Kind.dictReverse[self.kind],
                        self.old,
                        self.new,
                        self.notifier,
                        self.feature))


class EObserver(object):
    def __init__(self, notifier=None, notifyChanged=None):
        if notifier:
            notifier.listeners.append(self)
        if notifyChanged:
            self.notifyChanged = notifyChanged

    def observe(self, notifier):
        notifier.listeners.append(self)

    def notifyChanged(self, notification):
        pass

from enum import Enum, unique


class ENotifer(object):
    def notify(self, notification):
        notification.notifier = notification.notifier or self
        for listener in self._eternal_listener + self.listeners:
            listener.notifyChanged(notification)


@unique
class Kind(Enum):
    ADD = 0
    ADD_MANY = 1
    MOVE = 2
    REMOVE = 3
    REMOVE_MANY = 4
    SET = 5
    UNSET = 6


class Notification(object):
    def __init__(self, notifier=None, kind=None, old=None, new=None,
                 feature=None):
        self.notifier = notifier
        self.kind = kind
        self.old = old
        self.new = new
        self.feature = feature

    def __repr__(self):
        return ('[{0}] old={1} new={2} obj={3} #{4}'
                .format(self.kind.name,
                        self.old,
                        self.new,
                        self.notifier,
                        self.feature))


class EObserver(object):
    def __init__(self, notifier=None, notifyChanged=None):
        if notifier:
            notifier.listeners.append(self)
        if notifyChanged:
            self.notifyChanged = notifyChanged

    def observe(self, notifier):
        notifier.listeners.append(self)

    def notifyChanged(self, notification):
        pass

Add better enumeration for Notification
Add better enumeration for Notification

The previous 'Kind' enumeration for Notification were using a
home-made-cooked way of dealing with enumeration. The code were got
from an article from the http://sametmax.com/ website (great website
by the way). This new version uses the python 3.4 enumeration module,
but as this module had been introduced in Python 3.4, it means that
the Python 3.3 compatibility is broken.
