+++ /dev/null
-#! /usr/bin/env python\r
-\r
-"""Print names of all methods defined in module\r
-\r
-This script demonstrates use of the visitor interface of the compiler\r
-package.\r
-"""\r
-\r
-import compiler\r
-\r
-class MethodFinder:\r
- """Print the names of all the methods\r
-\r
- Each visit method takes two arguments, the node and its current\r
- scope. The scope is the name of the current class or None.\r
- """\r
-\r
- def visitClass(self, node, scope=None):\r
- self.visit(node.code, node.name)\r
-\r
- def visitFunction(self, node, scope=None):\r
- if scope is not None:\r
- print "%s.%s" % (scope, node.name)\r
- self.visit(node.code, None)\r
-\r
-def main(files):\r
- mf = MethodFinder()\r
- for file in files:\r
- f = open(file)\r
- buf = f.read()\r
- f.close()\r
- ast = compiler.parse(buf)\r
- compiler.walk(ast, mf)\r
-\r
-if __name__ == "__main__":\r
- import sys\r
-\r
- main(sys.argv[1:])\r