1 # Copyright 2000-2004 Michael Hudson mwh@python.net
6 # Permission to use, copy, modify, and distribute this software and
7 # its documentation for any purpose is hereby granted without fee,
8 # provided that the above copyright notice appear in all copies and
9 # that both that copyright notice and this permission notice appear in
10 # supporting documentation.
12 # THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
13 # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14 # AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
15 # INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
16 # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
17 # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 from pyrepl
.completing_reader
import uniqify
23 # for the completion support.
24 # this is all quite nastily written.
27 def _make_module_list_dir(dir, suffs
, prefix
=''):
29 for fname
in os
.listdir(dir):
30 file = os
.path
.join(dir, fname
)
31 if os
.path
.isfile(file):
33 if fname
.endswith(suff
):
34 l
.append( prefix
+ fname
[:-len(suff
)] )
36 elif os
.path
.isdir(file) \
37 and os
.path
.exists(os
.path
.join(file, "__init__.py")):
38 l
.append( prefix
+ fname
)
39 _packages
[prefix
+ fname
] = _make_module_list_dir(
40 file, suffs
, prefix
+ fname
+ '.' )
45 def _make_module_list():
47 suffs
= [x
[0] for x
in imp
.get_suffixes() if x
[0] != '.pyc']
49 c
= -cmp(len(x
), len(y
))
55 _packages
[''] = list(sys
.builtin_module_names
)
59 if os
.path
.isdir(dir):
60 _packages
[''] += _make_module_list_dir(dir, suffs
)
63 def find_modules(stem
):
65 pack
= '.'.join(l
[:-1])
67 mods
= _packages
[pack
]
69 raise ImportError, "can't find \"%s\" package"%pack
70 return [mod
for mod
in mods
if mod
.startswith(stem
)]