def _ask()

in source/idea/idea-sdk/src/ideasdk/user_input/framework.py [0:0]


    def _ask(self, question: Optional[Union[List[Dict], Dict]]) -> Optional[T]:
        questions = []
        try:
            if question is None:
                return None

            if isinstance(question, List):
                questions += question
            else:
                questions += [question]

            for question in questions:
                question_type = Utils.get_value_as_string('type', question)

                if 'qmark' in question:
                    qmark = question['qmark']
                    if qmark != '?':
                        question['qmark'] = f'{qmark}'

                if 'filter' not in question:
                    question['filter'] = self.get_filter()

                if 'name' not in question:
                    question['name'] = self.name

                if question_type == 'select' and 'style' not in question:
                    question['style'] = DEFAULT_SELECT_STYLE

                if question_type == 'checkbox':
                    # checkbox defaults are handled using choice.checked
                    del question['default']

                if 'instruction' in question:
                    if question_type in ('path', 'confirm', 'checkbox'):
                        # instruction is not supported by questionary for: path, confirm
                        message = question['message']
                        instruction = Utils.get_value_as_string('instruction', question)
                        if not Utils.is_empty(instruction):
                            message += f' {instruction}'
                            question['message'] = message
                        del question['instruction']

                if question_type == 'text' and Utils.get_value_as_bool('multiline', question, False):
                    instruction = Utils.get_value_as_string('instruction', question)
                    exit_note = 'Alt+Enter to exit'
                    if Utils.is_empty(instruction):
                        message = f'({exit_note})'
                    else:
                        if instruction.startswith('(') and instruction.endswith(')'):
                            message = instruction[1:-1]
                        else:
                            message = instruction
                        message = f'({message} | ${exit_note})'
                    question['instruction'] = message

                if question_type == 'path' and 'complete_style' not in question:
                    question['complete_style'] = DEFAULT_PATH_COMPLETE_STYLE

                if question_type in ('text', 'password', 'path') and 'default' in question:
                    default_val = question.get('default')
                    if default_val is None:
                        question['default'] = ''
                    elif not isinstance(default_val, str):
                        if isinstance(default_val, list):
                            entries = default_val
                            default_values = ''
                            for entry in entries:
                                default_values = f'{default_values},{entry}'
                            question['default'] = default_values.strip(',')
                        else:
                            question['default'] = str(default_val)

            result = unsafe_prompt(questions=questions)
            return Utils.get_any_value(self.name, result)

        except KeyboardInterrupt:
            raise exceptions.soca_exception(
                error_code=errorcodes.USER_INPUT_FLOW_INTERRUPT,
                message='',
                ref=self
            )
        except Exception as e:
            if isinstance(e, exceptions.SocaException):
                raise e
            else:
                question_debug_str = ''
                for question in questions:
                    question_name = Utils.get_value_as_string('name', question)
                    question_type = Utils.get_value_as_string('type', question)
                    question_debug_str = f'Name: {question_name}, Type: {question_type}'
                    break

                raise exceptions.soca_exception(
                    error_code=errorcodes.GENERAL_ERROR,
                    message=f'Unhandled exception occurred while processing the question: {question_debug_str}',
                    ref=e
                )