Esempio n. 1
0
    def get_var_data(self, fmt=None, **safe_repr_custom_attrs):
        '''
        :param dict fmt:
            Format expected by the DAP (keys: 'hex': bool, 'rawString': bool)
        '''
        timer = Timer()
        safe_repr = SafeRepr()
        if fmt is not None:
            safe_repr.convert_to_hex = fmt.get('hex', False)
            safe_repr.raw_value = fmt.get('rawString', False)
        for key, val in safe_repr_custom_attrs.items():
            setattr(safe_repr, key, val)

        type_name, _type_qualifier, _is_exception_on_eval, resolver, value = get_variable_details(
            self.value, to_string=safe_repr)

        is_raw_string = type_name in ('str', 'bytes', 'bytearray')

        attributes = []

        if is_raw_string:
            attributes.append('rawString')

        name = self.name

        if self._is_return_value:
            attributes.append('readOnly')
            name = '(return) %s' % (name, )

        elif name in (TOO_LARGE_ATTR, GENERATED_LEN_ATTR_NAME):
            attributes.append('readOnly')

        try:
            if self.value.__class__ == DAPGrouper:
                type_name = ''
        except:
            pass  # Ignore errors accessing __class__.

        var_data = {
            'name': name,
            'value': value,
            'type': type_name,
        }

        if self.evaluate_name is not None:
            var_data['evaluateName'] = self.evaluate_name

        if resolver is not None:  # I.e.: it's a container
            var_data['variablesReference'] = self.get_variable_reference()
        else:
            var_data[
                'variablesReference'] = 0  # It's mandatory (although if == 0 it doesn't have children).

        if len(attributes) > 0:
            var_data['presentationHint'] = {'attributes': attributes}

        timer.report_if_compute_repr_attr_slow('', name, type_name)
        return var_data
Esempio n. 2
0
def test_raw():
    safe_repr = SafeRepr()
    safe_repr.raw_value = True
    obj = b'\xed\xbd\xbf\xff\xfe\xfa\xfd'
    raw_value_repr = safe_repr(obj)
    assert isinstance(raw_value_repr, str)  # bytes on py2, str on py3
    if IS_PY2:
        assert raw_value_repr == obj.decode('latin1').encode('utf-8')
    else:
        assert raw_value_repr == obj.decode('latin1')
Esempio n. 3
0
def test_raw():
    safe_repr = SafeRepr()
    safe_repr.raw_value = True
    obj = b'\xed\xbd\xbf\xff\xfe\xfa\xfd'
    raw_value_repr = safe_repr(obj)
    assert isinstance(raw_value_repr, str)  # bytes on py2, str on py3
    if IS_PY2:
        assert raw_value_repr == obj.decode('latin1').encode('utf-8')
    else:
        assert raw_value_repr == obj.decode('latin1')
Esempio n. 4
0
    def get_var_data(self, fmt=None):
        '''
        :param dict fmt:
            Format expected by the DAP (keys: 'hex': bool, 'rawString': bool)
        '''
        safe_repr = SafeRepr()
        if fmt is not None:
            safe_repr.convert_to_hex = fmt.get('hex', False)
            safe_repr.raw_value = fmt.get('rawString', False)

        type_name, _type_qualifier, _is_exception_on_eval, resolver, value = get_variable_details(
            self.value, to_string=safe_repr)

        is_raw_string = type_name in ('str', 'unicode', 'bytes', 'bytearray')

        attributes = []

        if is_raw_string:
            attributes.append('rawString')

        name = self.name

        if self._is_return_value:
            attributes.append('readOnly')
            name = '(return) %s' % (name, )

        elif name in (TOO_LARGE_ATTR, '__len__'):
            attributes.append('readOnly')

        var_data = {
            'name': name,
            'value': value,
            'type': type_name,
        }

        if self.evaluate_name is not None:
            var_data['evaluateName'] = self.evaluate_name

        if resolver is not None:  # I.e.: it's a container
            var_data['variablesReference'] = self.get_variable_reference()
        else:
            var_data[
                'variablesReference'] = 0  # It's mandatory (although if == 0 it doesn't have children).

        if len(attributes) > 0:
            var_data['presentationHint'] = {'attributes': attributes}

        return var_data
    def get_var_data(self, fmt=None):
        '''
        :param dict fmt:
            Format expected by the DAP (keys: 'hex': bool, 'rawString': bool)
        '''
        safe_repr = SafeRepr()
        if fmt is not None:
            safe_repr.convert_to_hex = fmt.get('hex', False)
            safe_repr.raw_value = fmt.get('rawString', False)

        type_name, _type_qualifier, _is_exception_on_eval, resolver, value = get_variable_details(
            self.value, to_string=safe_repr)

        is_raw_string = type_name in ('str', 'unicode', 'bytes', 'bytearray')

        attributes = []

        if is_raw_string:
            attributes.append('rawString')

        name = self.name

        if self._is_return_value:
            attributes.append('readOnly')
            name = '(return) %s' % (name,)

        elif name in (TOO_LARGE_ATTR, '__len__'):
            attributes.append('readOnly')

        var_data = {
            'name': name,
            'value': value,
            'type': type_name,
        }

        if self.evaluate_name is not None:
            var_data['evaluateName'] = self.evaluate_name

        if resolver is not None:  # I.e.: it's a container
            var_data['variablesReference'] = self.get_variable_reference()
        else:
            var_data['variablesReference'] = 0  # It's mandatory (although if == 0 it doesn't have children).

        if len(attributes) > 0:
            var_data['presentationHint'] = {'attributes': attributes}

        return var_data