Fix some collecton validation

And add restrict_level helper method.
This commit is contained in:
Laurent Bachelier 2012-03-11 15:25:16 +01:00
commit 1430b40bc5
7 changed files with 11 additions and 13 deletions

View file

@ -96,8 +96,7 @@ class Transfer(CapBaseObject):
class ICapBank(ICapCollection):
def iter_resources(self, objs, split_path):
if Account in objs:
if len(split_path) > 0:
raise CollectionNotFound(split_path)
self._restrict_level(split_path)
return self.iter_accounts()

View file

@ -56,8 +56,7 @@ class Subscription(CapBaseObject):
class ICapBill(ICapCollection):
def iter_resources(self, objs, split_path):
if Subscription in objs:
if len(split_path) > 0:
raise CollectionNotFound(split_path)
self._restrict_level(split_path)
return self.iter_subscription()

View file

@ -100,3 +100,7 @@ class ICapCollection(IBaseCap):
i.next()
except StopIteration:
raise CollectionNotFound(collection.split_path)
def _restrict_level(self, split_path, lmax=0):
if len(split_path) > lmax:
raise CollectionNotFound(split_path)