# logilab.common.ureports package

## Submodules

## logilab.common.ureports.docbook_writer module

HTML formatting drivers for ureports

class logilab.common.ureports.docbook_writer.DocbookWriter(snippet: int = None)

  Bases: `HTMLWriter`

  format layouts as HTML

  begin_format(layout)

    begin to format a layout

  end_format(layout)

    finished to format a layout

  visit_link(layout)

    display links (using <ulink>)

  visit_list(layout)

    display a list (using <itemizedlist>)

  visit_paragraph(layout)

    display links (using <para>)

  visit_section(layout)

    display a section (using <chapter> (level 0) or <section>)

  visit_span(layout)

    display links (using <p>)

  visit_table(layout)

    display a table as html

  visit_text(layout)

    add some text

  visit_title(layout)

    display a title using <title>

  visit_verbatimtext(layout)

    display verbatim text (using <programlisting>)

## logilab.common.ureports.html_writer module

HTML formatting drivers for ureports

class logilab.common.ureports.html_writer.HTMLWriter(snippet: int = None)

  Bases: `BaseWriter`

  format layouts as HTML

  begin_format(layout: Any) → None

    begin to format a layout

  end_format(layout: Any) → None

    finished to format a layout

  handle_attrs(layout: Any) → str

    get an attribute string from layout member attributes

  visit_link(layout: Link) → None

    display links (using <a>)

  visit_list(layout: List) → None

    display a list as html

  visit_paragraph(layout: Paragraph) → None

    display links (using <p>)

  visit_section(layout: Section) → None

    display a section as html, using div + h[section level]

  visit_span(layout)

    display links (using <p>)

  visit_table(layout: Table) → None

    display a table as html

  visit_text(layout: Text) → None

    add some text

  visit_title(layout: Title) → None

    display a title using <hX>

  visit_verbatimtext(layout: VerbatimText) → None

    display verbatim text (using <pre>)

## logilab.common.ureports.nodes module

Micro reports objects.

A micro report is a tree of layout and content objects.

class logilab.common.ureports.nodes.BaseComponent(id: str | None = None, klass: str | None = None)

  Bases: `VNode`

  base report component

  attributes * id : the component’s optional id * klass : the component’s optional klass

class logilab.common.ureports.nodes.BaseLayout(children: List[Text] | Tuple[Paragraph | str, List | str] | Tuple[str, ...] = (), **kwargs: Any)

  Bases: `BaseComponent`

  base container node

  attributes * BaseComponent attributes * children : components in this table (i.e. the table’s cells)

  add_text(text: str) → None

    shortcut to add text data

  append(child: Any) → None

    overridden to detect problems easily

  parents() → List

    return the ancestor nodes

class logilab.common.ureports.nodes.Image(filename, stream, title=None, **kwargs)

  Bases: `BaseComponent`

  an embedded or a single image

  attributes : * BaseComponent attributes * filename : the image’s filename (REQUIRED) * stream : the stream object containing the image data (REQUIRED) * title : the image’s optional title

class logilab.common.ureports.nodes.Link(url: str, label: str = None, **kwargs: Any)

  Bases: `BaseComponent`

  a labelled link

  attributes : * BaseComponent attributes * url : the link’s target (REQUIRED) * label : the link’s label as a string (use the url by default)

class logilab.common.ureports.nodes.List(children: List[Text] | Tuple[Paragraph | str, List | str] | Tuple[str, ...] = (), **kwargs: Any)

  Bases: `BaseLayout`

  some list data

  attributes : * BaseLayout attributes

class logilab.common.ureports.nodes.Paragraph(children: List[Text] | Tuple[Paragraph | str, List | str] | Tuple[str, ...] = (), **kwargs: Any)

  Bases: `BaseLayout`

  a simple text paragraph

  attributes : * BaseLayout attributes

  A paragraph must not contains a section !

class logilab.common.ureports.nodes.Section(title: str = None, description: str = None, **kwargs: Any)

  Bases: `BaseLayout`

  a section

  attributes : * BaseLayout attributes

  a title may also be given to the constructor, it’ll be added as a first element a description may also be given to the constructor, it’ll be added as a first paragraph

