Mercurial > genshi > mirror
annotate scripts/ast_generator.py @ 906:39f5bfe11d91 experimental-inline
inline branch: move to native svn merge tracking.
author | cmlenz |
---|---|
date | Wed, 28 Apr 2010 21:30:39 +0000 |
parents | fe25855324dd |
children |
rev | line source |
---|---|
820 | 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__': | |
902
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
23 bnames.append("%s" % base.__name__) |
820 | 24 else: |
902
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
25 bnames.append("%s.%s" % (base.__module__,base.__name__)) |
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
26 print("class %s(%s):" % (cls.__name__, ", ".join(bnames))) |
820 | 27 written = False |
28 for attr in cls.__dict__: | |
29 if attr not in IGNORE_ATTRS: | |
30 written = True | |
902
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
31 print("\t%s = %s" % (attr, repr(cls.__dict__[attr]),)) |
820 | 32 if not written: |
902
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
33 print("\tpass") |
820 | 34 done.add(cls) |
35 | |
902
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
36 print('# Generated automatically, please do not edit') |
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
37 print('# Generator can be found in Genshi SVN, scripts/ast_generator.py') |
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
38 print('') |
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
39 print('__version__ = %s' % _ast.__version__) |
fe25855324dd
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
40 print('') |
820 | 41 |
42 for name in dir(_ast): | |
43 cls = getattr(_ast, name) | |
44 if cls.__class__ is type: | |
45 print_class(cls) | |
46 print |