Ejemplo n.º 1
0
def _object(o: edgedb.Object, repl_ctx: context.ReplContext,
            buf: terminal.Buffer) -> None:
    with buf.foldable_lines():
        buf.write(_object_name(o, repl_ctx), style.tree_node)
        buf.write(' {', style.tree_node)
        buf.folded_space()
        with buf.indent():
            non_empty = _object_guts(o,
                                     repl_ctx,
                                     buf,
                                     include_id_when_empty=True)
        if non_empty:
            buf.folded_space()
        buf.write('}', style.tree_node)
Ejemplo n.º 2
0
def _link(
    o: edgedb.Link,
    repl_ctx: context.ReplContext,
    buf: terminal.Buffer,
) -> None:
    with buf.foldable_lines():
        buf.write(_object_name(o.target, repl_ctx), style.tree_node)
        buf.write(' {', style.tree_node)
        buf.folded_space()
        with buf.indent():
            pointers = o.__dir__()
            pointers = tuple(ptr for ptr in pointers
                             if ptr not in {'source', 'target'})
            pointers_len = len(pointers)

            non_empty = _object_guts(o.target,
                                     repl_ctx,
                                     buf,
                                     include_id_when_empty=pointers_len == 0)

            if pointers_len > 0:
                if non_empty:
                    buf.write(',')
                    buf.mark_line_break()

                i = 0
                for name in pointers:
                    val = getattr(o, name)

                    buf.write(f'@{name}', style.code_tag)
                    buf.write(': ')
                    walk(val, repl_ctx, buf)
                    non_empty = True

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

        if non_empty:
            buf.folded_space()
        buf.write('}', style.tree_node)