class logilab.common.ureports.nodes.Span(children: List[Text] | Tuple[Paragraph | str, List | str] | Tuple[str, ...] = (), **kwargs: Any)

  Bases: `BaseLayout`

  a title

  attributes : * BaseLayout attributes

  A span should only contains Text and Link nodes (in-line elements)

class logilab.common.ureports.nodes.Table(cols: int, title: Any | None = None, rheaders: int = 0, cheaders: int = 0, rrheaders: int = 0, rcheaders: int = 0, **kwargs: Any)

  Bases: `BaseLayout`

  some tabular data

  attributes : * BaseLayout attributes * cols : the number of columns of the table (REQUIRED) * rheaders : the first row’s elements are table’s header * cheaders : the first col’s elements are table’s header * title : the table’s optional title

class logilab.common.ureports.nodes.Text(data: str, escaped: bool = True, **kwargs: Any)

  Bases: `BaseComponent`

  a text portion

  attributes : * BaseComponent attributes * data : the text value as an encoded or unicode string

class logilab.common.ureports.nodes.Title(children: List[Text] | Tuple[Paragraph | str, List | str] | Tuple[str, ...] = (), **kwargs: Any)

  Bases: `BaseLayout`

  a title

  attributes : * BaseLayout attributes

  A title must not contains a section nor a paragraph!

class logilab.common.ureports.nodes.VerbatimText(data: str, escaped: bool = True, **kwargs: Any)

  Bases: `Text`

  a verbatim text, display the raw data

  attributes : * BaseComponent attributes * data : the text value as an encoded or unicode string

## logilab.common.ureports.text_writer module

Text formatting drivers for ureports

class logilab.common.ureports.text_writer.TextWriter

  Bases: `BaseWriter`

  format layouts as text (ReStructured inspiration but not totally handled yet)

  begin_format(layout: Any) → None

    begin to format a layout

  default_table(layout: Table, table_content: List[List[str]], cols_width: List[int]) → None

    format a table

  field_table(layout: Table, table_content: List[List[str]], cols_width: List[int]) → None

    special case for field table

  visit_link(layout: Link) → None

    add a hyperlink

  visit_list(layout: List) → None

    display a list layout as text

  visit_paragraph(layout: Paragraph) → None

    enter a paragraph

  visit_section(layout: Section) → None

    display a section as text

  visit_span(layout)

    enter a span

  visit_table(layout: Table) → None

    display a table as text

  visit_text(layout: Text) → None

    add some text

  visit_title(layout: Title) → None
  visit_verbatimtext(layout: VerbatimText) → None

    display a verbatim layout as text (so difficult ;)

## Module contents

Universal report objects and some formatting drivers.

A way to create simple reports using python objects, primarily designed to be formatted as text and html.

class logilab.common.ureports.BaseWriter

  Bases: `object`

  base class for ureport writers

  begin_format(layout: Any) → None

    begin to format a layout

  compute_content(layout: VNode) → Generator[str, Any, None]

    trick to compute the formatting of children layout before actually writing it

    return an iterator on strings (one for each child element)

  end_format(layout: Any) → None

    finished to format a layout

  format(layout: Any, stream: StringIO | TextIO | None = None, encoding: Any | None = None) → None

    format and write the given layout into the stream object

    unicode policy: unicode strings may be found in the layout; try to call stream.write with it, but give it back encoded using the given encoding if it fails

  format_children(layout: Paragraph | Section | Title) → None

    recurse on the layout children and call their accept method (see the Visitor pattern)

  get_table_content(table: Table) → List[List[str]]

    trick to get table content without actually writing it

    return an aligned list of lists containing table cells values as string

  write(string: str) → None

    write a string in the output buffer

  writeln(string: str = '') → None

    write a line in the output buffer

logilab.common.ureports.build_summary(layout, level=1)

  make a summary for the report, including X level

logilab.common.ureports.get_nodes(node, klass)

  return an iterator on all children node of the given klass

logilab.common.ureports.layout_title(layout)

  try to return the layout’s title as string, return None if not found