|
1 # Copyright (C) 2005, Giovanni Bajo |
|
2 # Based on previous work under copyright (c) 2001, 2002 McMillan Enterprises, Inc. |
|
3 # |
|
4 # This program is free software; you can redistribute it and/or |
|
5 # modify it under the terms of the GNU General Public License |
|
6 # as published by the Free Software Foundation; either version 2 |
|
7 # of the License, or (at your option) any later version. |
|
8 # |
|
9 # This program is distributed in the hope that it will be useful, |
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 # GNU General Public License for more details. |
|
13 # |
|
14 # You should have received a copy of the GNU General Public License |
|
15 # along with this program; if not, write to the Free Software |
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
17 import sys, string |
|
18 |
|
19 def hook(mod): |
|
20 names = sys.builtin_module_names |
|
21 if 'posix' in names: |
|
22 removes = ['nt', 'ntpath', 'dos', 'dospath', 'os2', 'mac', 'macpath', |
|
23 'ce', 'riscos', 'riscospath', 'win32api', 'riscosenviron'] |
|
24 elif 'nt' in names: |
|
25 removes = ['dos', 'dospath', 'os2', 'mac', 'macpath', 'ce', 'riscos', |
|
26 'riscospath', 'riscosenviron',] |
|
27 elif 'os2' in names: |
|
28 removes = ['nt', 'dos', 'dospath', 'mac', 'macpath', 'win32api', 'ce', |
|
29 'riscos', 'riscospath', 'riscosenviron',] |
|
30 elif 'dos' in names: |
|
31 removes = ['nt', 'ntpath', 'os2', 'mac', 'macpath', 'win32api', 'ce', |
|
32 'riscos', 'riscospath', 'riscosenviron',] |
|
33 elif 'mac' in names: |
|
34 removes = ['nt', 'ntpath', 'dos', 'dospath', 'os2', 'win32api', 'ce', |
|
35 'riscos', 'riscospath', 'riscosenviron',] |
|
36 for i in range(len(mod.imports)-1, -1, -1): |
|
37 nm = mod.imports[i][0] |
|
38 pos = string.find(nm, '.') |
|
39 if pos > -1: |
|
40 nm = nm[:pos] |
|
41 if nm in removes : |
|
42 del mod.imports[i] |
|
43 return mod |
|
44 |