logilab.common.ureports package

Submodules

logilab.common.ureports.docbook_writer module

HTML formatting drivers for ureports

class logilab.common.ureports.docbook_writer.DocbookWriter(snippet: Optional[int] = None)[source]

Bases: HTMLWriter

format layouts as HTML

begin_format(layout)[source]

begin to format a layout

end_format(layout)[source]

finished to format a layout

display links (using <ulink>)

visit_list(layout)[source]

display a list (using <itemizedlist>)

visit_paragraph(layout)[source]

display links (using <para>)

visit_section(layout)[source]

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

visit_span(layout)[source]

display links (using <p>)

visit_table(layout)[source]

display a table as html

visit_text(layout)[source]

add some text

visit_title(layout)[source]

display a title using <title>

visit_verbatimtext(layout)[source]

display verbatim text (using <programlisting>)

logilab.common.ureports.html_writer module

HTML formatting drivers for ureports

class logilab.common.ureports.html_writer.HTMLWriter(snippet: Optional[int] = None)[source]

Bases: BaseWriter

format layouts as HTML

begin_format(layout: Any) None[source]

begin to format a layout

end_format(layout: Any) None[source]

finished to format a layout

handle_attrs(layout: Any) str[source]

get an attribute string from layout member attributes

display links (using <a>)

visit_list(layout: List) None[source]

display a list as html

visit_paragraph(layout: Paragraph) None[source]

display links (using <p>)

visit_section(layout: Section) None[source]

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

visit_span(layout)[source]

display links (using <p>)

visit_table(layout: Table) None[source]

display a table as html

visit_text(layout: Text) None[source]

add some text

visit_title(layout: Title) None[source]

display a title using <hX>

visit_verbatimtext(layout: VerbatimText) None[source]

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: Optional[str] = None, klass: Optional[str] = None)[source]

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: Union[List[Text], Tuple[Union[Paragraph, str], Union[List, str]], Tuple[str, ...]] = (), **kwargs: Any)[source]

Bases: BaseComponent

base container node

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

add_text(text: str) None[source]

shortcut to add text data

append(child: Any) None[source]

overridden to detect problems easily

parents() List[source]

return the ancestor nodes

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

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

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: Union[List[Text], Tuple[Union[Paragraph, str], Union[List, str]], Tuple[str, ...]] = (), **kwargs: Any)[source]

Bases: BaseLayout

some list data

attributes : * BaseLayout attributes

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

Bases: BaseLayout

a simple text paragraph

attributes : * BaseLayout attributes

A paragraph must not contains a section !

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

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: Union[List[Text], Tuple[Union[Paragraph, str], Union[List, str]], Tuple[str, ...]] = (), **kwargs: Any)[source]

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: Optional[Any] = None, rheaders: int = 0, cheaders: int = 0, rrheaders: int = 0, rcheaders: int = 0, **kwargs: Any)[source]

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)[source]

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: Union[List[Text], Tuple[Union[Paragraph, str], Union[List, str]], Tuple[str, ...]] = (), **kwargs: Any)[source]

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)[source]

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[source]

Bases: BaseWriter

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

begin_format(layout: Any) None[source]

begin to format a layout

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

format a table

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

special case for field table

add a hyperlink

visit_list(layout: List) None[source]

display a list layout as text

visit_paragraph(layout: Paragraph) None[source]

enter a paragraph

visit_section(layout: Section) None[source]

display a section as text

visit_span(layout)[source]

enter a span

visit_table(layout: Table) None[source]

display a table as text

visit_text(layout: Text) None[source]

add some text

visit_title(layout: Title) None[source]
visit_verbatimtext(layout: VerbatimText) None[source]

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[source]

Bases: object

base class for ureport writers

begin_format(layout: Any) None[source]

begin to format a layout

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

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[source]

finished to format a layout

format(layout: Any, stream: Optional[Union[StringIO, TextIO]] = None, encoding: Optional[Any] = None) None[source]

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: Union[Paragraph, Section, Title]) None[source]

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

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

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[source]

write a string in the output buffer

writeln(string: str = '') None[source]

write a line in the output buffer

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

make a summary for the report, including X level

logilab.common.ureports.get_nodes(node, klass)[source]

return an iterator on all children node of the given klass

logilab.common.ureports.layout_title(layout)[source]

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