simplify

Changeset

61:3199133437e9
2006-10-07 paulb raw files shortlog changelog graph Added support for reporting annotation errors.
viewer.py (file)
     1.1 --- a/viewer.py	Sat Oct 07 00:22:58 2006 +0200
     1.2 +++ b/viewer.py	Sat Oct 07 00:23:28 2006 +0200
     1.3 @@ -41,12 +41,15 @@
     1.4          self.dispatch(module)
     1.5  
     1.6      def dispatch(self, node):
     1.7 -        self.print_line(getattr(node, "filename", None), getattr(node, "lineno", None))
     1.8 +        self.dispatch_only(node)
     1.9          ASTVisitor.dispatch(self, node)
    1.10  
    1.11 -    def print_line(self, filename, lineno):
    1.12 +    def dispatch_only(self, node, every_time=0):
    1.13 +        self.print_line(getattr(node, "filename", None), getattr(node, "lineno", None), every_time)
    1.14 +
    1.15 +    def print_line(self, filename, lineno, every_time):
    1.16          last_printed = self.printed_lines.get(filename, 0)
    1.17 -        if lineno > last_printed:
    1.18 +        if lineno > last_printed or every_time:
    1.19              self.stream.write(self.get_line(filename, lineno))
    1.20              self.printed_lines[filename] = lineno
    1.21  
    1.22 @@ -68,6 +71,16 @@
    1.23          except IndexError:
    1.24              return ""
    1.25  
    1.26 +    def report(self, exc):
    1.27 +        self.stream.write("Exception was:\n\n" + str(exc.exc) + "\n\n")
    1.28 +        self.stream.write("Nodes:\n\n")
    1.29 +        for node in exc.nodes:
    1.30 +            self.stream.write(repr(node) + "\n")
    1.31 +            self.dispatch_only(node.original, every_time=1)
    1.32 +        self.stream.write("\nOriginal node was:\n\n" + repr(exc.nodes[0].original) + "\n")
    1.33 +        self.stream.write("\nSimplified node was:\n\n")
    1.34 +        exc.nodes[0].pprint(stream=self.stream)
    1.35 +
    1.36  # Convenience functions.
    1.37  
    1.38  def view(module, stream=None):