paulb@57 | 1 | #!/usr/bin/env python |
paulb@57 | 2 | |
paulb@57 | 3 | """ |
paulb@57 | 4 | View annotated sources. |
paulb@57 | 5 | |
paulb@57 | 6 | Copyright (C) 2006 Paul Boddie <paul@boddie.org.uk> |
paulb@57 | 7 | |
paulb@57 | 8 | This software is free software; you can redistribute it and/or |
paulb@57 | 9 | modify it under the terms of the GNU General Public License as |
paulb@57 | 10 | published by the Free Software Foundation; either version 2 of |
paulb@57 | 11 | the License, or (at your option) any later version. |
paulb@57 | 12 | |
paulb@57 | 13 | This software is distributed in the hope that it will be useful, |
paulb@57 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@57 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paulb@57 | 16 | GNU General Public License for more details. |
paulb@57 | 17 | |
paulb@57 | 18 | You should have received a copy of the GNU General Public |
paulb@57 | 19 | License along with this library; see the file LICENCE.txt |
paulb@57 | 20 | If not, write to the Free Software Foundation, Inc., |
paulb@57 | 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@57 | 22 | """ |
paulb@57 | 23 | |
paulb@57 | 24 | from compiler.visitor import ASTVisitor |
paulb@83 | 25 | from simplified import * |
paulb@57 | 26 | import sys |
paulb@57 | 27 | |
paulb@83 | 28 | # Exceptions. |
paulb@83 | 29 | |
paulb@83 | 30 | class ViewerError(SimplifiedError): |
paulb@83 | 31 | |
paulb@83 | 32 | "An error in viewing." |
paulb@83 | 33 | |
paulb@83 | 34 | pass |
paulb@83 | 35 | |
paulb@83 | 36 | # Classes. |
paulb@83 | 37 | |
paulb@57 | 38 | class Viewer(ASTVisitor): |
paulb@57 | 39 | |
paulb@57 | 40 | """ |
paulb@57 | 41 | A viewing visitor for AST nodes. |
paulb@57 | 42 | """ |
paulb@57 | 43 | |
paulb@57 | 44 | def __init__(self, stream): |
paulb@57 | 45 | ASTVisitor.__init__(self) |
paulb@57 | 46 | self.cached_files = {} |
paulb@57 | 47 | self.printed_lines = {} |
paulb@57 | 48 | self.visitor = self |
paulb@57 | 49 | self.stream = stream |
paulb@57 | 50 | |
paulb@57 | 51 | def process(self, module): |
paulb@57 | 52 | self.dispatch(module) |
paulb@57 | 53 | |
paulb@57 | 54 | def dispatch(self, node): |
paulb@61 | 55 | self.dispatch_only(node) |
paulb@57 | 56 | ASTVisitor.dispatch(self, node) |
paulb@57 | 57 | |
paulb@61 | 58 | def dispatch_only(self, node, every_time=0): |
paulb@61 | 59 | self.print_line(getattr(node, "filename", None), getattr(node, "lineno", None), every_time) |
paulb@61 | 60 | |
paulb@61 | 61 | def print_line(self, filename, lineno, every_time): |
paulb@57 | 62 | last_printed = self.printed_lines.get(filename, 0) |
paulb@61 | 63 | if lineno > last_printed or every_time: |
paulb@57 | 64 | self.stream.write(self.get_line(filename, lineno)) |
paulb@57 | 65 | self.printed_lines[filename] = lineno |
paulb@57 | 66 | |
paulb@57 | 67 | def get_line(self, filename, lineno): |
paulb@57 | 68 | if filename is None or lineno is None: |
paulb@57 | 69 | return "" |
paulb@57 | 70 | |
paulb@57 | 71 | if self.cached_files.has_key(filename): |
paulb@57 | 72 | lines = self.cached_files[filename] |
paulb@57 | 73 | else: |
paulb@57 | 74 | f = open(filename) |
paulb@57 | 75 | try: |
paulb@57 | 76 | self.cached_files[filename] = lines = f.readlines() |
paulb@57 | 77 | finally: |
paulb@57 | 78 | f.close() |
paulb@57 | 79 | |
paulb@57 | 80 | try: |
paulb@57 | 81 | return lines[lineno - 1] |
paulb@57 | 82 | except IndexError: |
paulb@57 | 83 | return "" |
paulb@57 | 84 | |
paulb@61 | 85 | def report(self, exc): |
paulb@61 | 86 | self.stream.write("Exception was:\n\n" + str(exc.exc) + "\n\n") |
paulb@61 | 87 | self.stream.write("Nodes:\n\n") |
paulb@61 | 88 | for node in exc.nodes: |
paulb@61 | 89 | self.stream.write(repr(node) + "\n") |
paulb@61 | 90 | self.dispatch_only(node.original, every_time=1) |
paulb@61 | 91 | self.stream.write("\nOriginal node was:\n\n" + repr(exc.nodes[0].original) + "\n") |
paulb@61 | 92 | self.stream.write("\nSimplified node was:\n\n") |
paulb@61 | 93 | exc.nodes[0].pprint(stream=self.stream) |
paulb@61 | 94 | |
paulb@78 | 95 | # HTML-related output production. |
paulb@78 | 96 | |
paulb@78 | 97 | html_header = """<?xml version="1.0" encoding="iso-8859-15"?> |
paulb@78 | 98 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
paulb@78 | 99 | <html xmlns="http://www.w3.org/1999/xhtml"> |
paulb@78 | 100 | <head> |
paulb@78 | 101 | <title>Module</title> |
paulb@78 | 102 | <style type="text/css"> |
paulb@78 | 103 | body { |
paulb@78 | 104 | padding-top: 4em; padding-bottom: 4em; |
paulb@78 | 105 | font-size: 14pt; font-family: monospace; |
paulb@78 | 106 | background-color: black; color: white; |
paulb@78 | 107 | } |
paulb@78 | 108 | |
paulb@78 | 109 | .class { margin-bottom: 1em; } |
paulb@78 | 110 | .function { margin-bottom: 1em; } |
paulb@78 | 111 | .body { padding-left: 2em; } |
paulb@78 | 112 | .keyword { color: yellow; } |
paulb@78 | 113 | .comment { color: blue; } |
paulb@83 | 114 | .str { color: #FF00FF; } |
paulb@83 | 115 | .doc { color: #FF00FF; margin-bottom: 1em; } |
paulb@78 | 116 | .ref { color: cyan; } |
paulb@78 | 117 | .ref a { color: cyan; text-decoration: none; } |
paulb@78 | 118 | |
paulb@84 | 119 | .popup { |
paulb@78 | 120 | display: none; z-index: 2; |
paulb@84 | 121 | position: absolute; top: 1em; left: 0.5em; |
paulb@84 | 122 | padding: 0.5em; background-color: #000000; |
paulb@84 | 123 | } |
paulb@84 | 124 | |
paulb@84 | 125 | .types { |
paulb@78 | 126 | padding: 0.5em; background-color: #0000FF; |
paulb@84 | 127 | float: right; |
paulb@78 | 128 | } |
paulb@78 | 129 | |
paulb@79 | 130 | .scopes { |
paulb@79 | 131 | padding: 0.5em; background-color: #007700; |
paulb@84 | 132 | float: left; |
paulb@79 | 133 | } |
paulb@79 | 134 | |
paulb@83 | 135 | .name, |
paulb@83 | 136 | .attr |
paulb@83 | 137 | { |
paulb@83 | 138 | position: relative; |
paulb@83 | 139 | } |
paulb@83 | 140 | |
paulb@84 | 141 | .name:hover > .popup, |
paulb@84 | 142 | .attr:hover > .popup |
paulb@78 | 143 | { |
paulb@78 | 144 | display: block; |
paulb@78 | 145 | } |
paulb@78 | 146 | |
paulb@78 | 147 | </style> |
paulb@78 | 148 | </head> |
paulb@78 | 149 | <body> |
paulb@78 | 150 | """ |
paulb@78 | 151 | |
paulb@78 | 152 | html_footer = """</body> |
paulb@78 | 153 | </html> |
paulb@78 | 154 | """ |
paulb@78 | 155 | |
paulb@78 | 156 | class Browser(ASTVisitor): |
paulb@78 | 157 | |
paulb@78 | 158 | """ |
paulb@78 | 159 | A browsing visitor for AST nodes. |
paulb@78 | 160 | """ |
paulb@78 | 161 | |
paulb@78 | 162 | def __init__(self, stream): |
paulb@78 | 163 | ASTVisitor.__init__(self) |
paulb@78 | 164 | self.visitor = self |
paulb@78 | 165 | self.stream = stream |
paulb@78 | 166 | |
paulb@78 | 167 | def process(self, module): |
paulb@78 | 168 | self.stream.write(html_header) |
paulb@78 | 169 | self.dispatch(module) |
paulb@78 | 170 | self.stream.write(html_footer) |
paulb@78 | 171 | |
paulb@83 | 172 | def dispatch(self, node): |
paulb@83 | 173 | try: |
paulb@83 | 174 | ASTVisitor.dispatch(self, node) |
paulb@83 | 175 | except ViewerError, exc: |
paulb@83 | 176 | exc.add(node) |
paulb@83 | 177 | raise |
paulb@83 | 178 | except Exception, exc: |
paulb@83 | 179 | raise ViewerError(exc, node) |
paulb@83 | 180 | |
paulb@78 | 181 | def visitModule(self, node): |
paulb@78 | 182 | self.default(node) |
paulb@78 | 183 | |
paulb@79 | 184 | # Statements. |
paulb@79 | 185 | |
paulb@78 | 186 | def visitPass(self, node): |
paulb@78 | 187 | self._keyword("pass") |
paulb@78 | 188 | |
paulb@78 | 189 | def visitClass(self, node): |
paulb@79 | 190 | definition = node._node |
paulb@83 | 191 | structure = definition.expr.ref |
paulb@79 | 192 | self.stream.write("<div class='class' id='%s'>\n" % self._url(structure.full_name())) |
paulb@78 | 193 | self.stream.write("<p>\n") |
paulb@78 | 194 | self._keyword("class") |
paulb@83 | 195 | self._name_start(structure.name) |
paulb@84 | 196 | self._popup_start() |
paulb@79 | 197 | self._scopes(definition) |
paulb@84 | 198 | self._popup_end() |
paulb@79 | 199 | self._name_end() |
paulb@78 | 200 | bases = structure.bases |
paulb@78 | 201 | if bases: |
paulb@79 | 202 | self.stream.write("(") |
paulb@78 | 203 | first = 1 |
paulb@78 | 204 | for base in bases: |
paulb@78 | 205 | if not first: |
paulb@78 | 206 | self.stream.write(",\n") |
paulb@83 | 207 | self._name_start(base.name) |
paulb@84 | 208 | self._popup_start() |
paulb@79 | 209 | self._types(base) |
paulb@79 | 210 | self._scopes(base) |
paulb@84 | 211 | self._popup_end() |
paulb@79 | 212 | self._name_end() |
paulb@78 | 213 | first = 0 |
paulb@78 | 214 | self.stream.write(")") |
paulb@78 | 215 | self.stream.write(":\n") |
paulb@79 | 216 | self._comment(self._text(structure.full_name())) |
paulb@78 | 217 | self.stream.write("</p>\n") |
paulb@78 | 218 | |
paulb@78 | 219 | self.stream.write("<div class='body'>\n") |
paulb@79 | 220 | self._doc(node) |
paulb@79 | 221 | self.dispatch(node.code) |
paulb@78 | 222 | self.stream.write("</div>\n") |
paulb@78 | 223 | self.stream.write("</div>\n") |
paulb@78 | 224 | |
paulb@83 | 225 | def visitFunction(self, node): |
paulb@83 | 226 | definition = node._node |
paulb@83 | 227 | subprogram = definition.expr.ref |
paulb@83 | 228 | self.stream.write("<div class='def' id='%s'>\n" % self._url(subprogram.full_name())) |
paulb@83 | 229 | self.stream.write("<p>\n") |
paulb@83 | 230 | self._keyword("def") |
paulb@83 | 231 | self._name_start(subprogram.name) |
paulb@84 | 232 | self._popup_start() |
paulb@83 | 233 | self._scopes(definition) |
paulb@84 | 234 | self._popup_end() |
paulb@83 | 235 | self._name_end() |
paulb@83 | 236 | self.stream.write("(") |
paulb@83 | 237 | first = 1 |
paulb@83 | 238 | for param, default in subprogram.params: |
paulb@83 | 239 | if not first: |
paulb@83 | 240 | self.stream.write(",\n") |
paulb@85 | 241 | self._parameter(subprogram, param) |
paulb@85 | 242 | first = 0 |
paulb@85 | 243 | if subprogram.star is not None: |
paulb@85 | 244 | if not first: |
paulb@85 | 245 | self.stream.write(", *\n") |
paulb@85 | 246 | param, default = subprogram.star |
paulb@85 | 247 | self._parameter(subprogram, param) |
paulb@85 | 248 | first = 0 |
paulb@85 | 249 | if subprogram.dstar is not None: |
paulb@85 | 250 | if not first: |
paulb@85 | 251 | self.stream.write(", **\n") |
paulb@85 | 252 | param, default = subprogram.dstar |
paulb@85 | 253 | self._parameter(subprogram, param) |
paulb@83 | 254 | first = 0 |
paulb@83 | 255 | self.stream.write(")") |
paulb@83 | 256 | self.stream.write(":\n") |
paulb@83 | 257 | self._comment(self._text(subprogram.full_name())) |
paulb@83 | 258 | self.stream.write("</p>\n") |
paulb@83 | 259 | |
paulb@83 | 260 | self.stream.write("<div class='body'>\n") |
paulb@83 | 261 | self._doc(node) |
paulb@83 | 262 | self.dispatch(node.code) |
paulb@83 | 263 | self.stream.write("</div>\n") |
paulb@83 | 264 | self.stream.write("</div>\n") |
paulb@83 | 265 | |
paulb@83 | 266 | def visitStmt(self, node): |
paulb@83 | 267 | self.stream.write("<div class='stmt'>\n") |
paulb@83 | 268 | self.default(node) |
paulb@83 | 269 | self.stream.write("</div>\n") |
paulb@83 | 270 | |
paulb@79 | 271 | def visitAssign(self, node): |
paulb@79 | 272 | self.stream.write("<div class='assign'>\n") |
paulb@79 | 273 | for lvalue in node.nodes: |
paulb@79 | 274 | self.dispatch(lvalue) |
paulb@79 | 275 | self.stream.write("=\n") |
paulb@79 | 276 | self.dispatch(node.expr) |
paulb@79 | 277 | self.stream.write("</div>\n") |
paulb@79 | 278 | |
paulb@79 | 279 | # Expressions. |
paulb@79 | 280 | |
paulb@85 | 281 | def visitCallFunc(self, node): |
paulb@85 | 282 | invocation = node._node |
paulb@85 | 283 | self.stream.write("<span class='callfunc'>\n") |
paulb@85 | 284 | self.dispatch(node.node) |
paulb@85 | 285 | self.stream.write("(") |
paulb@85 | 286 | first = 1 |
paulb@85 | 287 | for arg in node.args: |
paulb@85 | 288 | if not first: |
paulb@85 | 289 | self.stream.write(",\n") |
paulb@85 | 290 | self.dispatch(arg) |
paulb@85 | 291 | first = 0 |
paulb@85 | 292 | if node.star_args is not None: |
paulb@85 | 293 | if not first: |
paulb@85 | 294 | self.stream.write(", *\n") |
paulb@85 | 295 | self.dispatch(node.star_args) |
paulb@85 | 296 | first = 0 |
paulb@85 | 297 | if node.dstar_args is not None: |
paulb@85 | 298 | if not first: |
paulb@85 | 299 | self.stream.write(", **\n") |
paulb@85 | 300 | self.dispatch(node.dstar_args) |
paulb@85 | 301 | first = 0 |
paulb@85 | 302 | self.stream.write(")\n") |
paulb@85 | 303 | self.stream.write("</span>\n") |
paulb@85 | 304 | |
paulb@79 | 305 | def visitTuple(self, node): |
paulb@79 | 306 | self.stream.write("<span class='tuple'>\n") |
paulb@79 | 307 | self.stream.write("(") |
paulb@79 | 308 | self._sequence(node) |
paulb@79 | 309 | self.stream.write(")\n") |
paulb@79 | 310 | self.stream.write("</span>\n") |
paulb@79 | 311 | |
paulb@79 | 312 | visitAssTuple = visitTuple |
paulb@79 | 313 | |
paulb@79 | 314 | def visitList(self, node): |
paulb@79 | 315 | self.stream.write("<span class='list'>\n") |
paulb@79 | 316 | self.stream.write("[") |
paulb@79 | 317 | self._sequence(node) |
paulb@79 | 318 | self.stream.write("]\n") |
paulb@79 | 319 | self.stream.write("</span>\n") |
paulb@79 | 320 | |
paulb@79 | 321 | visitAssList = visitList |
paulb@79 | 322 | |
paulb@79 | 323 | def visitName(self, node): |
paulb@83 | 324 | self._name_start(node._node.name) |
paulb@84 | 325 | self._popup_start() |
paulb@79 | 326 | self._types(node._node) |
paulb@79 | 327 | self._scopes(node._node) |
paulb@84 | 328 | self._popup_end() |
paulb@79 | 329 | self._name_end() |
paulb@79 | 330 | |
paulb@79 | 331 | def visitAssName(self, node): |
paulb@83 | 332 | self._name_start(node._node.name) |
paulb@84 | 333 | self._popup_start() |
paulb@79 | 334 | self._types(node._node.expr) |
paulb@79 | 335 | self._scopes(node._node) |
paulb@84 | 336 | self._popup_end() |
paulb@79 | 337 | self._name_end() |
paulb@79 | 338 | |
paulb@79 | 339 | def visitConst(self, node): |
paulb@79 | 340 | self.stream.write(repr(node.value)) |
paulb@79 | 341 | |
paulb@83 | 342 | def visitGetattr(self, node): |
paulb@83 | 343 | self.stream.write("<span class='getattr'>\n") |
paulb@83 | 344 | self.dispatch(node.expr) |
paulb@83 | 345 | self.stream.write("<span class='attr'>\n") |
paulb@83 | 346 | self.stream.write(".%s\n" % self._text(node.attrname)) |
paulb@84 | 347 | self._popup_start() |
paulb@83 | 348 | self._types(node._node) |
paulb@83 | 349 | self._scopes(node._node) |
paulb@84 | 350 | self._popup_end() |
paulb@83 | 351 | self.stream.write("</span>\n") |
paulb@83 | 352 | self.stream.write("</span>\n") |
paulb@83 | 353 | |
paulb@83 | 354 | def visitAssAttr(self, node): |
paulb@83 | 355 | self.stream.write("<span class='assattr'>\n") |
paulb@83 | 356 | self.dispatch(node.expr) |
paulb@83 | 357 | self.stream.write("<span class='attr'>\n") |
paulb@83 | 358 | self.stream.write(".%s\n" % self._text(node.attrname)) |
paulb@84 | 359 | self._popup_start() |
paulb@83 | 360 | self._types(node._node) |
paulb@83 | 361 | self._scopes(node._node) |
paulb@84 | 362 | self._popup_end() |
paulb@83 | 363 | self.stream.write("</span>\n") |
paulb@83 | 364 | self.stream.write("</span>\n") |
paulb@83 | 365 | |
paulb@78 | 366 | # Output preparation methods. |
paulb@78 | 367 | |
paulb@78 | 368 | def _text(self, text): |
paulb@78 | 369 | return text.replace("&", "&").replace("<", "<").replace(">", ">") |
paulb@78 | 370 | |
paulb@78 | 371 | def _attr(self, attr): |
paulb@78 | 372 | return self._text(attr).replace("'", "'").replace('"', """) |
paulb@78 | 373 | |
paulb@78 | 374 | def _url(self, url): |
paulb@78 | 375 | return self._attr(url).replace("#", "%23").replace("-", "%2d") |
paulb@78 | 376 | |
paulb@78 | 377 | def _comment(self, comment): |
paulb@78 | 378 | self.stream.write("<span class='comment'># %s</span>\n" % comment) |
paulb@78 | 379 | |
paulb@78 | 380 | def _keyword(self, kw): |
paulb@78 | 381 | self.stream.write("<span class='keyword'>%s</span> " % kw) |
paulb@78 | 382 | |
paulb@79 | 383 | def _doc(self, node): |
paulb@79 | 384 | if node.doc is not None: |
paulb@83 | 385 | self.stream.write("<div class='doc'>%s</div>\n" % self._text(repr(node.doc))) |
paulb@79 | 386 | |
paulb@79 | 387 | def _sequence(self, node): |
paulb@79 | 388 | first = 1 |
paulb@79 | 389 | for n in node.nodes: |
paulb@79 | 390 | if not first: |
paulb@79 | 391 | self.stream.write(",\n") |
paulb@79 | 392 | self.dispatch(n) |
paulb@79 | 393 | first = 0 |
paulb@78 | 394 | |
paulb@85 | 395 | def _parameter(self, subprogram, param): |
paulb@85 | 396 | self._name_start(param) |
paulb@85 | 397 | if hasattr(subprogram, "paramtypes"): |
paulb@85 | 398 | self._popup_start() |
paulb@85 | 399 | self._types_list(subprogram.paramtypes[param]) |
paulb@85 | 400 | self._popup_end() |
paulb@85 | 401 | self._name_end() |
paulb@85 | 402 | |
paulb@83 | 403 | def _name(self, name): |
paulb@83 | 404 | self.stream.write("<span class='name'>%s</span>\n" % name) |
paulb@79 | 405 | |
paulb@83 | 406 | def _name_start(self, name): |
paulb@83 | 407 | self.stream.write("<span class='name'>%s\n" % name) |
paulb@79 | 408 | |
paulb@79 | 409 | def _name_end(self): |
paulb@79 | 410 | self.stream.write("</span>\n") |
paulb@79 | 411 | |
paulb@84 | 412 | def _popup_start(self): |
paulb@84 | 413 | self.stream.write("<span class='popup'>\n") |
paulb@84 | 414 | |
paulb@84 | 415 | def _popup_end(self): |
paulb@84 | 416 | self.stream.write("</span>\n") |
paulb@84 | 417 | |
paulb@79 | 418 | def _types(self, node): |
paulb@84 | 419 | if hasattr(node, "types"): |
paulb@84 | 420 | self._types_list(node.types) |
paulb@84 | 421 | elif hasattr(node, "writes"): |
paulb@84 | 422 | self._types_list(flatten(node.writes.values())) |
paulb@84 | 423 | elif hasattr(node, "accesses"): |
paulb@84 | 424 | self._types_list(flatten(node.accesses.values())) |
paulb@84 | 425 | else: |
paulb@83 | 426 | self.stream.write("<div class='types'>\n") |
paulb@83 | 427 | self.stream.write("No types!\n") |
paulb@83 | 428 | self.stream.write("</div>\n") |
paulb@83 | 429 | |
paulb@83 | 430 | def _types_list(self, types): |
paulb@79 | 431 | self.stream.write("<div class='types'>\n") |
paulb@83 | 432 | for type in types: |
paulb@79 | 433 | fn = type.type.full_name() |
paulb@79 | 434 | self.stream.write("<div class='type'>") |
paulb@78 | 435 | self.stream.write(self._text(fn)) |
paulb@78 | 436 | self.stream.write("</div>\n") |
paulb@79 | 437 | self.stream.write("</div>\n") |
paulb@79 | 438 | |
paulb@79 | 439 | def _scopes(self, node): |
paulb@83 | 440 | if not isinstance(node, LoadName): |
paulb@83 | 441 | self.stream.write("<div class='scopes'>\n") |
paulb@83 | 442 | if not hasattr(node, "writes") and not hasattr(node, "accesses"): |
paulb@83 | 443 | self.stream.write("No scopes!\n") |
paulb@83 | 444 | else: |
paulb@83 | 445 | for ref in getattr(node, "writes", getattr(node, "accesses", {})).keys(): |
paulb@83 | 446 | fn = ref.full_name() |
paulb@83 | 447 | self.stream.write("<div class='scope'>") |
paulb@83 | 448 | self.stream.write(self._text(fn)) |
paulb@83 | 449 | self.stream.write("</div>\n") |
paulb@79 | 450 | self.stream.write("</div>\n") |
paulb@78 | 451 | |
paulb@84 | 452 | # Utility functions. |
paulb@84 | 453 | |
paulb@84 | 454 | def flatten(lists): |
paulb@84 | 455 | result = [] |
paulb@84 | 456 | for l in lists: |
paulb@84 | 457 | for attr in l: |
paulb@84 | 458 | if attr not in result: |
paulb@84 | 459 | result.append(attr) |
paulb@84 | 460 | return result |
paulb@84 | 461 | |
paulb@57 | 462 | # Convenience functions. |
paulb@57 | 463 | |
paulb@57 | 464 | def view(module, stream=None): |
paulb@57 | 465 | viewer = Viewer(stream or sys.stdout) |
paulb@57 | 466 | viewer.process(module.original) |
paulb@57 | 467 | |
paulb@78 | 468 | def browse(module, stream=None): |
paulb@78 | 469 | browser = Browser(stream or sys.stdout) |
paulb@78 | 470 | browser.process(module.original) |
paulb@78 | 471 | |
paulb@78 | 472 | def makedoc(module, filename): |
paulb@78 | 473 | stream = open(filename, "wb") |
paulb@78 | 474 | try: |
paulb@78 | 475 | browser = Browser(stream) |
paulb@78 | 476 | browser.process(module.original) |
paulb@78 | 477 | finally: |
paulb@78 | 478 | stream.close() |
paulb@78 | 479 | |
paulb@57 | 480 | # vim: tabstop=4 expandtab shiftwidth=4 |