Mercurial > genshi > mirror
comparison scripts/ast_generator.py @ 794:f9e23d472a6e trunk
Merged AST branch back into trunk. Most of this code was written by Marcin Kurczych for his Google Summer of Code 2008 project. The merge of this branch means that Genshi now uses the native `_ast` module on Python >= 2.5, and an emulation thereof on Python 2.4. This replaces the usage of the `compiler` package, which was deprecated in Python 2.6 and removed in Python 3.0. Another effect is that Genshi now runs on Google AppEngine (although performance is bad due to the lack of template caching).
author | cmlenz |
---|---|
date | Tue, 16 Dec 2008 23:02:36 +0000 |
parents | |
children | f33ecf3c319e fe25855324dd |
comparison
equal
deleted
inserted
replaced
793:be88c77839fc | 794:f9e23d472a6e |
---|---|
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 |