

def handle_event(self, event, event_params):

    def get_parameter(param_name):
        parameter = event_params.get(param_name)
        if (parameter is None):
            raise Exception("Parameter '{param_name}' required in localization is missing from event!".format(param_name=param_name))
        if (type(parameter) == unicode):
            parameter = parameter.encode('utf-8')
        return parameter

    def get_parameter_map(parametrized_text):
        parameter_names = [key.group(0).strip('{}') for key in PARAM_REGEX.finditer(parametrized_text)]
        parameter_map = {param_name: get_parameter(param_name) for param_name in parameter_names}
        return parameter_map
    raw_messages = []
    if (self.event_id == event.event_id):
        for message_id in self.message_ids:
            try:
                localized_message = database.get_localized_message(event.user_id, message_id)
                text_parameter_map = get_parameter_map(localized_message.message_text)
                title_parameter_map = get_parameter_map(localized_message.message_title)
                if (localized_message is not None):
                    raw_messages.extend(database.get_raw_messages(login_id=event.user_id, title=localized_message.message_title.format(**title_parameter_map), content=localized_message.message_text.format(**text_parameter_map), screen=localized_message.message.screen, game=config.game, world_id=config.world_id, dry_run=config.dry_run, message_id=message_id))
                else:
                    context.main_logger.debug('Cannot get localization for user {login_id}'.format(login_id=event.user_id))
            except:
                context.main_logger.exception('Problem with preparing message (message_id={message_id})'.format(message_id=message_id))
    else:
        context.main_logger.error('EventToMessagesHandler can handle event_id {handled_id} but got {passed_id}'.format(handled_id=self.event_id, passed_id=event.event_id))
    return raw_messages

dataset/ETHPy150Open Nordeus/pushkin/pushkin/request/event_handlers.py EventToMessagesHandler.handle_event/original