<s> """<STR_LIT>""" <EOL> from traits . api import HasTraits , List , Str , Tuple <EOL> class EventTracker ( HasTraits ) : <EOL> """<STR_LIT>""" <EOL> events = List ( Tuple ) <EOL> event_names = List ( Str ) <EOL> subscriptions = List ( Tuple ) <EOL> def _subscriptions_changed ( self , old , new ) : <EOL> """<STR_LIT>""" <EOL> for subscription in old : <EOL> self . _remove_subscription ( subscription ) <EOL> for subscription in new : <EOL> self . _add_subscription ( subscription ) <EOL> return <EOL> def _subscriptions_items_changed ( self , event ) : <EOL> """<STR_LIT>""" <EOL> for subscription in event . removed : <EOL> self . _remove_subscription ( subscription ) <EOL> for subscription in event . added : <EOL> self . _add_subscription ( subscription ) <EOL> return <EOL> def _listener ( self , obj , trait_name , old , new ) : <EOL> """<STR_LIT>""" <EOL> self . events . append ( ( obj , trait_name , old , new ) ) <EOL> self . event_names . append ( trait_name ) <EOL> return <EOL> def _add_subscription ( self , subscription ) : <EOL> """<STR_LIT>""" <EOL> obj , trait_name = subscription <EOL> if trait_name is not None : <EOL> obj . on_trait_change ( self . _listener , trait_name ) <EOL> else : <EOL> obj . on_trait_change ( self . _listener ) <EOL> return <EOL> def _remove_subscription ( self , subscription ) : <EOL> """<STR_LIT>""" <EOL> obj , trait_name = subscription <EOL> if trait_name is not None : <EOL> obj . on_trait_change ( self . _listener , trait_name , remove = True ) <EOL> else : <EOL> obj . on_trait_change ( self . _listener , remove = True ) <EOL> return </s>
