annotate Tools/scripts/nm2def.py @ 24042:63fbbed10714 legacy-trunk

Simplify HTTPSConnection constructor. See discussion in SF bug 458463.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 28 Jun 2002 23:38:14 +0000
parents 14a27acc755a
children 8a7a2f1f88f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9281
809dcc1bbc21 Added #! line
Guido van Rossum <guido@python.org>
parents: 9103
diff changeset
1 #! /usr/bin/env python
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 """nm2def.py
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 Helpers to extract symbols from Unix libs and auto-generate
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 Windows definition files from them. Depends on nm(1). Tested
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 on Linux and Solaris only (-p option to nm is for Solaris only).
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 By Marc-Andre Lemburg, Aug 1998.
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 Additional notes: the output of nm is supposed to look like this:
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 acceler.o:
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 000001fd T PyGrammar_AddAccelerators
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 U PyGrammar_FindDFA
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 00000237 T PyGrammar_RemoveAccelerators
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 U _IO_stderr_
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 U exit
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 U fprintf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 U free
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 U malloc
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 U printf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 grammar1.o:
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 00000000 T PyGrammar_FindDFA
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 00000034 T PyGrammar_LabelRepr
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 U _PyParser_TokenNames
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 U abort
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 U printf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 U sprintf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 ...
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 Even if this isn't the default output of your nm, there is generally an
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 option to produce this format (since it is the original v7 Unix format).
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 """
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 import os,re,string,sys
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 PYTHONLIB = 'libpython'+sys.version[:3]+'.a'
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 PC_PYTHONLIB = 'Python'+sys.version[0]+sys.version[2]+'.dll'
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 NM = 'nm -p -g %s' # For Linux, use "nm -g %s"
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 def symbols(lib=PYTHONLIB,types=('T','C','D')):
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 lines = os.popen(NM % lib).readlines()
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 lines = map(string.strip,lines)
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 symbols = {}
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 for line in lines:
9103
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
49 if len(line) == 0 or ':' in line:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
50 continue
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
51 items = string.split(line)
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
52 if len(items) != 3:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
53 continue
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
54 address, type, name = items
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
55 if type not in types:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
56 continue
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
57 symbols[name] = address,type
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 return symbols
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 def export_list(symbols):
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 data = []
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 code = []
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 for name,(addr,type) in symbols.items():
9103
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
65 if type in ('C','D'):
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
66 data.append('\t'+name)
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
67 else:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
68 code.append('\t'+name)
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 data.sort()
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 data.append('')
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 code.sort()
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 return string.join(data,' DATA\n')+'\n'+string.join(code,'\n')
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 # Definition file template
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 DEF_TEMPLATE = """\
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 EXPORTS
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 %s
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 """
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
79
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 # Special symbols that have to be included even though they don't
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 # pass the filter
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 SPECIALS = (
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 )
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 def filter_Python(symbols,specials=SPECIALS):
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 for name in symbols.keys():
9103
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
88 if name[:2] == 'Py' or name[:3] == '_Py':
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
89 pass
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
90 elif name not in specials:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
91 del symbols[name]
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 def main():
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 s = symbols(PYTHONLIB)
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 filter_Python(s)
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 exports = export_list(s)
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 f = sys.stdout # open('PC/python_nt.def','w')
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 f.write(DEF_TEMPLATE % (exports))
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 f.close()
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 9281
diff changeset
101
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 if __name__ == '__main__':
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 main()