'handles the jmespath query for injection or printing'

def handle_jmespath_query(self, args, continue_flag):

    if hasattr(self.last.result, u'__dict__'):
        input_dict = dict(self.last.result)
    else:
        input_dict = self.last.result
    try:
        queries = []
        results = []
        injected_command = []
        for arg in args:
            if arg.startswith(SELECT_SYMBOL[u'query']):
                query = arg[len(SELECT_SYMBOL[u'query']):]
                queries.append(query)
                results.append(jmespath.search(query, input_dict))
                injected_command.append(SELECT_SYMBOL[u'query'])
            elif (re.search((u'\\-.*\\=\\%s.*' % SELECT_SYMBOL[u'query']), arg) is not None):
                parition = arg.partition(SELECT_SYMBOL[u'query'])
                base = parition[0]
                query = parition[2]
                queries.append(query)
                results.append(jmespath.search(query, input_dict))
                injected_command.append((base + SELECT_SYMBOL[u'query']))
            else:
                injected_command.append(arg)
        if ((len(args) > 0) and args[0].startswith(SELECT_SYMBOL[u'query'])):
            print(json.dumps(results[0], sort_keys=True, indent=2), file=self.output)
            continue_flag = True
        else:
            cmd_base = u'    '.join(injected_command)
            if all((isinstance(result, (six.text_type, six.string_types)) for result in results)):
                for result in results:
                    cmd_base = cmd_base.replace(SELECT_SYMBOL[u'query'], result, 1)
                self.cli_execute(cmd_base)
                continue_flag = True
            elif all((isinstance(result, list) for result in results)):
                if (len(results) > 1):
                    for (res_counter, _) in enumerate(results[0]):
                        base = cmd_base
                        skip = False
                        for counter in range(cmd_base.count(SELECT_SYMBOL[u'query'])):
                            if ((counter < len(results)) and (res_counter < len(results[counter]))):
                                try:
                                    base = base.replace(SELECT_SYMBOL[u'query'], results[counter][res_counter], 1)
                                except TypeError:
                                    pass
                            else:
                                skip = True
                        if (not skip):
                            self.cli_execute(base)
                else:
                    for (res_counter, _) in enumerate(results[0]):
                        base = cmd_base
                        skip = False
                        for counter in range(cmd_base.count(SELECT_SYMBOL[u'query'])):
                            if ((counter < len(results)) and (res_counter < len(results[counter]))):
                                try:
                                    base = base.replace(SELECT_SYMBOL[u'query'], results[counter][res_counter], 1)
                                except TypeError:
                                    pass
                            else:
                                skip = True
                        if (not skip):
                            self.cli_execute(base)
                continue_flag = True
    except (jmespath.exceptions.ParseError, CLIError):
        print(u'Invalid    Query', file=self.output)
        continue_flag = True
    return continue_flag
