Edgewall Software

source: trunk/scripts/ast_generator.py

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
Line 
1#!/usr/bin/env python2.5
2
3"""Script to that automatically generates genshi/templates/_astpy24.py.
4Be sure to run this with a Python 2.5 interpreter.
5"""
6
7import _ast
8
9done = set()
10
11IGNORE_ATTRS = ('__module__', '__dict__', '__weakref__', '__setattr__',
12                '__new__', '__getattribute__', '__reduce__', '__delattr__',
13                '__init__')
14
15def 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
36print('# Generated automatically, please do not edit')
37print('# Generator can be found in Genshi SVN, scripts/ast_generator.py')
38print('')
39print('__version__ = %s' % _ast.__version__)
40print('')
41
42for name in dir(_ast):
43    cls = getattr(_ast, name)
44    if cls.__class__ is type:
45        print_class(cls)
46        print
Note: See TracBrowser for help on using the repository browser.