cmlenz@820: #!/usr/bin/env python2.5 cmlenz@820: cmlenz@820: """Script to that automatically generates genshi/templates/_astpy24.py. cmlenz@820: Be sure to run this with a Python 2.5 interpreter. cmlenz@820: """ cmlenz@820: cmlenz@820: import _ast cmlenz@820: cmlenz@820: done = set() cmlenz@820: cmlenz@820: IGNORE_ATTRS = ('__module__', '__dict__', '__weakref__', '__setattr__', cmlenz@820: '__new__', '__getattribute__', '__reduce__', '__delattr__', cmlenz@820: '__init__') cmlenz@820: cmlenz@820: def print_class(cls): cmlenz@820: bnames = [] cmlenz@820: for base in cls.__bases__: cmlenz@820: if base.__module__ == '_ast': cmlenz@820: if base not in done: cmlenz@820: print_class(base) cmlenz@820: bnames.append(base.__name__) cmlenz@820: elif base.__module__ == '__builtin__': cmlenz@902: bnames.append("%s" % base.__name__) cmlenz@820: else: cmlenz@902: bnames.append("%s.%s" % (base.__module__,base.__name__)) cmlenz@902: print("class %s(%s):" % (cls.__name__, ", ".join(bnames))) cmlenz@820: written = False cmlenz@820: for attr in cls.__dict__: cmlenz@820: if attr not in IGNORE_ATTRS: cmlenz@820: written = True cmlenz@902: print("\t%s = %s" % (attr, repr(cls.__dict__[attr]),)) cmlenz@820: if not written: cmlenz@902: print("\tpass") cmlenz@820: done.add(cls) cmlenz@820: cmlenz@902: print('# Generated automatically, please do not edit') cmlenz@902: print('# Generator can be found in Genshi SVN, scripts/ast_generator.py') cmlenz@902: print('') cmlenz@902: print('__version__ = %s' % _ast.__version__) cmlenz@902: print('') cmlenz@820: cmlenz@820: for name in dir(_ast): cmlenz@820: cls = getattr(_ast, name) cmlenz@820: if cls.__class__ is type: cmlenz@820: print_class(cls) cmlenz@820: print