Show More
@@ -69,11 +69,10 b' from IPython.core.error import TryNext' | |||||
69 | from IPython.core.inputsplitter import ESC_MAGIC |
|
69 | from IPython.core.inputsplitter import ESC_MAGIC | |
70 | from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol |
|
70 | from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol | |
71 | from IPython.utils import generics |
|
71 | from IPython.utils import generics | |
72 | from IPython.utils import io |
|
|||
73 | from IPython.utils.decorators import undoc |
|
72 | from IPython.utils.decorators import undoc | |
74 | from IPython.utils.dir2 import dir2, get_real_method |
|
73 | from IPython.utils.dir2 import dir2, get_real_method | |
75 | from IPython.utils.process import arg_split |
|
74 | from IPython.utils.process import arg_split | |
76 | from IPython.utils.py3compat import builtin_mod, string_types, PY3 |
|
75 | from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2 | |
77 | from traitlets import CBool, Enum |
|
76 | from traitlets import CBool, Enum | |
78 |
|
77 | |||
79 | #----------------------------------------------------------------------------- |
|
78 | #----------------------------------------------------------------------------- | |
@@ -348,7 +347,7 b' class Completer(Configurable):' | |||||
348 | for word in lst: |
|
347 | for word in lst: | |
349 | if word[:n] == text and word != "__builtins__": |
|
348 | if word[:n] == text and word != "__builtins__": | |
350 | match_append(word) |
|
349 | match_append(word) | |
351 | return matches |
|
350 | return [cast_unicode_py2(m) for m in matches] | |
352 |
|
351 | |||
353 | def attr_matches(self, text): |
|
352 | def attr_matches(self, text): | |
354 | """Compute matches when text contains a dot. |
|
353 | """Compute matches when text contains a dot. | |
@@ -401,8 +400,7 b' class Completer(Configurable):' | |||||
401 | pass |
|
400 | pass | |
402 | # Build match list to return |
|
401 | # Build match list to return | |
403 | n = len(attr) |
|
402 | n = len(attr) | |
404 |
re |
|
403 | return [u"%s.%s" % (expr, w) for w in words if w[:n] == attr ] | |
405 | return res |
|
|||
406 |
|
404 | |||
407 |
|
405 | |||
408 | def get__all__entries(obj): |
|
406 | def get__all__entries(obj): | |
@@ -412,7 +410,7 b' def get__all__entries(obj):' | |||||
412 | except: |
|
410 | except: | |
413 | return [] |
|
411 | return [] | |
414 |
|
412 | |||
415 | return [w for w in words if isinstance(w, string_types)] |
|
413 | return [cast_unicode_py2(w) for w in words if isinstance(w, string_types)] | |
416 |
|
414 | |||
417 |
|
415 | |||
418 | def match_dict_keys(keys, prefix, delims): |
|
416 | def match_dict_keys(keys, prefix, delims): | |
@@ -682,9 +680,9 b' class IPCompleter(Completer):' | |||||
682 | # when escaped with backslash |
|
680 | # when escaped with backslash | |
683 | if text.startswith('!'): |
|
681 | if text.startswith('!'): | |
684 | text = text[1:] |
|
682 | text = text[1:] | |
685 | text_prefix = '!' |
|
683 | text_prefix = u'!' | |
686 | else: |
|
684 | else: | |
687 | text_prefix = '' |
|
685 | text_prefix = u'' | |
688 |
|
686 | |||
689 | text_until_cursor = self.text_until_cursor |
|
687 | text_until_cursor = self.text_until_cursor | |
690 | # track strings with open quotes |
|
688 | # track strings with open quotes | |
@@ -715,7 +713,7 b' class IPCompleter(Completer):' | |||||
715 | text = os.path.expanduser(text) |
|
713 | text = os.path.expanduser(text) | |
716 |
|
714 | |||
717 | if text == "": |
|
715 | if text == "": | |
718 | return [text_prefix + protect_filename(f) for f in self.glob("*")] |
|
716 | return [cast_unicode_py2(text_prefix + protect_filename(f)) for f in self.glob("*")] | |
719 |
|
717 | |||
720 | # Compute the matches from the filesystem |
|
718 | # Compute the matches from the filesystem | |
721 | m0 = self.clean_glob(text.replace('\\','')) |
|
719 | m0 = self.clean_glob(text.replace('\\','')) | |
@@ -737,11 +735,8 b' class IPCompleter(Completer):' | |||||
737 | matches = [text_prefix + |
|
735 | matches = [text_prefix + | |
738 | protect_filename(f) for f in m0] |
|
736 | protect_filename(f) for f in m0] | |
739 |
|
737 | |||
740 | #io.rprint('mm', matches) # dbg |
|
|||
741 |
|
||||
742 | # Mark directories in input list by appending '/' to their names. |
|
738 | # Mark directories in input list by appending '/' to their names. | |
743 |
|
|
739 | return [cast_unicode_py2(x+'/') if os.path.isdir(x) else x for x in matches] | |
744 | return matches |
|
|||
745 |
|
740 | |||
746 | def magic_matches(self, text): |
|
741 | def magic_matches(self, text): | |
747 | """Match magics""" |
|
742 | """Match magics""" | |
@@ -763,9 +758,9 b' class IPCompleter(Completer):' | |||||
763 | comp = [ pre2+m for m in cell_magics if m.startswith(bare_text)] |
|
758 | comp = [ pre2+m for m in cell_magics if m.startswith(bare_text)] | |
764 | if not text.startswith(pre2): |
|
759 | if not text.startswith(pre2): | |
765 | comp += [ pre+m for m in line_magics if m.startswith(bare_text)] |
|
760 | comp += [ pre+m for m in line_magics if m.startswith(bare_text)] | |
766 | return comp |
|
761 | return [cast_unicode_py2(c) for c in comp] | |
767 |
|
762 | |||
768 | def python_matches(self,text): |
|
763 | def python_matches(self, text): | |
769 | """Match attributes or global python names""" |
|
764 | """Match attributes or global python names""" | |
770 |
|
765 | |||
771 | #io.rprint('Completer->python_matches, txt=%r' % text) # dbg |
|
766 | #io.rprint('Completer->python_matches, txt=%r' % text) # dbg | |
@@ -787,7 +782,6 b' class IPCompleter(Completer):' | |||||
787 | matches = [] |
|
782 | matches = [] | |
788 | else: |
|
783 | else: | |
789 | matches = self.global_matches(text) |
|
784 | matches = self.global_matches(text) | |
790 |
|
||||
791 | return matches |
|
785 | return matches | |
792 |
|
786 | |||
793 | def _default_arguments_from_docstring(self, doc): |
|
787 | def _default_arguments_from_docstring(self, doc): | |
@@ -916,7 +910,7 b' class IPCompleter(Completer):' | |||||
916 |
|
910 | |||
917 | for namedArg in namedArgs: |
|
911 | for namedArg in namedArgs: | |
918 | if namedArg.startswith(text): |
|
912 | if namedArg.startswith(text): | |
919 | argMatches.append("%s=" %namedArg) |
|
913 | argMatches.append(u"%s=" %namedArg) | |
920 | return argMatches |
|
914 | return argMatches | |
921 |
|
915 | |||
922 | def dict_key_matches(self, text): |
|
916 | def dict_key_matches(self, text): | |
@@ -1075,7 +1069,6 b' class IPCompleter(Completer):' | |||||
1075 | return u'', [] |
|
1069 | return u'', [] | |
1076 |
|
1070 | |||
1077 | def dispatch_custom_completer(self, text): |
|
1071 | def dispatch_custom_completer(self, text): | |
1078 | #io.rprint("Custom! '%s' %s" % (text, self.custom_completers)) # dbg |
|
|||
1079 | line = self.line_buffer |
|
1072 | line = self.line_buffer | |
1080 | if not line.strip(): |
|
1073 | if not line.strip(): | |
1081 | return None |
|
1074 | return None | |
@@ -1101,17 +1094,16 b' class IPCompleter(Completer):' | |||||
1101 | for c in itertools.chain(self.custom_completers.s_matches(cmd), |
|
1094 | for c in itertools.chain(self.custom_completers.s_matches(cmd), | |
1102 | try_magic, |
|
1095 | try_magic, | |
1103 | self.custom_completers.flat_matches(self.text_until_cursor)): |
|
1096 | self.custom_completers.flat_matches(self.text_until_cursor)): | |
1104 | #print "try",c # dbg |
|
|||
1105 | try: |
|
1097 | try: | |
1106 | res = c(event) |
|
1098 | res = c(event) | |
1107 | if res: |
|
1099 | if res: | |
1108 | # first, try case sensitive match |
|
1100 | # first, try case sensitive match | |
1109 | withcase = [r for r in res if r.startswith(text)] |
|
1101 | withcase = [cast_unicode_py2(r) for r in res if r.startswith(text)] | |
1110 | if withcase: |
|
1102 | if withcase: | |
1111 | return withcase |
|
1103 | return withcase | |
1112 | # if none, then case insensitive ones are ok too |
|
1104 | # if none, then case insensitive ones are ok too | |
1113 | text_low = text.lower() |
|
1105 | text_low = text.lower() | |
1114 | return [r for r in res if r.lower().startswith(text_low)] |
|
1106 | return [cast_unicode_py2(r) for r in res if r.lower().startswith(text_low)] | |
1115 | except TryNext: |
|
1107 | except TryNext: | |
1116 | pass |
|
1108 | pass | |
1117 |
|
1109 |
General Comments 0
You need to be logged in to leave comments.
Login now