From: Leandro Lucarella Date: Wed, 10 Oct 2007 19:00:43 +0000 (-0300) Subject: Raise a CommandNotFoundError if updating an object without update(). X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/9a326a33b28fb685e681bf63c63be9f820db0356 Raise a CommandNotFoundError if updating an object without update(). When a DictSubHandler try to update an object that doesn't have an update() method, it raises a CommandNotFoundError to emulate that the update command doesn't exist. --- diff --git a/pymin/services/util.py b/pymin/services/util.py index c0371a1..3f50957 100644 --- a/pymin/services/util.py +++ b/pymin/services/util.py @@ -9,7 +9,8 @@ try: except ImportError: import pickle -from pymin.dispatcher import Handler, handler, HandlerError +from pymin.dispatcher import Handler, handler, HandlerError, \ + CommandNotFoundError #DEBUG = False DEBUG = True @@ -619,6 +620,10 @@ class DictSubHandler(SubHandler): @handler(u'Update an item') def update(self, key, *args, **kwargs): r"update(key, ...) -> None :: Update an item of the dict." + # TODO make it right with metaclasses, so the method is not created + # unless the update() method really exists. + if not hasattr(self._dict_subhandler_class, 'update'): + raise CommandNotFoundError(('update',)) if not key in self._dict(): raise ItemNotFoundError(key) self._dict()[key].update(*args, **kwargs)