|
Last change
on this file was
1090,
checked in by cmlenz, 14 years ago
|
|
Add unit tests for correct handling of with statements and yield expressions in the AST code generator.
|
-
Property svn:eol-style set to
native
-
Property svn:executable set to
*
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [974] | 1 | #!/usr/bin/env python2.5 |
|---|
| [952] | 2 | |
|---|
| [974] | 3 | """Script to that automatically generates genshi/templates/_astpy24.py. |
|---|
| 4 | Be sure to run this with a Python 2.5 interpreter. |
|---|
| 5 | """ |
|---|
| [952] | 6 | |
|---|
| 7 | import _ast |
|---|
| 8 | |
|---|
| [973] | 9 | done = set() |
|---|
| 10 | |
|---|
| 11 | IGNORE_ATTRS = ('__module__', '__dict__', '__weakref__', '__setattr__', |
|---|
| 12 | '__new__', '__getattribute__', '__reduce__', '__delattr__', |
|---|
| 13 | '__init__') |
|---|
| 14 | |
|---|
| [952] | 15 | def print_class(cls): |
|---|
| 16 | bnames = [] |
|---|
| 17 | for base in cls.__bases__: |
|---|
| 18 | if base.__module__ == '_ast': |
|---|
| 19 | if base not in done: |
|---|
| 20 | print_class(base) |
|---|
| 21 | bnames.append(base.__name__) |
|---|
| 22 | elif base.__module__ == '__builtin__': |
|---|
| [1076] | 23 | bnames.append("%s" % base.__name__) |
|---|
| [952] | 24 | else: |
|---|
| [1076] | 25 | bnames.append("%s.%s" % (base.__module__,base.__name__)) |
|---|
| 26 | print("class %s(%s):" % (cls.__name__, ", ".join(bnames))) |
|---|
| [952] | 27 | written = False |
|---|
| 28 | for attr in cls.__dict__: |
|---|
| [973] | 29 | if attr not in IGNORE_ATTRS: |
|---|
| [952] | 30 | written = True |
|---|
| [1076] | 31 | print("\t%s = %s" % (attr, repr(cls.__dict__[attr]),)) |
|---|
| [952] | 32 | if not written: |
|---|
| [1076] | 33 | print("\tpass") |
|---|
| [952] | 34 | done.add(cls) |
|---|
| 35 | |
|---|
| [1076] | 36 | print('# Generated automatically, please do not edit') |
|---|
| [1090] | 37 | print('# Generator can be found in Genshi SVN, scripts/ast_generator.py') |
|---|
| [1076] | 38 | print('') |
|---|
| 39 | print('__version__ = %s' % _ast.__version__) |
|---|
| 40 | print('') |
|---|
| [952] | 41 | |
|---|
| 42 | for name in dir(_ast): |
|---|
| 43 | cls = getattr(_ast, name) |
|---|
| 44 | if cls.__class__ is type: |
|---|
| 45 | print_class(cls) |
|---|
| [973] | 46 | print |
|---|
Note: See
TracBrowser
for help on using the repository browser.