OLD | NEW |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. | 1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # | 3 # |
4 # This file is part of logilab-common. | 4 # This file is part of logilab-common. |
5 # | 5 # |
6 # logilab-common is free software: you can redistribute it and/or modify it unde
r | 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r |
7 # the terms of the GNU Lesser General Public License as published by the Free | 7 # the terms of the GNU Lesser General Public License as published by the Free |
8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y | 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
9 # later version. | 9 # later version. |
10 # | 10 # |
11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT | 11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT |
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | 13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. | 14 # details. |
15 # | 15 # |
16 # You should have received a copy of the GNU Lesser General Public License along | 16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. | 17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. |
18 """Universal report objects and some formatting drivers. | 18 """Universal report objects and some formatting drivers. |
19 | 19 |
20 A way to create simple reports using python objects, primarily designed to be | 20 A way to create simple reports using python objects, primarily designed to be |
21 formatted as text and html. | 21 formatted as text and html. |
22 """ | 22 """ |
| 23 from __future__ import generators |
23 __docformat__ = "restructuredtext en" | 24 __docformat__ = "restructuredtext en" |
24 | 25 |
25 import sys | 26 import sys |
| 27 from cStringIO import StringIO |
| 28 from StringIO import StringIO as UStringIO |
26 | 29 |
27 from logilab.common.compat import StringIO | |
28 from logilab.common.textutils import linesep | 30 from logilab.common.textutils import linesep |
29 | 31 |
30 | 32 |
31 def get_nodes(node, klass): | 33 def get_nodes(node, klass): |
32 """return an iterator on all children node of the given klass""" | 34 """return an iterator on all children node of the given klass""" |
33 for child in node.children: | 35 for child in node.children: |
34 if isinstance(child, klass): | 36 if isinstance(child, klass): |
35 yield child | 37 yield child |
36 # recurse (FIXME: recursion controled by an option) | 38 # recurse (FIXME: recursion controled by an option) |
37 for grandchild in get_nodes(child, klass): | 39 for grandchild in get_nodes(child, klass): |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 stream.write(data.encode(self.encoding)) | 151 stream.write(data.encode(self.encoding)) |
150 def writeln(data=''): | 152 def writeln(data=''): |
151 try: | 153 try: |
152 stream.write(data+linesep) | 154 stream.write(data+linesep) |
153 except UnicodeEncodeError: | 155 except UnicodeEncodeError: |
154 stream.write(data.encode(self.encoding)+linesep) | 156 stream.write(data.encode(self.encoding)+linesep) |
155 self.write = write | 157 self.write = write |
156 self.writeln = writeln | 158 self.writeln = writeln |
157 self.__compute_funcs.append((write, writeln)) | 159 self.__compute_funcs.append((write, writeln)) |
158 for child in layout.children: | 160 for child in layout.children: |
159 stream = StringIO() | 161 stream = UStringIO() |
160 child.accept(self) | 162 child.accept(self) |
161 yield stream.getvalue() | 163 yield stream.getvalue() |
162 self.__compute_funcs.pop() | 164 self.__compute_funcs.pop() |
163 try: | 165 try: |
164 self.write, self.writeln = self.__compute_funcs[-1] | 166 self.write, self.writeln = self.__compute_funcs[-1] |
165 except IndexError: | 167 except IndexError: |
166 del self.write | 168 del self.write |
167 del self.writeln | 169 del self.writeln |
168 | 170 |
169 | 171 |
170 from logilab.common.ureports.nodes import * | 172 from logilab.common.ureports.nodes import * |
171 from logilab.common.ureports.text_writer import TextWriter | 173 from logilab.common.ureports.text_writer import TextWriter |
172 from logilab.common.ureports.html_writer import HTMLWriter | 174 from logilab.common.ureports.html_writer import HTMLWriter |
OLD | NEW |