ObserverCode
class NoView(Exception): """The view does not exist."""
pass
class NoController(Exception): """The controller does not exist."""
pass
class Observer:
def __init__(self, aView, aController): """Construct the instance."""
self.__dict = {} self.__dict['view'] = aView self.__dict['controller'] = aController
return
def __del__(self): """Destroy the instance."""
self.finished() return
def finished(self): """Manually break the loops."""
for item in self.__dict.values(): if item: item.finished()
self.__dict = {} self.__dict['view'] = None self.__dict['controller'] = None return
def getView(self): """Return the view."""
result = None
if self.__dict['view']: result = self.__dict['view'] else: raise NoView
return result
def getController(self): """Return the controller."""
result = None
if self.__dict['controller']: result = self.__dict['controller'] else: raise NoController
return result
def __getitem__(self, key): """Private helper."""
return self.__dict[key]