| 1 | #!/usr/bin/env python2.5 |
|---|
| 2 | |
|---|
| 3 | """Script to that automatically generates genshi/templates/_astpy24.py. |
|---|
| 4 | Be sure to run this with a Python 2.5 interpreter. |
|---|
| 5 | """ |
|---|
| 6 | |
|---|
| 7 | import _ast |
|---|
| 8 | |
|---|
| 9 | done = set() |
|---|
| 10 | |
|---|
| 11 | IGNORE_ATTRS = ('__module__', '__dict__', '__weakref__', '__setattr__', |
|---|
| 12 | '__new__', '__getattribute__', '__reduce__', '__delattr__', |
|---|
| 13 | '__init__') |
|---|
| 14 | |
|---|
| 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__': |
|---|
| 23 | bnames.append("%s" % base.__name__) |
|---|
| 24 | else: |
|---|
| 25 | bnames.append("%s.%s" % (base.__module__,base.__name__)) |
|---|
| 26 | print("class %s(%s):" % (cls.__name__, ", ".join(bnames))) |
|---|
| 27 | written = False |
|---|
| 28 | for attr in cls.__dict__: |
|---|
| 29 | if attr not in IGNORE_ATTRS: |
|---|
| 30 | written = True |
|---|
| 31 | print("\t%s = %s" % (attr, repr(cls.__dict__[attr]),)) |
|---|
| 32 | if not written: |
|---|
| 33 | print("\tpass") |
|---|
| 34 | done.add(cls) |
|---|
| 35 | |
|---|
| 36 | print('# Generated automatically, please do not edit') |
|---|
| 37 | print('# Generator can be found in Genshi SVN, scripts/ast_generator.py') |
|---|
| 38 | print('') |
|---|
| 39 | print('__version__ = %s' % _ast.__version__) |
|---|
| 40 | print('') |
|---|
| 41 | |
|---|
| 42 | for name in dir(_ast): |
|---|
| 43 | cls = getattr(_ast, name) |
|---|
| 44 | if cls.__class__ is type: |
|---|
| 45 | print_class(cls) |
|---|
| 46 | print |
|---|