|
Last change
on this file since 1538 was 2, checked in by Yuri Dario, 15 years ago |
|
Initial import for vendor code.
|
-
Property svn:eol-style
set to
native
|
|
File size:
885 bytes
|
| Line | |
|---|
| 1 | #! /usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | """Print names of all methods defined in module
|
|---|
| 4 |
|
|---|
| 5 | This script demonstrates use of the visitor interface of the compiler
|
|---|
| 6 | package.
|
|---|
| 7 | """
|
|---|
| 8 |
|
|---|
| 9 | import compiler
|
|---|
| 10 |
|
|---|
| 11 | class MethodFinder:
|
|---|
| 12 | """Print the names of all the methods
|
|---|
| 13 |
|
|---|
| 14 | Each visit method takes two arguments, the node and its current
|
|---|
| 15 | scope. The scope is the name of the current class or None.
|
|---|
| 16 | """
|
|---|
| 17 |
|
|---|
| 18 | def visitClass(self, node, scope=None):
|
|---|
| 19 | self.visit(node.code, node.name)
|
|---|
| 20 |
|
|---|
| 21 | def visitFunction(self, node, scope=None):
|
|---|
| 22 | if scope is not None:
|
|---|
| 23 | print "%s.%s" % (scope, node.name)
|
|---|
| 24 | self.visit(node.code, None)
|
|---|
| 25 |
|
|---|
| 26 | def main(files):
|
|---|
| 27 | mf = MethodFinder()
|
|---|
| 28 | for file in files:
|
|---|
| 29 | f = open(file)
|
|---|
| 30 | buf = f.read()
|
|---|
| 31 | f.close()
|
|---|
| 32 | ast = compiler.parse(buf)
|
|---|
| 33 | compiler.walk(ast, mf)
|
|---|
| 34 |
|
|---|
| 35 | if __name__ == "__main__":
|
|---|
| 36 | import sys
|
|---|
| 37 |
|
|---|
| 38 | main(sys.argv[1:])
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.