Mercurial > mm7
comparison lib/swig/swigwin-2.0.11/Tools/pyname_patch.py @ 1899:b3009adc0e2f
Adding swig, gitignore, hgignore
author | Nomad |
---|---|
date | Mon, 21 Oct 2013 10:42:27 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1867:eb580660bbbb | 1899:b3009adc0e2f |
---|---|
1 #!/usr/bin/env python | |
2 """ | |
3 From SWIG 1.3.37 we deprecated all SWIG symbols that start with Py, | |
4 since they are inappropriate and discouraged in Python documentation | |
5 (from http://www.python.org/doc/2.5.2/api/includes.html): | |
6 | |
7 "All user visible names defined by Python.h (except those defined by the included | |
8 standard headers) have one of the prefixes "Py" or "_Py". Names beginning with | |
9 "_Py" are for internal use by the Python implementation and should not be used | |
10 by extension writers. Structure member names do not have a reserved prefix. | |
11 | |
12 Important: user code should never define names that begin with "Py" or "_Py". | |
13 This confuses the reader, and jeopardizes the portability of the user code to | |
14 future Python versions, which may define additional names beginning with one | |
15 of these prefixes." | |
16 | |
17 This file is a simple script used for change all of these symbols, for user code | |
18 or SWIG itself. | |
19 """ | |
20 import re | |
21 from shutil import copyfile | |
22 import sys | |
23 | |
24 symbols = [ | |
25 #(old name, new name) | |
26 ("PySequence_Base", "SwigPySequence_Base"), | |
27 ("PySequence_Cont", "SwigPySequence_Cont"), | |
28 ("PySwigIterator_T", "SwigPyIterator_T"), | |
29 ("PyPairBoolOutputIterator", "SwigPyPairBoolOutputIterator"), | |
30 ("PySwigIterator", "SwigPyIterator"), | |
31 ("PySwigIterator_T", "SwigPyIterator_T"), | |
32 ("PyMapIterator_T", "SwigPyMapIterator_T"), | |
33 ("PyMapKeyIterator_T", "SwigPyMapKeyIterator_T"), | |
34 ("PyMapValueIterator_T", "SwigPyMapValueITerator_T"), | |
35 ("PyObject_ptr", "SwigPtr_PyObject"), | |
36 ("PyObject_var", "SwigVar_PyObject"), | |
37 ("PyOper", "SwigPyOper"), | |
38 ("PySeq", "SwigPySeq"), | |
39 ("PySequence_ArrowProxy", "SwigPySequence_ArrowProxy"), | |
40 ("PySequence_Cont", "SwigPySequence_Cont"), | |
41 ("PySequence_InputIterator", "SwigPySequence_InputIterator"), | |
42 ("PySequence_Ref", "SwigPySequence_Ref"), | |
43 ("PySwigClientData", "SwigPyClientData"), | |
44 ("PySwigClientData_Del", "SwigPyClientData_Del"), | |
45 ("PySwigClientData_New", "SwigPyClientData_New"), | |
46 ("PySwigIterator", "SwigPyIterator"), | |
47 ("PySwigIteratorClosed_T", "SwigPyIteratorClosed_T"), | |
48 ("PySwigIteratorOpen_T", "SwigPyIteratorOpen_T"), | |
49 ("PySwigIterator_T", "SwigPyIterator_T"), | |
50 ("PySwigObject", "SwigPyObject"), | |
51 ("PySwigObject_Check", "SwigPyObject_Check"), | |
52 ("PySwigObject_GetDesc", "SwigPyObject_GetDesc"), | |
53 ("PySwigObject_New", "SwigPyObject_New"), | |
54 ("PySwigObject_acquire", "SwigPyObject_acquire"), | |
55 ("PySwigObject_append", "SwigPyObject_append"), | |
56 ("PySwigObject_as_number", "SwigPyObject_as_number"), | |
57 ("PySwigObject_compare", "SwigPyObject_compare"), | |
58 ("PySwigObject_dealloc", "SwigPyObject_dealloc"), | |
59 ("PySwigObject_disown", "SwigPyObject_disown"), | |
60 ("PySwigObject_format", "SwigPyObject_format"), | |
61 ("PySwigObject_getattr", "SwigPyObject_getattr"), | |
62 ("PySwigObject_hex", "SwigPyObject_hex"), | |
63 ("PySwigObject_long", "SwigPyObject_long"), | |
64 ("PySwigObject_next", "SwigPyObject_next"), | |
65 ("PySwigObject_oct", "SwigPyObject_oct"), | |
66 ("PySwigObject_own", "SwigPyObject_own"), | |
67 ("PySwigObject_print", "SwigPyObject_print"), | |
68 ("PySwigObject_repr", "SwigPyObject_repr"), | |
69 ("PySwigObject_richcompare", "SwigPyObject_richcompare"), | |
70 ("PySwigObject_str", "SwigPyObject_str"), | |
71 ("PySwigObject_type", "SwigPyObject_type"), | |
72 ("PySwigPacked", "SwigPyPacked"), | |
73 ("PySwigPacked_Check", "SwigPyPacked_Check"), | |
74 ("PySwigPacked_New", "SwigPyPacked_New"), | |
75 ("PySwigPacked_UnpackData", "SwigPyPacked_UnpackData"), | |
76 ("PySwigPacked_compare", "SwigPyPacked_compare"), | |
77 ("PySwigPacked_dealloc", "SwigPyPacked_dealloc"), | |
78 ("PySwigPacked_print", "SwigPyPacked_print"), | |
79 ("PySwigPacked_repr", "SwigPyPacked_repr"), | |
80 ("PySwigPacked_str", "SwigPyPacked_str"), | |
81 ("PySwigPacked_type", "SwigPyPacked_type"), | |
82 ("pyseq", "swigpyseq"), | |
83 ("pyswigobject_type", "swigpyobject_type"), | |
84 ("pyswigpacked_type", "swigpypacked_type"), | |
85 ] | |
86 | |
87 res = [(re.compile("\\b(%s)\\b"%oldname), newname) for oldname, newname in symbols] | |
88 | |
89 def patch_file(fn): | |
90 newf = [] | |
91 changed = False | |
92 for line in open(fn): | |
93 for r, newname in res: | |
94 line, n = r.subn(newname, line) | |
95 if n>0: | |
96 changed = True | |
97 newf.append(line) | |
98 | |
99 if changed: | |
100 copyfile(fn, fn+".bak") | |
101 f = open(fn, "w") | |
102 f.write("".join(newf)) | |
103 f.close() | |
104 return changed | |
105 | |
106 def main(fns): | |
107 for fn in fns: | |
108 try: | |
109 if patch_file(fn): | |
110 print "Patched file", fn | |
111 except IOError: | |
112 print "Error occurred during patching", fn | |
113 return | |
114 | |
115 if __name__=="__main__": | |
116 if len(sys.argv) > 1: | |
117 main(sys.argv[1:]) | |
118 else: | |
119 print "Patch your interface file for SWIG's Py* symbol name deprecation." | |
120 print "Usage:" | |
121 print " %s files..."%sys.argv[0] | |
122 | |
123 |