summaryrefslogtreecommitdiffstats
path: root/Lib/dos-8x3/rlcomple.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-05-08 17:31:04 (GMT)
committerGuido van Rossum <guido@python.org>2000-05-08 17:31:04 (GMT)
commitaad6761ccea28e0a0da6761570b18adc72e01c37 (patch)
tree731b55d5648f08e1bc755bcace1f836413cd8aae /Lib/dos-8x3/rlcomple.py
parent0b095bc0929fb43157019c50e3e680a29ec94a65 (diff)
downloadcpython-aad6761ccea28e0a0da6761570b18adc72e01c37.zip
cpython-aad6761ccea28e0a0da6761570b18adc72e01c37.tar.gz
cpython-aad6761ccea28e0a0da6761570b18adc72e01c37.tar.bz2
The usual...
Diffstat (limited to 'Lib/dos-8x3/rlcomple.py')
-rw-r--r--Lib/dos-8x3/rlcomple.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/Lib/dos-8x3/rlcomple.py b/Lib/dos-8x3/rlcomple.py
index 92633ab..aa1dd02 100644
--- a/Lib/dos-8x3/rlcomple.py
+++ b/Lib/dos-8x3/rlcomple.py
@@ -1,7 +1,6 @@
"""Word completion for GNU readline 2.0.
This requires the latest extension to the readline module (the
-set_completer() function). When completing a simple identifier, it
completes keywords, built-ins and globals in __main__; when completing
NAME.NAME..., it evaluates (!) the expression up to the last dot and
completes its attributes.
@@ -87,7 +86,8 @@ class Completer:
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.
+ completions. (For class instances, class members are are also
+ considered.)
WARNING: this can still invoke arbitrary C code, if an object
with a __getattr__ hook is evaluated.
@@ -98,7 +98,11 @@ class Completer:
if not m:
return
expr, attr = m.group(1, 3)
- words = dir(eval(expr, __main__.__dict__))
+ object = eval(expr, __main__.__dict__)
+ words = dir(object)
+ if hasattr(object,'__class__'):
+ words.append('__class__')
+ words = words + get_class_members(object.__class__)
matches = []
n = len(attr)
for word in words:
@@ -106,4 +110,11 @@ class Completer:
matches.append("%s.%s" % (expr, word))
return matches
+def get_class_members(klass):
+ ret = dir(klass)
+ if hasattr(klass,'__bases__'):
+ for base in klass.__bases__:
+ ret = ret + get_class_members(base)
+ return ret
+
readline.set_completer(Completer().complete)