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
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
1 #!/usr/bin/env python2.5
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
2
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
3 """Script to that automatically generates genshi/templates/_astpy24.py.
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
4 Be sure to run this with a Python 2.5 interpreter.
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
5 """
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
6
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
7 import _ast
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
8
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
9 done = set()
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
10
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
11 IGNORE_ATTRS = ('__module__', '__dict__', '__weakref__', '__setattr__',
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
12 '__new__', '__getattribute__', '__reduce__', '__delattr__',
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
13 '__init__')
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
14
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
15 def print_class(cls):
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
16 bnames = []
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
17 for base in cls.__bases__:
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
18 if base.__module__ == '_ast':
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
19 if base not in done:
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
20 print_class(base)
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
21 bnames.append(base.__name__)
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
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
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
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
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
27 written = False
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
28 for attr in cls.__dict__:
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
29 if attr not in IGNORE_ATTRS:
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
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
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
32 if not written:
902
fe25855324dd Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
33 print("\tpass")
820
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
34 done.add(cls)
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
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
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
41
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
42 for name in dir(_ast):
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
43 cls = getattr(_ast, name)
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
44 if cls.__class__ is type:
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
45 print_class(cls)
9755836bb396 Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents:
diff changeset
46 print
Copyright (C) 2012-2017 Edgewall Software