Guest User

Untitled

a guest
Aug 7th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ItemValidator(object):
  2.  
  3. def __init__(self, items, item=None):
  4. self.items = items
  5. self.item = item
  6.  
  7. def validate(self):
  8. if self.item:
  9. if self.item.color = "Green" and Item("Red") in self.items: # or something like that
  10. raise MyGreenValidationError
  11. return True
  12.  
  13. >>> f = Foo()
  14. >>> item = Item("Green")
  15. >>> i = ItemValidator(f.items, item=item)
  16. >>> if i.validate():
  17. >>> f.items.add(item)
Advertisement
Add Comment
Please, Sign In to add comment