sequence.py 987 B

1234567891011121314151617181920212223242526272829303132
  1. '''This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
  2. Copyright 2011 by the AToMPM team and licensed under the LGPL
  3. See COPYING.lesser and README.md in the root of this project for full details'''
  4. from ..tcore.composer import Composer
  5. class Sequence(Composer):
  6. '''
  7. Applies each rule in the order provided.
  8. '''
  9. def __init__(self, rules):
  10. '''
  11. Applies each rule in the order provided.
  12. @param rules: The rules to apply.
  13. '''
  14. super(Sequence, self).__init__()
  15. self.rules = rules
  16. def packet_in(self, packet):
  17. self.exception = None
  18. self.is_success = False
  19. for rule in self.rules:
  20. packet = rule.packet_in(packet)
  21. packet.clean()
  22. if not rule.is_success:
  23. if rule.exception is not None:
  24. self.exception = rule.exception
  25. return packet
  26. self.is_success = True
  27. return packet