def _eventPlainTextDelegator(self, event, name, subclass=None, content=None): # watch for background job events and provide additional handling for ## the pending_jobs deferred objects waiting for bgapi response data if name == 'BACKGROUND_JOB': job_deferred = self.pending_jobs.get(event.dict['Job-UUID'], None) if job_deferred: job_deferred.callback(content) # determine the subscription function name funcname = utils.eventname2funcname(name, subclass=subclass) # construct the function list from all subscribers # NOTE: we copy the retrieved list into a new list object, to ## avoid object reference issues causing the list contained in ## the event_subscriptions dict to be modified if subclass: funclist = list(self.event_subscriptions.get( ' '.join([name, subclass]), [])) else: funclist = list(self.event_subscriptions.get(name, [])) # make sure subscribers for ALL events get this one funclist += self.event_subscriptions.get('ALL', []) # construct an informative event title title = name if subclass: title = ' '.join([title, subclass]) for func in funclist: if not callable(func): logger.error('Subscription function %r for event %s is ' 'not callable.' % (funcname, title)) continue # invoke the subscription function func(event, content)
def _eventPlainTextDelegator(self, obj, name, subclass=None, content=None): # determine the subscription function name funcname = utils.eventname2funcname(name, subclass=subclass) # get the function, if it exists subscription_func = getattr(self, funcname, None) # construct an informative event title title = name if subclass: title = ' '.join([title, subclass]) # if the function is not usable for any reason, log about it if not subscription_func: logger.error('Subscription function %r not defined for ' 'event %s.' % (funcname, title)) return if not callable(subscription_func): logger.error('Subscription function %r for event %s is not ' 'callable.' % (funcname, title)) return # invoke the subscription function subscription_func(obj, content)