Esempio n. 1
0
def var_to_xml(val,
               name,
               trim_if_too_big=True,
               additional_in_xml='',
               evaluate_full_value=True):
    """ single variable or dictionary to xml representation """

    type_name, type_qualifier, is_exception_on_eval, resolver, value = get_variable_details(
        val, evaluate_full_value)

    scope = get_var_scope(name, val, '', True)
    try:
        name = quote(name, '/>_= ')  # TODO: Fix PY-5834 without using quote
    except:
        pass

    xml = '<var name="%s" type="%s" ' % (make_valid_xml_value(name),
                                         make_valid_xml_value(type_name))

    if type_qualifier:
        xml_qualifier = 'qualifier="%s"' % make_valid_xml_value(type_qualifier)
    else:
        xml_qualifier = ''

    if value:
        # cannot be too big... communication may not handle it.
        if len(value
               ) > MAXIMUM_VARIABLE_REPRESENTATION_SIZE and trim_if_too_big:
            value = value[0:MAXIMUM_VARIABLE_REPRESENTATION_SIZE]
            value += '...'

        xml_value = ' value="%s"' % (make_valid_xml_value(quote(
            value, '/>_= ')))
    else:
        xml_value = ''

    if is_exception_on_eval:
        xml_container = ' isErrorOnEval="True"'
    else:
        if resolver is not None:
            xml_container = ' isContainer="True"'
        else:
            xml_container = ''

    if scope:
        return ''.join((xml, xml_qualifier, xml_value, xml_container,
                        additional_in_xml, ' scope="', scope, '"', ' />\n'))
    else:
        return ''.join((xml, xml_qualifier, xml_value, xml_container,
                        additional_in_xml, ' />\n'))
    def _group_entries(self, lst, handle_return_values):
        scope_to_grouper = {}

        group_entries = []
        if isinstance(self.value, DAPGrouper):
            new_lst = lst
        else:
            new_lst = []
            get_presentation = self.py_db.variable_presentation.get_presentation
            # Now that we have the contents, group items.
            for attr_name, attr_value, evaluate_name in lst:
                scope = get_var_scope(attr_name, attr_value, evaluate_name,
                                      handle_return_values)

                entry = (attr_name, attr_value, evaluate_name)
                if scope:
                    presentation = get_presentation(scope)
                    if presentation == 'hide':
                        continue

                    elif presentation == 'inline':
                        new_lst.append(entry)

                    else:  # group
                        if scope not in scope_to_grouper:
                            grouper = DAPGrouper(scope)
                            scope_to_grouper[scope] = grouper
                        else:
                            grouper = scope_to_grouper[scope]

                        grouper.contents_debug_adapter_protocol.append(entry)

                else:
                    new_lst.append(entry)

            for scope in DAPGrouper.SCOPES_SORTED:
                grouper = scope_to_grouper.get(scope)
                if grouper is not None:
                    group_entries.append((scope, grouper, None))

        return new_lst, group_entries