diff options
author | Guido van Rossum <guido@python.org> | 1998-03-26 21:13:24 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-03-26 21:13:24 (GMT) |
commit | 45e2fbc2e70ef28b1f0327207f33dab3a4e825c5 (patch) | |
tree | 24cafdb6ffb07170188292a02440935291327cde /Lib/rlcompleter.py | |
parent | 9ea7024754f0e42d7fc70fd1c8f6f6cfbf7e1cf0 (diff) | |
download | cpython-45e2fbc2e70ef28b1f0327207f33dab3a4e825c5.zip cpython-45e2fbc2e70ef28b1f0327207f33dab3a4e825c5.tar.gz cpython-45e2fbc2e70ef28b1f0327207f33dab3a4e825c5.tar.bz2 |
Mass check-in after untabifying all files that need it.
Diffstat (limited to 'Lib/rlcompleter.py')
-rw-r--r-- | Lib/rlcompleter.py | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index 4deb0bc..e0ae72c 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -47,60 +47,60 @@ import __main__ class Completer: def complete(self, text, state): - """Return the next possible completion for 'text'. + """Return the next possible completion for 'text'. - This is called successively with state == 0, 1, 2, ... until it - returns None. The completion should begin with 'text'. + This is called successively with state == 0, 1, 2, ... until it + returns None. The completion should begin with 'text'. - """ - if state == 0: - if "." in text: - self.matches = self.attr_matches(text) - else: - self.matches = self.global_matches(text) - return self.matches[state] + """ + if state == 0: + if "." in text: + self.matches = self.attr_matches(text) + else: + self.matches = self.global_matches(text) + return self.matches[state] def global_matches(self, text): - """Compute matches when text is a simple name. - - Return a list of all keywords, built-in functions and names - currently defines in __main__ that match. - - """ - import keyword - matches = [] - n = len(text) - for list in [keyword.kwlist, - __builtin__.__dict__.keys(), - __main__.__dict__.keys()]: - for word in list: - if word[:n] == text: - matches.append(word) - return matches + """Compute matches when text is a simple name. + + Return a list of all keywords, built-in functions and names + currently defines in __main__ that match. + + """ + import keyword + matches = [] + n = len(text) + for list in [keyword.kwlist, + __builtin__.__dict__.keys(), + __main__.__dict__.keys()]: + for word in list: + if word[:n] == text: + matches.append(word) + return matches def attr_matches(self, text): - """Compute matches when text contains a dot. - - Assuming the text is of the form NAME.NAME....[NAME], and is - evaluabable in the globals of __main__, it will be evaluated - and its attributes (as revealed by dir()) are used as possible - completions. - - WARNING: this can still invoke arbitrary C code, if an object - with a __getattr__ hook is evaluated. - - """ - import re - m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) - if not m: - return - expr, attr = m.group(1, 3) - words = dir(eval(expr, __main__.__dict__)) - matches = [] - n = len(attr) - for word in words: - if word[:n] == attr: - matches.append("%s.%s" % (expr, word)) - return matches + """Compute matches when text contains a dot. + + Assuming the text is of the form NAME.NAME....[NAME], and is + evaluabable in the globals of __main__, it will be evaluated + and its attributes (as revealed by dir()) are used as possible + completions. + + WARNING: this can still invoke arbitrary C code, if an object + with a __getattr__ hook is evaluated. + + """ + import re + m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) + if not m: + return + expr, attr = m.group(1, 3) + words = dir(eval(expr, __main__.__dict__)) + matches = [] + n = len(attr) + for word in words: + if word[:n] == attr: + matches.append("%s.%s" % (expr, word)) + return matches readline.set_completer(Completer().complete) |