diff options
author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2009-07-27 10:20:26 +0200 |
---|---|---|
committer | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2009-07-27 10:20:26 +0200 |
commit | fd15c8efa8b1344aa05ef4531e65df698b1b8679 (patch) | |
tree | bc164ed6566acf42e52e188f2542f2525a275db8 /ureports | |
parent | 3e5c562599e14ba1d8af5a69ddb69f1a590ba374 (diff) | |
download | logilab-common-fd15c8efa8b1344aa05ef4531e65df698b1b8679.tar.gz |
[cleanup] delete-trailing-whitespaces
Diffstat (limited to 'ureports')
-rw-r--r-- | ureports/__init__.py | 10 | ||||
-rw-r--r-- | ureports/docbook_writer.py | 22 | ||||
-rw-r--r-- | ureports/html_writer.py | 18 | ||||
-rw-r--r-- | ureports/nodes.py | 34 | ||||
-rw-r--r-- | ureports/text_writer.py | 24 |
5 files changed, 53 insertions, 55 deletions
diff --git a/ureports/__init__.py b/ureports/__init__.py index 210ec60..f58707b 100644 --- a/ureports/__init__.py +++ b/ureports/__init__.py @@ -33,14 +33,14 @@ def get_nodes(node, klass): # recurse (FIXME: recursion controled by an option) 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 """ for child in layout.children: if isinstance(child, Title): 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 @@ -70,7 +70,7 @@ def build_summary(layout, level=1): class BaseWriter(object): """base class for ureport writers""" - + def format(self, layout, stream=None, encoding=None): """format and write the given layout into the stream object @@ -88,7 +88,7 @@ class BaseWriter(object): self.begin_format(layout) layout.accept(self) self.end_format(layout) - + def format_children(self, layout): """recurse on the layout children and call their accept method (see the Visitor pattern) @@ -110,7 +110,7 @@ class BaseWriter(object): def begin_format(self, layout): """begin to format a layout""" self.section = 0 - + def end_format(self, layout): """finished to format a layout""" diff --git a/ureports/docbook_writer.py b/ureports/docbook_writer.py index 8848132..d55068f 100644 --- a/ureports/docbook_writer.py +++ b/ureports/docbook_writer.py @@ -19,7 +19,7 @@ from logilab.common.ureports import HTMLWriter class DocbookWriter(HTMLWriter): """format layouts as HTML""" - + def begin_format(self, layout): """begin to format a layout""" super(HTMLWriter, self).begin_format(layout) @@ -29,7 +29,7 @@ class DocbookWriter(HTMLWriter): <book xmlns:xi='http://www.w3.org/2001/XInclude' lang='fr'> """) - + def end_format(self, layout): """finished to format a layout""" if self.snippet is None: @@ -58,9 +58,9 @@ class DocbookWriter(HTMLWriter): 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): + for i in range(layout.cols): self.writeln(self._indent(' <colspec colname="c%s" colwidth="1*"/>' % i)) - + table_content = self.get_table_content(layout) # write headers if layout.cheaders: @@ -93,27 +93,27 @@ class DocbookWriter(HTMLWriter): cell = row[j] or ' ' self.writeln(' <entry>%s</entry>' % cell) self.writeln(self._indent(' </row>')) - + def visit_list(self, layout): """display a list (using <itemizedlist>)""" 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>')) - + def visit_paragraph(self, layout): """display links (using <para>)""" self.write(self._indent(' <para>')) self.format_children(layout) self.writeln('</para>') - + def visit_span(self, layout): """display links (using <p>)""" #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, @@ -125,11 +125,11 @@ class DocbookWriter(HTMLWriter): self.writeln(self._indent(' <programlisting>')) self.write(layout.data.replace('&', '&').replace('<', '<')) self.writeln(self._indent(' </programlisting>')) - + def visit_text(self, layout): """add some text""" self.write(layout.data.replace('&', '&').replace('<', '<')) - + def _indent(self, string): """correctly indent string according to section""" - return ' ' * 2*(self.section) + string + return ' ' * 2*(self.section) + string diff --git a/ureports/html_writer.py b/ureports/html_writer.py index 930aff7..45ae9c5 100644 --- a/ureports/html_writer.py +++ b/ureports/html_writer.py @@ -21,11 +21,11 @@ from logilab.common.ureports import BaseWriter class HTMLWriter(BaseWriter): """format layouts as HTML""" - + def __init__(self, snippet=None): super(HTMLWriter, self).__init__() self.snippet = snippet - + def handle_attrs(self, layout): """get an attribute string from layout member attributes""" attrs = '' @@ -36,14 +36,14 @@ class HTMLWriter(BaseWriter): if nid: attrs += ' id="%s"' % nid return attrs - + def begin_format(self, layout): """begin to format a layout""" super(HTMLWriter, self).begin_format(layout) if self.snippet is None: self.writeln('<html>') self.writeln('<body>') - + def end_format(self, layout): """finished to format a layout""" if self.snippet is None: @@ -88,26 +88,26 @@ class HTMLWriter(BaseWriter): self.writeln('<td>%s</td>' % cell) self.writeln('</tr>') self.writeln('</table>') - + def visit_list(self, layout): """display a list as html""" self.writeln('<ul%s>' % self.handle_attrs(layout)) for row in list(self.compute_content(layout)): self.writeln('<li>%s</li>' % row) self.writeln('</ul>') - + def visit_paragraph(self, layout): """display links (using <p>)""" self.write('<p>') self.format_children(layout) self.write('</p>') - + def visit_span(self, layout): """display links (using <p>)""" self.write('<span%s>' % self.handle_attrs(layout)) self.format_children(layout) self.write('</span>') - + def visit_link(self, layout): """display links (using <a>)""" self.write(' <a href="%s"%s>%s</a>' % (layout.url, @@ -118,7 +118,7 @@ class HTMLWriter(BaseWriter): self.write('<pre>') self.write(layout.data.replace('&', '&').replace('<', '<')) self.write('</pre>') - + def visit_text(self, layout): """add some text""" data = layout.data diff --git a/ureports/nodes.py b/ureports/nodes.py index 3807a4c..8992d31 100644 --- a/ureports/nodes.py +++ b/ureports/nodes.py @@ -48,14 +48,14 @@ class BaseLayout(BaseComponent): """overridden to detect problems easily""" assert child not in self.parents() VNode.append(self, child) - + def parents(self): """return the ancestor nodes""" assert self.parent is not self if self.parent is None: return [] return [self.parent] + self.parent.parents() - + def add_text(self, text): """shortcut to add text data""" self.children.append(Text(text)) @@ -85,7 +85,7 @@ class VerbatimText(Text): * BaseComponent attributes * data : the text value as an encoded or unicode string """ - + class Link(BaseComponent): """a labelled link @@ -100,7 +100,7 @@ class Link(BaseComponent): self.url = url self.label = label or url - + class Image(BaseComponent): """an embeded or a single image @@ -118,15 +118,15 @@ class Image(BaseComponent): self.stream = stream self.title = title - + # container nodes ############################################################# - + class Section(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 @@ -138,34 +138,34 @@ class Section(BaseLayout): self.insert(0, Paragraph([Text(description)])) if title: self.insert(0, Title(children=(title,))) - + class Title(BaseLayout): """a title - + attributes : * BaseLayout attributes A title must not contains a section nor a paragraph! """ - + class Span(BaseLayout): """a title - + attributes : * BaseLayout attributes A span should only contains Text and Link nodes (in-line elements) """ - + class Paragraph(BaseLayout): """a simple text paragraph - + attributes : * BaseLayout attributes A paragraph must not contains a section ! """ - + class Table(BaseLayout): """some tabular data @@ -175,7 +175,7 @@ class Table(BaseLayout): * 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 - """ + """ def __init__(self, cols, title=None, rheaders=0, cheaders=0, rrheaders=0, rcheaders=0, **kwargs): @@ -187,10 +187,10 @@ class Table(BaseLayout): self.cheaders = cheaders self.rrheaders = rrheaders self.rcheaders = rcheaders - + class List(BaseLayout): """some list data attributes : * BaseLayout attributes - """ + """ diff --git a/ureports/text_writer.py b/ureports/text_writer.py index 437d88b..e8bab0d 100644 --- a/ureports/text_writer.py +++ b/ureports/text_writer.py @@ -20,7 +20,7 @@ from logilab.common.ureports import BaseWriter TITLE_UNDERLINES = ['', '=', '-', '`', '.', '~', '^'] BULLETS = ['*', '-'] - + class TextWriter(BaseWriter): """format layouts as text (ReStructured inspiration but not totally handled yet) @@ -29,7 +29,7 @@ class TextWriter(BaseWriter): super(TextWriter, self).begin_format(layout) self.list_level = 0 self.pending_urls = [] - + def visit_section(self, layout): """display a section as text """ @@ -43,7 +43,7 @@ class TextWriter(BaseWriter): self.pending_urls = [] self.section -= 1 self.writeln() - + def visit_title(self, layout): title = ''.join(list(self.compute_content(layout))) self.writeln(title) @@ -51,16 +51,16 @@ class TextWriter(BaseWriter): self.writeln(TITLE_UNDERLINES[self.section] * len(title)) except IndexError: print "FIXME TITLE TOO DEEP. TURNING TITLE INTO TEXT" - + def visit_paragraph(self, layout): """enter a paragraph""" self.format_children(layout) self.writeln() - + def visit_span(self, layout): """enter a span""" self.format_children(layout) - + def visit_table(self, layout): """display a table as text""" table_content = self.get_table_content(layout) @@ -75,7 +75,7 @@ class TextWriter(BaseWriter): else: self.default_table(layout, table_content, cols_width) self.writeln() - + def default_table(self, layout, table_content, cols_width): """format a table""" cols_width = [size+1 for size in cols_width] @@ -96,14 +96,14 @@ class TextWriter(BaseWriter): self.write(headsep) else: self.write(table_linesep) - + def field_table(self, layout, table_content, cols_width): """special case for field table""" assert layout.cols == 2 format_string = '%s%%-%ss: %%s' % (linesep, cols_width[0]) for field, value in table_content: self.write(format_string % (field, value)) - + def visit_list(self, layout): """display a list layout as text""" @@ -122,7 +122,7 @@ class TextWriter(BaseWriter): self.pending_urls.append( (layout.label, layout.url) ) else: self.write(layout.url) - + def visit_verbatimtext(self, layout): """display a verbatim layout as text (so difficult ;) """ @@ -130,9 +130,7 @@ class TextWriter(BaseWriter): for line in layout.data.splitlines(): self.writeln(' ' + line) self.writeln() - + def visit_text(self, layout): """add some text""" self.write(layout.data) - - |