<s> """<STR_LIT>""" <EOL> import re <EOL> class Trigger : <EOL> MODE_ERROR = <NUM_LIT:0> <EOL> MODE_SUCCESS = <NUM_LIT:1> <EOL> MODE_UNKNOWN = <NUM_LIT:2> <EOL> def __init__ ( self , mode = MODE_SUCCESS ) : <EOL> self . _mode = mode <EOL> pass <EOL> def is_error ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _mode is Trigger . MODE_ERROR <EOL> def get_mode ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _mode <EOL> def set_mode ( self , mode ) : <EOL> """<STR_LIT>""" <EOL> self . _mode = mode <EOL> def execute ( self , response ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> class StatusTrigger ( Trigger ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , status , * args , ** kwargs ) : <EOL> Trigger . __init__ ( self , * args , ** kwargs ) <EOL> self . _status = status <EOL> def execute ( self , response ) : <EOL> """<STR_LIT>""" <EOL> return response . get_status ( ) is self . _status <EOL> class RegexpTrigger ( Trigger ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , regexps , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> Trigger . __init__ ( self , * args , ** kwargs ) <EOL> self . _regexps = [ ] <EOL> if isinstance ( regexps , list ) : <EOL> for regexp in regexps : <EOL> self . _regexps . append ( re . compile ( regexp , re . I | re . MULTILINE ) ) <EOL> else : <EOL> self . _regexps = [ re . compile ( regexps ) ] <EOL> def execute ( self , response ) : <EOL> """<STR_LIT>""" <EOL> content = response . get_content ( ) <EOL> for regexp in self . _regexps : <EOL> if regexp . search ( content ) : <EOL> return True <EOL> return False </s>
