def __call__(self, *args, **kwargs): name_to_find = self.func.__name__ logging.debug("All active plugin objects %s " % get_all_active_plugin_objects()) for ( obj ) in ( get_all_active_plugin_objects() ): # horrible hack to find back the bound method from the unbound function the decorator was able to give us matching_members = getmembers(obj, self.method_filter) logging.debug("Matching members %s -> %s" % (obj, matching_members)) if matching_members: name, func = matching_members[0] if self.form_param: content = request.forms.get(self.form_param) if content is None: raise Exception( "Received a request on a webhook with a form_param defined, " "but that key ({}) is missing from the request.".format(self.form_param) ) try: content = loads(content) except ValueError: logging.debug("The form parameter is not JSON, return it as a string") response = func(content, **kwargs) else: data = try_decode_json(request) if not data: if hasattr(request, "forms"): data = dict(request.forms) # form encoded else: data = request.body.read().decode() response = func(data, **kwargs) return response if response else "" # assume None as an OK response (simplifies the client side) raise Exception("Problem finding back the correct Handler for func %s" % name_to_find)
def dispatch_request(self, *args, **kwargs): name_to_find = self.func.__name__ for obj in get_all_active_plugin_objects( ): # horrible hack to find back the bound method from the unbound function the decorator was able to give us matching_members = getmembers(obj, self.method_filter) if matching_members: name, func = matching_members[0] if self.form_param: content = request.form[self.form_param] try: content = loads(content) except ValueError: logging.debug( 'The form parameter is not JSON, return it as a string' ) response = func(content, **kwargs) else: data = request.json if request.json else request.data # flask will find out automagically if it is a JSON structure response = func( data if data else request.form, **kwargs ) # or it will magically parse a form so adapt for our users return response if response else OK # assume None as an OK response (simplifies the client side) raise Exception('Problem finding back the correct Handler for func %s', name_to_find)
def dispatch_request(self, *args, **kwargs): name_to_find = self.func.__name__ for ( obj ) in ( get_all_active_plugin_objects() ): # horrible hack to find back the bound method from the unbound function the decorator was able to give us matching_members = getmembers(obj, self.method_filter) if matching_members: name, func = matching_members[0] if self.form_param: content = request.form[self.form_param] try: content = loads(content) except ValueError: logging.debug("The form parameter is not JSON, return it as a string") response = func(content, **kwargs) else: data = ( request.json if request.json else request.data ) # flask will find out automagically if it is a JSON structure response = func( data if data else request.form, **kwargs ) # or it will magically parse a form so adapt for our users return response if response else OK # assume None as an OK response (simplifies the client side) raise Exception("Problem finding back the correct Handler for func %s", name_to_find)
def signal_connect_to_all_plugins(self): for bot in get_all_active_plugin_objects(): if hasattr(bot, "callback_connect"): try: bot.callback_connect() except Exception as e: logging.exception("callback_connect failed for %s" % bot)
def signal_connect_to_all_plugins(self): for bot in get_all_active_plugin_objects(): if hasattr(bot, 'callback_connect'): try: bot.callback_connect() except Exception as e: logging.exception("callback_connect failed for %s" % bot)
def send_message(self, mess): super(ErrBot, self).send_message(mess) for bot in get_all_active_plugin_objects(): # noinspection PyBroadException try: bot.callback_botmessage(mess) except Exception as _: logging.exception("Crash in a callback_botmessage handler")
def signal_connect_to_all_plugins(self): for bot in get_all_active_plugin_objects(): if hasattr(bot, 'callback_connect'): #noinspection PyBroadException try: bot.callback_connect() except Exception as _: logging.exception("callback_connect failed for %s" % bot)
def callback_message(self, conn, mess): if super(ErrBot, self).callback_message(conn, mess): # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): try: bot.callback_message(conn, mess) except Exception: logging.exception("Crash in a callback_message handler")
def callback_presence(self, pres): for bot in get_all_active_plugin_objects(): # noinspection PyBroadException try: logging.debug('callback_presence for %s with %s' % (bot.__class__.__name__, pres)) bot.callback_presence(pres) except Exception as _: logging.exception('Crash in the callback_presence handler.')
def callback_message(self, conn, mess): super(ErrBot, self).callback_message(conn, mess) for bot in get_all_active_plugin_objects(): if hasattr(bot, 'callback_message'): try: bot.callback_message(conn, mess) except: logging.exception("Probably a type error")
def send_message(self, mess): super(ErrBot, self).send_message(mess) for bot in get_all_active_plugin_objects(): # noinspection PyBroadException try: bot.callback_botmessage(mess) except Exception as _: logging.exception("Crash in a callback_botmessage handler")
def callback_user_left_chat(self, conn, pres): for bot in get_all_active_plugin_objects(): #noinspection PyBroadException try: logging.debug('Callback %s' % bot) bot.callback_user_left_chat(conn, pres) except Exception as _: logging.exception('Crash in the callback_user_left_chat handler.')
def callback_user_left_chat(self, conn, pres): for bot in get_all_active_plugin_objects(): #noinspection PyBroadException try: logging.debug('Callback %s' % bot) bot.callback_user_left_chat(conn, pres) except Exception as _: logging.exception('Crash in the callback_user_left_chat handler.')
def callback_message(self, conn, mess): if super(ErrBot, self).callback_message(conn, mess): # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): try: bot.callback_message(conn, mess) except Exception: logging.exception("Crash in a callback_message handler")
def signal_connect_to_all_plugins(self): for bot in get_all_active_plugin_objects(): if hasattr(bot, 'callback_connect'): # noinspection PyBroadException try: logging.debug('Callback %s' % bot) bot.callback_connect() except Exception as _: logging.exception("callback_connect failed for %s" % bot)
def send_message(self, mess): super(ErrBot, self).send_message(mess) # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): # noinspection PyBroadException try: bot.callback_botmessage(mess) except Exception as _: logging.exception("Crash in a callback_botmessage handler")
def send_message(self, mess): super(ErrBot, self).send_message(mess) # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): #noinspection PyBroadException try: bot.callback_botmessage(mess) except Exception as _: logging.exception("Crash in a callback_botmessage handler")
def callback_message(self, conn, mess): if super(ErrBot, self).callback_message(conn, mess): # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): #noinspection PyBroadException try: logging.debug('Callback %s' % bot) bot.callback_message(conn, mess) except Exception as _: logging.exception("Crash in a callback_message handler")
def callback_message(self, conn, mess): if super(ErrBot, self).callback_message(conn, mess): # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): #noinspection PyBroadException try: logging.debug('Callback %s' % bot) bot.callback_message(conn, mess) except Exception as _: logging.exception("Crash in a callback_message handler")
def __call__(self, *args, **kwargs): name_to_find = self.func.__name__ logging.debug('All active plugin objects %s ' % get_all_active_plugin_objects()) # Horrible hack to find the bound method from the unbound function the decorator # was able to give us: for obj in get_all_active_plugin_objects(): matching_members = getmembers(obj, self.method_filter) logging.debug('Matching members %s -> %s' % (obj, matching_members)) if matching_members: name, func = matching_members[0] if self.raw: # override and gives the request directly response = func(request, **kwargs) elif self.form_param: content = request.forms.get(self.form_param) if content is None: raise Exception( "Received a request on a webhook with a form_param defined, " "but that key ({}) is missing from the request.". format(self.form_param)) try: content = loads(content) except ValueError: logging.debug( 'The form parameter is not JSON, return it as a string' ) response = func(content, **kwargs) else: data = try_decode_json(request) if not data: if hasattr(request, 'forms'): data = dict(request.forms) # form encoded else: data = request.body.read().decode() response = func(data, **kwargs) return response if response else '' # assume None as an OK response (simplifies the client side) raise Exception( 'Problem finding back the correct Handler for func %s' % name_to_find)
def callback_message(self, conn, mess): # Ignore messages from myself if self.jid.bareMatch(get_jid_from_message(mess)): logging.debug('Ignore a message from myself') return super(ErrBot, self).callback_message(conn, mess) for bot in get_all_active_plugin_objects(): if hasattr(bot, 'callback_message'): try: bot.callback_message(conn, mess) except: logging.exception("Probably a type error")
def dispatch_request(self): for obj in get_all_active_plugin_objects(): # horrible hack to find back the bound method from the unbound function the decorator was able to give us for name, method in getmembers(obj, ismethod): if method.im_func.__name__ == self.func.__name__: # FIXME : add a fully qualified name here if self.form_param: content = request.form[self.form_param] try: content = simplejson.loads(content) except JSONDecodeError: logging.debug('The form parameter is not JSON, return it as a string') response = self.func(obj, content) else: response = self.func(obj, request.json if request.json else request.data) # flask will find out automagically if it is a JSON structure return response if response else OK # assume None as an OK response (simplifies the client side) raise Exception('Problem finding back the correct Handlerfor func %s', self.func)
def callback_message(self, mess): if super(ErrBot, self).callback_message(mess): # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): # noinspection PyBroadException try: logging.debug('callback_message for %s' % bot.__class__.__name__) # backward compatibility from the time we needed conn if len(inspect.getargspec(bot.callback_message).args) == 3: logging.warn('Deprecation: Plugin %s uses the old callback_message convention, ' 'now the signature should be simply def callback_message(self, mess)' % bot.__class__.__name__) bot.callback_message(None, mess) else: bot.callback_message(mess) except Exception as _: logging.exception("Crash in a callback_message handler")
def _dispatch_to_plugins(method, *args, **kwargs): """ Dispatch the given method to all active plugins. Will catch and log any exceptions that occur. :param method: The name of the function to dispatch. :param *args: Passed to the callback function. :param **kwargs: Passed to the callback function. """ for plugin in get_all_active_plugin_objects(): plugin_name = plugin.__class__.__name__ logging.debug("Triggering {} on {}".format(method, plugin_name)) # noinspection PyBroadException try: getattr(plugin, method)(*args, **kwargs) except Exception as _: logging.exception("{} on {} crashed".format(method, plugin_name))
def _dispatch_to_plugins(method, *args, **kwargs): """ Dispatch the given method to all active plugins. Will catch and log any exceptions that occur. :param method: The name of the function to dispatch. :param *args: Passed to the callback function. :param **kwargs: Passed to the callback function. """ for plugin in get_all_active_plugin_objects(): plugin_name = plugin.__class__.__name__ logging.debug("Triggering {} on {}".format(method, plugin_name)) # noinspection PyBroadException try: getattr(plugin, method)(*args, **kwargs) except Exception as _: logging.exception("{} on {} crashed".format( method, plugin_name))
def callback_message(self, mess): if super(ErrBot, self).callback_message(mess): # Act only in the backend tells us that this message is OK to broadcast for bot in get_all_active_plugin_objects(): # noinspection PyBroadException try: logging.debug('callback_message for %s' % bot.__class__.__name__) # backward compatibility from the time we needed conn if len(inspect.getargspec(bot.callback_message).args) == 3: logging.warning( 'Deprecation: Plugin %s uses the old callback_message convention, ' 'now the signature should be simply def callback_message(self, mess)' % bot.__class__.__name__) bot.callback_message(None, mess) else: bot.callback_message(mess) except Exception as _: logging.exception("Crash in a callback_message handler")
def callback_stream(self, stream): logging.info("Initiated an incoming transfer %s" % stream) Tee(stream, get_all_active_plugin_objects()).start()
def callback_stream(self, stream): logging.info("Initiated an incoming transfer %s" % stream) Tee(stream, get_all_active_plugin_objects()).start()