##// END OF EJS Templates
Close http://www.scipy.net/roundup/ipython/issue34 with slightly modified...
fperez -
r3:22db71d2
parent child
Show More
@@ -84,6 +84,13 import __main__
84
84
85 __all__ = ["Completer"]
85 __all__ = ["Completer"]
86
86
87 # declares Python 2.2 compatibility symbols:
88 try:
89 basestring
90 except NameError:
91 import types
92 basestring = (types.StringType, types.UnicodeType)
93
87 class Completer:
94 class Completer:
88 def __init__(self, namespace = None):
95 def __init__(self, namespace = None):
89 """Create a new completer for the command line.
96 """Create a new completer for the command line.
@@ -171,21 +178,15 class Completer:
171 return []
178 return []
172 expr, attr = m.group(1, 3)
179 expr, attr = m.group(1, 3)
173 object = eval(expr, self.namespace)
180 object = eval(expr, self.namespace)
174 words = dir(object)
181 words = [w for w in dir(object) if isinstance(w, basestring)]
175 if hasattr(object,'__class__'):
182 if hasattr(object,'__class__'):
176 words.append('__class__')
183 words.append('__class__')
177 words.extend(get_class_members(object.__class__))
184 words.extend(get_class_members(object.__class__))
178 n = len(attr)
185 n = len(attr)
179 matches = []
186 matches = []
180 for word in words:
187 for word in words:
181 try:
188 if word[:n] == attr and word != "__builtins__":
182 if word[:n] == attr and word != "__builtins__":
189 matches.append("%s.%s" % (expr, word))
183 matches.append("%s.%s" % (expr, word))
184 except:
185 # some badly behaved objects pollute dir() with non-strings,
186 # which cause the completion to fail. This way we skip the
187 # bad entries and can still continue processing the others.
188 pass
189 return matches
190 return matches
190
191
191 def get_class_members(klass):
192 def get_class_members(klass):
General Comments 0
You need to be logged in to leave comments. Login now