summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Spanti <nicola.spanti@logilab.fr>2019-12-19 14:45:32 +0100
committerNicola Spanti <nicola.spanti@logilab.fr>2019-12-19 14:45:32 +0100
commitedafcaf18af5d3c86959c768f2b9bcb4578f5723 (patch)
tree86c803329be46f11afd33028009eaf1dd616a428
parent20c7f941f3761a742e5fe65ae13639c20e2d428f (diff)
downloadlogilab-common-edafcaf18af5d3c86959c768f2b9bcb4578f5723.tar.gz
[py] Make flake8 less angry with logilab/common/ureports/
-rw-r--r--logilab/common/ureports/__init__.py14
-rw-r--r--logilab/common/ureports/docbook_writer.py39
-rw-r--r--logilab/common/ureports/html_writer.py17
-rw-r--r--logilab/common/ureports/nodes.py25
-rw-r--r--logilab/common/ureports/text_writer.py19
5 files changed, 65 insertions, 49 deletions
diff --git a/logilab/common/ureports/__init__.py b/logilab/common/ureports/__init__.py
index d76ebe5..8ce68a0 100644
--- a/logilab/common/ureports/__init__.py
+++ b/logilab/common/ureports/__init__.py
@@ -3,18 +3,18 @@
#
# This file is part of logilab-common.
#
-# logilab-common is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
+# logilab-common is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by the
+# Free Software Foundation, either version 2.1 of the License,
+# or (at your option) any later version.
#
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
-# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with logilab-common. If not, see <http://www.gnu.org/licenses/>.
"""Universal report objects and some formatting drivers.
A way to create simple reports using python objects, primarily designed to be
@@ -37,6 +37,7 @@ def get_nodes(node, klass):
for grandchild in get_nodes(child, klass):
yield grandchild
+
def layout_title(layout):
"""try to return the layout's title as string, return None if not found
"""
@@ -44,6 +45,7 @@ def layout_title(layout):
if isinstance(child, Title):
return u' '.join([node.data for node in get_nodes(child, Text)])
+
def build_summary(layout, level=1):
"""make a summary for the report, including X level"""
assert level > 0
diff --git a/logilab/common/ureports/docbook_writer.py b/logilab/common/ureports/docbook_writer.py
index a520364..f28474e 100644
--- a/logilab/common/ureports/docbook_writer.py
+++ b/logilab/common/ureports/docbook_writer.py
@@ -3,23 +3,24 @@
#
# This file is part of logilab-common.
#
-# logilab-common is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
+# logilab-common is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by the
+# Free Software Foundation, either version 2.1 of the License,
+# or (at your option) any later version.
#
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
-# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with logilab-common. If not, see <http://www.gnu.org/licenses/>.
"""HTML formatting drivers for ureports"""
__docformat__ = "restructuredtext en"
from logilab.common.ureports import HTMLWriter
+
class DocbookWriter(HTMLWriter):
"""format layouts as HTML"""
@@ -47,7 +48,7 @@ class DocbookWriter(HTMLWriter):
self.section += 1
self.writeln(self._indent('<%s%s>' % (tag, self.handle_attrs(layout))))
self.format_children(layout)
- self.writeln(self._indent('</%s>'% tag))
+ self.writeln(self._indent('</%s>' % tag))
self.section -= 1
def visit_title(self, layout):
@@ -58,11 +59,14 @@ class DocbookWriter(HTMLWriter):
def visit_table(self, layout):
"""display a table as html"""
- self.writeln(self._indent(' <table%s><title>%s</title>' \
- % (self.handle_attrs(layout), layout.title)))
- self.writeln(self._indent(' <tgroup cols="%s">'% layout.cols))
+ self.writeln(
+ self._indent(' <table%s><title>%s</title>' % (
+ self.handle_attrs(layout), layout.title)))
+ self.writeln(self._indent(' <tgroup cols="%s">' % layout.cols))
for i in range(layout.cols):
- self.writeln(self._indent(' <colspec colname="c%s" colwidth="1*"/>' % i))
+ self.writeln(
+ self._indent(
+ ' <colspec colname="c%s" colwidth="1*"/>' % i))
table_content = self.get_table_content(layout)
# write headers
@@ -83,7 +87,8 @@ class DocbookWriter(HTMLWriter):
self.writeln(self._indent(' <row>'))
for j in range(len(row)):
cell = row[j] or '&#160;'
- self.writeln(self._indent(' <entry>%s</entry>' % cell))
+ self.writeln(
+ self._indent(' <entry>%s</entry>' % cell))
self.writeln(self._indent(' </row>'))
self.writeln(self._indent(' </tbody>'))
self.writeln(self._indent(' </tgroup>'))
@@ -99,7 +104,8 @@ class DocbookWriter(HTMLWriter):
def visit_list(self, layout):
"""display a list (using <itemizedlist>)"""
- self.writeln(self._indent(' <itemizedlist%s>' % self.handle_attrs(layout)))
+ self.writeln(self._indent(' <itemizedlist%s>'
+ '' % self.handle_attrs(layout)))
for row in list(self.compute_content(layout)):
self.writeln(' <listitem><para>%s</para></listitem>' % row)
self.writeln(self._indent(' </itemizedlist>'))
@@ -112,16 +118,15 @@ class DocbookWriter(HTMLWriter):
def visit_span(self, layout):
"""display links (using <p>)"""
- #TODO: translate in docbook
+ # TODO: translate in docbook
self.write('<literal %s>' % self.handle_attrs(layout))
self.format_children(layout)
self.write('</literal>')
def visit_link(self, layout):
"""display links (using <ulink>)"""
- self.write('<ulink url="%s"%s>%s</ulink>' % (layout.url,
- self.handle_attrs(layout),
- layout.label))
+ self.write('<ulink url="%s"%s>%s</ulink>' % (
+ layout.url, self.handle_attrs(layout), layout.label))
def visit_verbatimtext(self, layout):
"""display verbatim text (using <programlisting>)"""
diff --git a/logilab/common/ureports/html_writer.py b/logilab/common/ureports/html_writer.py
index 02d0816..989662f 100644
--- a/logilab/common/ureports/html_writer.py
+++ b/logilab/common/ureports/html_writer.py
@@ -3,22 +3,21 @@
#
# This file is part of logilab-common.
#
-# logilab-common is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
+# logilab-common is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by the
+# Free Software Foundation, either version 2.1 of the License,
+# or (at your option) any later version.
#
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
-# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with logilab-common. If not, see <http://www.gnu.org/licenses/>.
"""HTML formatting drivers for ureports"""
__docformat__ = "restructuredtext en"
-from cgi import escape
from logilab.common.ureports import BaseWriter
@@ -54,7 +53,6 @@ class HTMLWriter(BaseWriter):
self.writeln(u'</body>')
self.writeln(u'</html>')
-
def visit_section(self, layout):
"""display a section as html, using div + h[section level]"""
self.section += 1
@@ -80,7 +78,7 @@ class HTMLWriter(BaseWriter):
elif i+1 == len(table_content) and layout.rrheaders:
self.writeln(u'<tr class="header">')
else:
- self.writeln(u'<tr class="%s">' % (i%2 and 'even' or 'odd'))
+ self.writeln(u'<tr class="%s">' % (i % 2 and 'even' or 'odd'))
for j in range(len(row)):
cell = row[j] or u'&#160;'
if (layout.rheaders and i == 0) or \
@@ -117,6 +115,7 @@ class HTMLWriter(BaseWriter):
self.write(u' <a href="%s"%s>%s</a>' % (layout.url,
self.handle_attrs(layout),
layout.label))
+
def visit_verbatimtext(self, layout):
"""display verbatim text (using <pre>)"""
self.write(u'<pre>')
diff --git a/logilab/common/ureports/nodes.py b/logilab/common/ureports/nodes.py
index b90de74..d1267f5 100644
--- a/logilab/common/ureports/nodes.py
+++ b/logilab/common/ureports/nodes.py
@@ -3,18 +3,18 @@
#
# This file is part of logilab-common.
#
-# logilab-common is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
+# logilab-common is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by the
+# Free Software Foundation, either version 2.1 of the License,
+# or (at your option) any later version.
#
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
-# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with logilab-common. If not, see <http://www.gnu.org/licenses/>.
"""Micro reports objects.
A micro report is a tree of layout and content objects.
@@ -23,6 +23,7 @@ __docformat__ = "restructuredtext en"
from logilab.common.tree import VNode
+
class BaseComponent(VNode):
"""base report component
@@ -34,6 +35,7 @@ class BaseComponent(VNode):
VNode.__init__(self, id)
self.klass = klass
+
class BaseLayout(BaseComponent):
"""base container node
@@ -77,12 +79,13 @@ class Text(BaseComponent):
"""
def __init__(self, data, escaped=True, **kwargs):
super(Text, self).__init__(**kwargs)
- #if isinstance(data, unicode):
- # data = data.encode('ascii')
+ # if isinstance(data, unicode):
+ # data = data.encode('ascii')
assert isinstance(data, str), data.__class__
self.escaped = escaped
self.data = data
+
class VerbatimText(Text):
"""a verbatim text, display the raw data
@@ -91,6 +94,7 @@ class VerbatimText(Text):
* data : the text value as an encoded or unicode string
"""
+
class Link(BaseComponent):
"""a labelled link
@@ -144,6 +148,7 @@ class Section(BaseLayout):
if title:
self.insert(0, Title(children=(title,)))
+
class Title(BaseLayout):
"""a title
@@ -153,6 +158,7 @@ class Title(BaseLayout):
A title must not contains a section nor a paragraph!
"""
+
class Span(BaseLayout):
"""a title
@@ -162,6 +168,7 @@ class Span(BaseLayout):
A span should only contains Text and Link nodes (in-line elements)
"""
+
class Paragraph(BaseLayout):
"""a simple text paragraph
@@ -171,6 +178,7 @@ class Paragraph(BaseLayout):
A paragraph must not contains a section !
"""
+
class Table(BaseLayout):
"""some tabular data
@@ -193,6 +201,7 @@ class Table(BaseLayout):
self.rrheaders = rrheaders
self.rcheaders = rcheaders
+
class List(BaseLayout):
"""some list data
diff --git a/logilab/common/ureports/text_writer.py b/logilab/common/ureports/text_writer.py
index b894c09..ae92774 100644
--- a/logilab/common/ureports/text_writer.py
+++ b/logilab/common/ureports/text_writer.py
@@ -3,18 +3,18 @@
#
# This file is part of logilab-common.
#
-# logilab-common is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
+# logilab-common is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by the
+# Free Software Foundation, either version 2.1 of the License,
+# or (at your option) any later version.
#
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
-# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with logilab-common. If not, see <http://www.gnu.org/licenses/>.
"""Text formatting drivers for ureports"""
from __future__ import print_function
@@ -28,6 +28,7 @@ from logilab.common.ureports import BaseWriter
TITLE_UNDERLINES = [u'', u'=', u'-', u'`', u'.', u'~', u'^']
BULLETS = [u'*', u'-']
+
class TextWriter(BaseWriter):
"""format layouts as text
(ReStructured inspiration but not totally handled yet)
@@ -89,7 +90,8 @@ class TextWriter(BaseWriter):
format_strings = u' '.join([u'%%-%ss'] * len(cols_width))
format_strings = format_strings % tuple(cols_width)
format_strings = format_strings.split(' ')
- table_linesep = u'\n+' + u'+'.join([u'-'*w for w in cols_width]) + u'+\n'
+ table_linesep = (
+ u'\n+' + u'+'.join([u'-'*w for w in cols_width]) + u'+\n')
headsep = u'\n+' + u'+'.join([u'='*w for w in cols_width]) + u'+\n'
# FIXME: layout.cheaders
self.write(table_linesep)
@@ -111,7 +113,6 @@ class TextWriter(BaseWriter):
for field, value in table_content:
self.write(format_string % (field, value))
-
def visit_list(self, layout):
"""display a list layout as text"""
bullet = BULLETS[self.list_level % len(BULLETS)]
@@ -126,7 +127,7 @@ class TextWriter(BaseWriter):
"""add a hyperlink"""
if layout.label != layout.url:
self.write(u'`%s`_' % layout.label)
- self.pending_urls.append( (layout.label, layout.url) )
+ self.pending_urls.append((layout.label, layout.url))
else:
self.write(layout.url)