summaryrefslogtreecommitdiff
path: root/logilab/common/ureports/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'logilab/common/ureports/__init__.py')
-rw-r--r--logilab/common/ureports/__init__.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/logilab/common/ureports/__init__.py b/logilab/common/ureports/__init__.py
index 9c0f1df..a539150 100644
--- a/logilab/common/ureports/__init__.py
+++ b/logilab/common/ureports/__init__.py
@@ -46,14 +46,14 @@ def layout_title(layout):
"""
for child in layout.children:
if isinstance(child, Title):
- return u' '.join([node.data for node in get_nodes(child, Text)])
+ return " ".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
level -= 1
- summary = List(klass=u'summary')
+ summary = List(klass="summary")
for child in layout.children:
if not isinstance(child, Section):
continue
@@ -61,8 +61,8 @@ def build_summary(layout, level=1):
if not label and not child.id:
continue
if not child.id:
- child.id = label.replace(' ', '-')
- node = Link(u'#'+child.id, label=label or child.id)
+ child.id = label.replace(" ", "-")
+ node = Link("#" + child.id, label=label or child.id)
# FIXME: Three following lines produce not very compliant
# docbook: there are some useless <para><para>. They might be
# replaced by the three commented lines but this then produces
@@ -70,16 +70,21 @@ def build_summary(layout, level=1):
if level and [n for n in child.children if isinstance(n, Section)]:
node = Paragraph([node, build_summary(child, level)])
summary.append(node)
-# summary.append(node)
-# if level and [n for n in child.children if isinstance(n, Section)]:
-# summary.append(build_summary(child, level))
+ # summary.append(node)
+ # if level and [n for n in child.children if isinstance(n, Section)]:
+ # summary.append(build_summary(child, level))
return summary
class BaseWriter(object):
"""base class for ureport writers"""
- def format(self, layout: Any, stream: Optional[Union[StringIO, TextIO]] = None, encoding: Optional[Any] = None) -> None:
+ def format(
+ self,
+ layout: Any,
+ stream: Optional[Union[StringIO, TextIO]] = None,
+ encoding: Optional[Any] = None,
+ ) -> None:
"""format and write the given layout into the stream object
unicode policy: unicode strings may be found in the layout;
@@ -89,22 +94,22 @@ class BaseWriter(object):
if stream is None:
stream = sys.stdout
if not encoding:
- encoding = getattr(stream, 'encoding', 'UTF-8')
- self.encoding = encoding or 'UTF-8'
+ encoding = getattr(stream, "encoding", "UTF-8")
+ self.encoding = encoding or "UTF-8"
self.__compute_funcs: List[Tuple[Callable[[str], Any], Callable[[str], Any]]] = []
self.out = stream
self.begin_format(layout)
layout.accept(self)
self.end_format(layout)
- def format_children(self, layout: Union['Paragraph', 'Section', 'Title']) -> None:
+ def format_children(self, layout: Union["Paragraph", "Section", "Title"]) -> None:
"""recurse on the layout children and call their accept method
(see the Visitor pattern)
"""
- for child in getattr(layout, 'children', ()):
+ for child in getattr(layout, "children", ()):
child.accept(self)
- def writeln(self, string: str = u'') -> None:
+ def writeln(self, string: str = "") -> None:
"""write a line in the output buffer"""
self.write(string + linesep)
@@ -146,7 +151,7 @@ class BaseWriter(object):
# fill missing cells
while len(result[-1]) < cols:
- result[-1].append(u'')
+ result[-1].append("")
return result
@@ -166,13 +171,13 @@ class BaseWriter(object):
# error from porting to python3?
stream.write(data.encode(self.encoding)) # type: ignore
- def writeln(data: str = u'') -> None:
+ def writeln(data: str = "") -> None:
try:
- stream.write(data+linesep)
+ stream.write(data + linesep)
except UnicodeEncodeError:
# mypy: Unsupported operand types for + ("bytes" and "str")
# error from porting to python3?
- stream.write(data.encode(self.encoding)+linesep) # type: ignore
+ stream.write(data.encode(self.encoding) + linesep) # type: ignore
# mypy: Cannot assign to a method
# this really looks like black dirty magic since self.write is reused elsewhere in the code
@@ -202,6 +207,7 @@ class BaseWriter(object):
del self.write
del self.writeln
+
# mypy error: Incompatible import of "Table" (imported name has type
# mypy error: "Type[logilab.common.ureports.nodes.Table]", local name has type
# mypy error: "Type[logilab.common.table.Table]")