X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/3660782f64b0e3dfc2db4b1bfce4c59b4b46e3fc..0b06609c08cbd1e1b7120f617a2261028b02dce5:/pymin/services/util.py diff --git a/pymin/services/util.py b/pymin/services/util.py index b665c00..9c96fca 100644 --- a/pymin/services/util.py +++ b/pymin/services/util.py @@ -703,7 +703,7 @@ class ContainerSubHandler(SubHandler): item.update(*args, **kwargs) if hasattr(item, '_update'): item._update = True - except IndexError: + except LookupError: raise ItemNotFoundError(index) @handler(u'Delete an item') @@ -718,9 +718,17 @@ class ContainerSubHandler(SubHandler): else: del self._attr()[index] return item - except IndexError: + except LookupError: raise ItemNotFoundError(index) + @handler(u'Remove all items (use with care).') + def clear(self): + r"clear() -> None :: Delete all items of the container." + if isinstance(self._attr(), dict): + self._attr.clear() + else: + self._attr(list()) + @handler(u'Get information about an item') def get(self, index): r"get(index) -> item :: List all the information of an item." @@ -728,7 +736,7 @@ class ContainerSubHandler(SubHandler): index = int(index) # TODO validation try: return self._vattr()[index] - except IndexError: + except LookupError: raise ItemNotFoundError(index) @handler(u'Get information about all items')