File: make_excs.py

package info (click to toggle)
jython 2.2.1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,708 kB
  • ctags: 46,200
  • sloc: python: 150,937; java: 86,267; xml: 1,080; perl: 104; sh: 93; makefile: 81; ansic: 24
file content (88 lines) | stat: -rw-r--r-- 2,114 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""generate code for exceptions and for the types module"""

template1 = '        %(name)s = new PyString("%(name)s");'
template2 = '        dict.__setitem__("%(name)s", Py.%(name)s);'
template3 = '''\
        %(name)s = new PyTuple(new PyObject[]
            {%(values)s});
'''
template4 = '''\
        tmp = exceptions.__findattr__("%(name)s");
        if (tmp != null) %(name)s = tmp;'''
import exceptions, types, string

excs = {}
for name in dir(exceptions):
	c = getattr(exceptions, name)
	try:
		if issubclass(c, exceptions.Exception):
			excs[c] = {}
	except: 
		pass

for key, value in excs.items():
	for base in key.__bases__:
		excs[base][key] = 1
		

import sys
fp = open('c:\\jpython\\JavaCode\\org\\python\\core\\excs.txt', 'w')
sys.stdout = fp

for exc in excs.keys():
	print template4 % {'name': exc.__name__}
	
print 
print

for exc in excs.keys():
	print template2 % {'name': exc.__name__}

print
print
	
for exc, values in excs.items():
	if len(values) == 0:
		print template1 % {'name': exc.__name__}
		
for exc, values in excs.items():
	if len(values) != 0:
		vl = []
		for key in values.keys():
			vl.append('Py.'+key.__name__)
			
		print template3 % {'name': exc.__name__, 	'values':string.join(vl, ', ')}
		

print
print
sys.exit()
temp = """\
	public static PyObject %(name)s;
	public static PyException %(name)s(String message) {
	    return new PyException(Py.%(name)s, message);
	}
"""

for exc, values in excs.items():
	if len(values) == 0:
		print temp % {'name': exc.__name__}


print 
print


types = ['ArrayType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', 'CodeType', 'ComplexType',
 'DictType', 'DictionaryType', 'EllipsisType', 'FileType', 'FloatType', 'FrameType',
  'FunctionType', 'InstanceType', 'IntType', 'LambdaType', 'ListType', 'LongType', 
  'MethodType', 'ModuleType', 'NoneType', 'SliceType', 'StringType', 
  'TracebackType', 'TupleType', 'TypeType', 'UnboundMethodType', 'XRangeType']

line = '\t\tdict.__setitem__("%(name)sType", PyJavaClass.lookup(Py%(name)s.class));'

for name in types:
	name = name[:-4]
	print line % {'name':name}

fp.close()