MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / _repr_obj

Method _repr_obj

_pydevd_bundle/pydevd_safe_repr.py:323–366  ·  view source on GitHub ↗
(self, obj, level, limit_inner, limit_outer)

Source from the content-addressed store, hash-verified

321 return self._repr_obj(obj, level, self.maxother_inner, self.maxother_outer)
322
323 def _repr_obj(self, obj, level, limit_inner, limit_outer):
324 try:
325 if self.raw_value:
326 # For raw value retrieval, ignore all limits.
327 if isinstance(obj, bytes):
328 yield obj.decode("latin-1")
329 return
330
331 try:
332 mv = memoryview(obj)
333 except Exception:
334 yield self._convert_to_unicode_or_bytes_repr(repr(obj))
335 return
336 else:
337 # Map bytes to Unicode codepoints with same values.
338 yield mv.tobytes().decode("latin-1")
339 return
340 elif self.convert_to_hex and isinstance(obj, self.int_types):
341 obj_repr = hex(obj)
342 else:
343 obj_repr = repr(obj)
344 except Exception:
345 try:
346 obj_repr = object.__repr__(obj)
347 except Exception:
348 try:
349 obj_repr = "<no repr available for " + type(obj).__name__ + ">" # noqa
350 except Exception:
351 obj_repr = "<no repr available for object>"
352
353 limit = limit_inner if level > 0 else limit_outer
354
355 if limit >= len(obj_repr):
356 yield self._convert_to_unicode_or_bytes_repr(obj_repr)
357 return
358
359 # Slightly imprecise calculations - we may end up with a string that is
360 # up to 3 characters longer than limit. If you need precise formatting,
361 # you are using the wrong class.
362 left_count, right_count = max(1, int(2 * limit / 3)), max(1, int(limit / 3)) # noqa
363
364 yield obj_repr[:left_count]
365 yield "..."
366 yield obj_repr[-right_count:]
367
368 def _convert_to_unicode_or_bytes_repr(self, obj_repr):
369 return obj_repr

Callers 2

_repr_strMethod · 0.95
_repr_otherMethod · 0.95

Calls 3

decodeMethod · 0.45
__repr__Method · 0.45

Tested by

no test coverage detected