def _get_default_var_string_representation(v, _type, typeName, format): try: str_from_provider = _str_from_providers(v, _type, typeName) if str_from_provider is not None: value = str_from_provider elif hasattr(v, '__class__'): if v.__class__ == frame_type: value = pydevd_resolver.frameResolver.get_frame_name(v) elif v.__class__ in (list, tuple): if len(v) > pydevd_resolver.MAX_ITEMS_TO_HANDLE: value = '%s' % take_first_n_coll_elements( v, pydevd_resolver.MAX_ITEMS_TO_HANDLE) value = value.rstrip(')]}') + '...' else: value = '%s' % str(v) else: value = format % v else: value = str(v) except: try: value = repr(v) except: value = 'Unable to get repr for %s' % v.__class__ return value
def var_to_xml(val, name, doTrim=True, additional_in_xml='', evaluate_full_value=True): """ single variable or dictionary to xml representation """ try: # This should be faster than isinstance (but we have to protect against not having a '__class__' attribute). is_exception_on_eval = val.__class__ == ExceptionOnEvaluate except: is_exception_on_eval = False if is_exception_on_eval: v = val.result else: v = val _type, typeName, resolver = get_type(v) type_qualifier = getattr(_type, "__module__", "") if not evaluate_full_value: value = DEFAULT_VALUES_DICT[LOAD_VALUES_POLICY] else: try: str_from_provider = _str_from_providers(v, _type, typeName) if str_from_provider is not None: value = str_from_provider elif hasattr(v, '__class__'): if v.__class__ == frame_type: value = pydevd_resolver.frameResolver.get_frame_name(v) elif v.__class__ in (list, tuple, set, frozenset, dict): if len(v) > pydevd_resolver.MAX_ITEMS_TO_HANDLE: value = '%s: %s' % ( str(v.__class__), take_first_n_coll_elements( v, pydevd_resolver.MAX_ITEMS_TO_HANDLE)) value = value.rstrip(')]}') + '...' else: value = '%s: %s' % (str(v.__class__), v) else: try: cName = str(v.__class__) if cName.find('.') != -1: cName = cName.split('.')[-1] elif cName.find( "'" ) != -1: # does not have '.' (could be something like <type 'int'>) cName = cName[cName.index("'") + 1:] if cName.endswith("'>"): cName = cName[:-2] except: cName = str(v.__class__) value = '%s: %s' % (cName, v) else: value = str(v) except: try: value = repr(v) except: value = 'Unable to get repr for %s' % v.__class__ 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(typeName)) 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 doTrim: value = value[0:MAXIMUM_VARIABLE_REPRESENTATION_SIZE] value += '...' # fix to work with unicode values try: if not IS_PY3K: if value.__class__ == unicode: # @UndefinedVariable value = value.encode('utf-8') else: if value.__class__ == bytes: value = value.encode('utf-8') except TypeError: # in java, unicode is a function pass xml_value = ' value="%s"' % (make_valid_xml_value(quote( value, '/>_= '))) else: xml_value = '' if is_numeric_container(typeName): xml_shape = ' shape="%s"' % make_valid_xml_value(str(v.shape)) else: xml_shape = '' if is_exception_on_eval: xml_container = ' isErrorOnEval="True"' else: if resolver is not None: xml_container = ' isContainer="True"' else: xml_container = '' return ''.join((xml, xml_qualifier, xml_value, xml_container, xml_shape, additional_in_xml, ' />\n'))
def var_to_struct(val, name, do_trim=True, evaluate_full_value=True): """ single variable or dictionary to Thrift struct representation """ debug_value = DebugValue() try: # This should be faster than isinstance (but we have to protect against not having a '__class__' attribute). is_exception_on_eval = val.__class__ == ExceptionOnEvaluate except: is_exception_on_eval = False if is_exception_on_eval: v = val.result else: v = val _type, typeName, resolver = get_type(v) type_qualifier = getattr(_type, "__module__", "") if not evaluate_full_value: value = DEFAULT_VALUES_DICT[LOAD_VALUES_POLICY] else: try: str_from_provider = _str_from_providers(v, _type, typeName) if str_from_provider is not None: value = str_from_provider elif hasattr(v, '__class__'): if v.__class__ == frame_type: value = pydevd_resolver.frameResolver.get_frame_name(v) elif v.__class__ in (list, tuple): if len(v) > pydevd_resolver.MAX_ITEMS_TO_HANDLE: value = '%s: %s' % ( str(v.__class__), take_first_n_coll_elements( v, pydevd_resolver.MAX_ITEMS_TO_HANDLE)) value = value.rstrip(')]}') + '...' else: value = '%s: %s' % (str(v.__class__, v)) else: value = str(v) else: value = str(v) except: try: value = repr(v) except: value = 'Unable to get repr for %s' % v.__class__ debug_value.name = name debug_value.type = typeName if type_qualifier: debug_value.qualifier = type_qualifier if value: # cannot be too big... communication may not handle it. if len(value) > MAXIMUM_VARIABLE_REPRESENTATION_SIZE and do_trim: value = value[0:MAXIMUM_VARIABLE_REPRESENTATION_SIZE] value += '...' # fix to work with unicode values try: if not IS_PY3K: if value.__class__ == unicode: # @UndefinedVariable value = value.encode('utf-8') else: if value.__class__ == bytes: value = value.encode('utf-8') except TypeError: # in java, unicode is a function pass debug_value.value = value if is_exception_on_eval: debug_value.isErrorOnEval = True else: if resolver is not None: debug_value.isContainer = True else: pass return debug_value
def var_to_xml(val, name, doTrim=True, additional_in_xml='', evaluate_full_value=True): """ single variable or dictionary to xml representation """ try: # This should be faster than isinstance (but we have to protect against not having a '__class__' attribute). is_exception_on_eval = val.__class__ == ExceptionOnEvaluate except: is_exception_on_eval = False if is_exception_on_eval: v = val.result else: v = val _type, typeName, resolver = get_type(v) type_qualifier = getattr(_type, "__module__", "") if not evaluate_full_value: value = DEFAULT_VALUES_DICT[LOAD_VALUES_POLICY] else: try: str_from_provider = _str_from_providers(v, _type, typeName) if str_from_provider is not None: value = str_from_provider elif hasattr(v, '__class__'): if v.__class__ == frame_type: value = pydevd_resolver.frameResolver.get_frame_name(v) elif v.__class__ in (list, tuple, set, frozenset, dict): if len(v) > pydevd_resolver.MAX_ITEMS_TO_HANDLE: value = '%s: %s' % (str(v.__class__), take_first_n_coll_elements( v, pydevd_resolver.MAX_ITEMS_TO_HANDLE)) value = value.rstrip(')]}') + '...' else: value = '%s: %s' % (str(v.__class__), v) else: try: cName = str(v.__class__) if cName.find('.') != -1: cName = cName.split('.')[-1] elif cName.find("'") != -1: # does not have '.' (could be something like <type 'int'>) cName = cName[cName.index("'") + 1:] if cName.endswith("'>"): cName = cName[:-2] except: cName = str(v.__class__) value = '%s: %s' % (cName, v) else: value = str(v) except: try: value = repr(v) except: value = 'Unable to get repr for %s' % v.__class__ 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(typeName)) 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 doTrim: value = value[0:MAXIMUM_VARIABLE_REPRESENTATION_SIZE] value += '...' # fix to work with unicode values try: if not IS_PY3K: if value.__class__ == unicode: # @UndefinedVariable value = value.encode('utf-8') else: if value.__class__ == bytes: value = value.encode('utf-8') except TypeError: # in java, unicode is a function pass 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 = '' return ''.join((xml, xml_qualifier, xml_value, xml_container, additional_in_xml, ' />\n'))