Beispiel #1
0
    def _object_guts(o, repl_ctx: context.ReplContext, buf, *,
                     include_id_when_empty: bool):
        pointers = introspect.introspect_object(o).pointers
        if not repl_ctx.show_implicit_fields:
            pointers = tuple(ptr for ptr in pointers if not ptr.implicit)
        pointers_len = len(pointers)

        pointers_rendered = 0
        for ptr in pointers:
            buf.write(ptr.name, style.key)
            buf.write(': ')

            if ptr.kind is introspect.PointerKind.LINK:
                link = o[ptr.name]
                BinaryRenderer.walk(link, repl_ctx, buf)
            else:
                val = getattr(o, ptr.name)
                BinaryRenderer.walk(val, repl_ctx, buf)

            pointers_rendered += 1
            if pointers_rendered < pointers_len:
                buf.write(',')
                buf.mark_line_break()

        if pointers_rendered == 0 and include_id_when_empty:
            buf.write('id', style.key)
            buf.write(': ')
            BinaryRenderer.walk(o.id, repl_ctx, buf)
            pointers_rendered = 1

        return pointers_rendered > 0
Beispiel #2
0
    def test_recorddesc_4(self):
        f = private.create_object_factory(
            id={'property', 'implicit'},
            lb='link-property',
            c='property',
            d='link',
        )

        o = f(1, 2, 3, 4)
        intro = introspect.introspect_object(o)

        self.assertEqual(intro.pointers, (
            ('id', introspect.PointerKind.PROPERTY, True),
            ('c', introspect.PointerKind.PROPERTY, False),
            ('d', introspect.PointerKind.LINK, False),
        ))

        # clear cache so that tests in refcount mode don't freak out.
        introspect._introspect_object_desc.cache_clear()