##// END OF EJS Templates
Work to address the review comments on Fernando's branch....
Work to address the review comments on Fernando's branch. * Added comment about Magic(object) (r1224) * Moved InteractiveTB.set_mode from IPythonApp -> InteractiveShell (r1229) * Moved pylabtools.py to IPython/lib (r1229) * Cleaned up comments and copyrights in testing (r1233) * Added comment about ip.shell._ofind (r1237) * Removed "Bye." from quitter (r1240). * Refactored and removed :mod:`IPython.utils.genutils` and :mod:`IPython.utils.platutils`. These modules have been replaced by topical focused modules in :mod:`IPython.utils`. * Refactored tests in :mod:`IPython.utils.tests`. * Moved :func:`IPython.testing.tools.temp_pyfile` to :mod:`IPython.utils.io`. * Moved :func:`IPython.testing.tools.cmd2argv` to :func:`IPython.testing.tools.pycmd2argv` and documented the fact that this only works with Python based command line programs. * Created a new :func:`IPython.utils.path.get_ipython_module_path` to use in finding paths to IPython modules.

File last commit:

r2498:3eae1372
r2498:3eae1372
Show More
ipy_greedycompleter.py
76 lines | 2.2 KiB | text/x-python | PythonLexer
/ IPython / quarantine / ipy_greedycompleter.py
Ville M. Vainio
Add ipy_greedycompleter.py
r1183 """ Greedy completer extension for IPython
Normal tab completer refuses to evaluate nonsafe stuff. This will evaluate
everything, so you need to consider the consequences of pressing tab
yourself!
Note that this extension simplifies readline interaction by setting
only whitespace as completer delimiter. If this works well, we will
do the same in default completer.
"""
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
Brian Granger
Continuing a massive refactor of everything.
r2205 from IPython.core.error import TryNext
Brian Granger
generics.py => utils/generics.py
r2022 from IPython.utils import generics
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 from IPython.utils.dir2 import dir2
Ville M. Vainio
Add ipy_greedycompleter.py
r1183
def attr_matches(self, text):
"""Compute matches when text contains a dot.
MONKEYPATCHED VERSION (ipy_greedycompleter.py)
Assuming the text is of the form NAME.NAME....[NAME], and is
evaluatable in self.namespace or self.global_namespace, it will be
evaluated and its attributes (as revealed by dir()) are used as
possible 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.
"""
import re
force_complete = 1
# Another option, seems to work great. Catches things like ''.<tab>
m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
if m:
expr, attr = m.group(1, 3)
else:
# force match - eval anything that ends with colon
if not force_complete:
return []
m2 = re.match(r"(.+)\.(\w*)$", self.lbuf)
if not m2:
return []
expr, attr = m2.group(1,2)
try:
obj = eval(expr, self.namespace)
except:
try:
obj = eval(expr, self.global_namespace)
except:
return []
words = dir2(obj)
try:
words = generics.complete_object(obj, words)
Brian Granger
Continuing a massive refactor of everything.
r2205 except TryNext:
Ville M. Vainio
Add ipy_greedycompleter.py
r1183 pass
# Build match list to return
n = len(attr)
res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ]
return res
def main():
Brian Granger
rlineimpl.py utils/rlineimpl.py and imports updated.
r2044 import IPython.utils.rlineimpl as readline
Ville M. Vainio
Add ipy_greedycompleter.py
r1183 readline.set_completer_delims(" \n\t")
# monkeypatch - the code will be folded to normal completer later on
Brian Granger
completer.py => core/completer.py and imports updated.
r2012 import IPython.core.completer
IPython.core.completer.Completer.attr_matches = attr_matches
Ville M. Vainio
Add ipy_greedycompleter.py
r1183
main()