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