<s> from taskflow . listeners import base <EOL> def _freeze_it ( values ) : <EOL> """<STR_LIT>""" <EOL> if not values : <EOL> return frozenset ( ) <EOL> else : <EOL> return frozenset ( values ) <EOL> class CaptureListener ( base . Listener ) : <EOL> """<STR_LIT>""" <EOL> FLOW = '<STR_LIT>' <EOL> TASK = '<STR_LIT>' <EOL> RETRY = '<STR_LIT>' <EOL> def __init__ ( self , engine , <EOL> task_listen_for = base . DEFAULT_LISTEN_FOR , <EOL> flow_listen_for = base . DEFAULT_LISTEN_FOR , <EOL> retry_listen_for = base . DEFAULT_LISTEN_FOR , <EOL> capture_flow = True , capture_task = True , capture_retry = True , <EOL> skip_tasks = None , skip_retries = None , skip_flows = None , <EOL> values = None ) : <EOL> super ( CaptureListener , self ) . __init__ ( <EOL> engine , <EOL> task_listen_for = task_listen_for , <EOL> flow_listen_for = flow_listen_for , <EOL> retry_listen_for = retry_listen_for ) <EOL> self . _capture_flow = capture_flow <EOL> self . _capture_task = capture_task <EOL> self . _capture_retry = capture_retry <EOL> self . _skip_tasks = _freeze_it ( skip_tasks ) <EOL> self . _skip_flows = _freeze_it ( skip_flows ) <EOL> self . _skip_retries = _freeze_it ( skip_retries ) <EOL> if values is None : <EOL> self . values = [ ] <EOL> else : <EOL> self . values = values <EOL> @ staticmethod <EOL> def _format_capture ( kind , state , details ) : <EOL> """<STR_LIT>""" <EOL> return ( kind , state , details ) <EOL> def _task_receiver ( self , state , details ) : <EOL> if self . _capture_task : <EOL> if details [ '<STR_LIT>' ] not in self . _skip_tasks : <EOL> self . values . append ( self . _format_capture ( self . TASK , <EOL> state , details ) ) <EOL> def _retry_receiver ( self , state , details ) : <EOL> if self . _capture_retry : <EOL> if details [ '<STR_LIT>' ] not in self . _skip_retries : <EOL> self . values . append ( self . _format_capture ( self . RETRY , <EOL> state , details ) ) <EOL> def _flow_receiver ( self , state , details ) : <EOL> if self . _capture_flow : <EOL> if details [ '<STR_LIT>' ] not in self . _skip_flows : <EOL> self . values . append ( self . _format_capture ( self . FLOW , <EOL> state , details ) ) </s>
