Show More
@@ -472,7 +472,7 b' class IPCompleter(Completer):' | |||||
472 |
|
472 | |||
473 | # List where completion matches will be stored |
|
473 | # List where completion matches will be stored | |
474 | self.matches = [] |
|
474 | self.matches = [] | |
475 |
self.shell = shell |
|
475 | self.shell = shell | |
476 | if alias_table is None: |
|
476 | if alias_table is None: | |
477 | alias_table = {} |
|
477 | alias_table = {} | |
478 | self.alias_table = alias_table |
|
478 | self.alias_table = alias_table | |
@@ -602,7 +602,7 b' class IPCompleter(Completer):' | |||||
602 | #print 'Completer->magic_matches:',text,'lb',self.text_until_cursor # dbg |
|
602 | #print 'Completer->magic_matches:',text,'lb',self.text_until_cursor # dbg | |
603 | # Get all shell magics now rather than statically, so magics loaded at |
|
603 | # Get all shell magics now rather than statically, so magics loaded at | |
604 | # runtime show up too |
|
604 | # runtime show up too | |
605 | magics = self.shell.lsmagic() |
|
605 | magics = self.shell._magic.lsmagic() | |
606 | pre = self.magic_escape |
|
606 | pre = self.magic_escape | |
607 | baretext = text.lstrip(pre) |
|
607 | baretext = text.lstrip(pre) | |
608 | return [ pre+m for m in magics if m.startswith(baretext)] |
|
608 | return [ pre+m for m in magics if m.startswith(baretext)] |
@@ -187,7 +187,7 b' class ReadlineNoRecord(object):' | |||||
187 | # Main IPython class |
|
187 | # Main IPython class | |
188 | #----------------------------------------------------------------------------- |
|
188 | #----------------------------------------------------------------------------- | |
189 |
|
189 | |||
190 |
class InteractiveShell(SingletonConfigurable |
|
190 | class InteractiveShell(SingletonConfigurable): | |
191 | """An enhanced, interactive shell for Python.""" |
|
191 | """An enhanced, interactive shell for Python.""" | |
192 |
|
192 | |||
193 | _instance = None |
|
193 | _instance = None | |
@@ -430,7 +430,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
430 | self.init_encoding() |
|
430 | self.init_encoding() | |
431 | self.init_prefilter() |
|
431 | self.init_prefilter() | |
432 |
|
432 | |||
433 | Magic.__init__(self, self) |
|
433 | self._magic = Magic(self) | |
434 |
|
434 | |||
435 | self.init_syntax_highlighting() |
|
435 | self.init_syntax_highlighting() | |
436 | self.init_hooks() |
|
436 | self.init_hooks() | |
@@ -588,11 +588,11 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
588 | """Initialize logging in case it was requested at the command line. |
|
588 | """Initialize logging in case it was requested at the command line. | |
589 | """ |
|
589 | """ | |
590 | if self.logappend: |
|
590 | if self.logappend: | |
591 |
self.magic |
|
591 | self.magic('logstart %s append' % self.logappend) | |
592 | elif self.logfile: |
|
592 | elif self.logfile: | |
593 |
self.magic |
|
593 | self.magic('logstart %' % self.logfile) | |
594 | elif self.logstart: |
|
594 | elif self.logstart: | |
595 |
self.magic |
|
595 | self.magic('logstart') | |
596 |
|
596 | |||
597 | def init_builtins(self): |
|
597 | def init_builtins(self): | |
598 | # A single, static flag that we set to True. Its presence indicates |
|
598 | # A single, static flag that we set to True. Its presence indicates | |
@@ -1397,7 +1397,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
1397 | if not found: |
|
1397 | if not found: | |
1398 | if oname.startswith(ESC_MAGIC): |
|
1398 | if oname.startswith(ESC_MAGIC): | |
1399 | oname = oname[1:] |
|
1399 | oname = oname[1:] | |
1400 |
obj = |
|
1400 | obj = self.find_magic(oname) | |
1401 | if obj is not None: |
|
1401 | if obj is not None: | |
1402 | found = True |
|
1402 | found = True | |
1403 | ospace = 'IPython internal' |
|
1403 | ospace = 'IPython internal' | |
@@ -1996,7 +1996,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
1996 | # FIXME: Move the color initialization to the DisplayHook, which |
|
1996 | # FIXME: Move the color initialization to the DisplayHook, which | |
1997 | # should be split into a prompt manager and displayhook. We probably |
|
1997 | # should be split into a prompt manager and displayhook. We probably | |
1998 | # even need a centralize colors management object. |
|
1998 | # even need a centralize colors management object. | |
1999 |
self.magic |
|
1999 | self.magic('colors %s' % self.colors) | |
2000 | # History was moved to a separate module |
|
2000 | # History was moved to a separate module | |
2001 | from IPython.core import history |
|
2001 | from IPython.core import history | |
2002 | history.init_ipython(self) |
|
2002 | history.init_ipython(self) | |
@@ -2026,11 +2026,11 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2026 | magic_name, _, magic_args = arg_s.partition(' ') |
|
2026 | magic_name, _, magic_args = arg_s.partition(' ') | |
2027 | magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) |
|
2027 | magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) | |
2028 |
|
2028 | |||
2029 |
fn = |
|
2029 | fn = self.find_magic(magic_name) | |
2030 | if fn is None: |
|
2030 | if fn is None: | |
2031 | error("Magic function `%s` not found." % magic_name) |
|
2031 | error("Magic function `%s` not found." % magic_name) | |
2032 | else: |
|
2032 | else: | |
2033 | magic_args = self.var_expand(magic_args,1) |
|
2033 | magic_args = self.var_expand(magic_args, 1) | |
2034 | # Grab local namespace if we need it: |
|
2034 | # Grab local namespace if we need it: | |
2035 | if getattr(fn, "needs_local_scope", False): |
|
2035 | if getattr(fn, "needs_local_scope", False): | |
2036 | self._magic_locals = sys._getframe(1).f_locals |
|
2036 | self._magic_locals = sys._getframe(1).f_locals | |
@@ -2040,7 +2040,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2040 | self._magic_locals = {} |
|
2040 | self._magic_locals = {} | |
2041 | return result |
|
2041 | return result | |
2042 |
|
2042 | |||
2043 | def define_magic(self, magicname, func): |
|
2043 | def define_magic(self, magic_name, func): | |
2044 | """Expose own function as magic function for ipython |
|
2044 | """Expose own function as magic function for ipython | |
2045 |
|
2045 | |||
2046 | Example:: |
|
2046 | Example:: | |
@@ -2054,10 +2054,15 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2054 | ip.define_magic('foo',foo_impl) |
|
2054 | ip.define_magic('foo',foo_impl) | |
2055 | """ |
|
2055 | """ | |
2056 | im = types.MethodType(func,self) |
|
2056 | im = types.MethodType(func,self) | |
2057 |
old = |
|
2057 | old = self.find_magic(magic_name) | |
2058 |
setattr(self, |
|
2058 | setattr(self._magic, 'magic_' + magic_name, im) | |
2059 | return old |
|
2059 | return old | |
2060 |
|
2060 | |||
|
2061 | def find_magic(self, magic_name): | |||
|
2062 | """Find and return a magic function by name. | |||
|
2063 | """ | |||
|
2064 | return getattr(self._magic, 'magic_' + magic_name, None) | |||
|
2065 | ||||
2061 | #------------------------------------------------------------------------- |
|
2066 | #------------------------------------------------------------------------- | |
2062 | # Things related to macros |
|
2067 | # Things related to macros | |
2063 | #------------------------------------------------------------------------- |
|
2068 | #------------------------------------------------------------------------- | |
@@ -2685,7 +2690,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2685 | # Now we must activate the gui pylab wants to use, and fix %run to take |
|
2690 | # Now we must activate the gui pylab wants to use, and fix %run to take | |
2686 | # plot updates into account |
|
2691 | # plot updates into account | |
2687 | self.enable_gui(gui) |
|
2692 | self.enable_gui(gui) | |
2688 | self.magic_run = self._pylab_magic_run |
|
2693 | self._magic.magic_run = self._pylab_magic_run | |
2689 |
|
2694 | |||
2690 | #------------------------------------------------------------------------- |
|
2695 | #------------------------------------------------------------------------- | |
2691 | # Utilities |
|
2696 | # Utilities |
@@ -107,7 +107,7 b' class MacroToEdit(ValueError): pass' | |||||
107 | # Configurable. This messes up the MRO in some way. The fix is that we need to |
|
107 | # Configurable. This messes up the MRO in some way. The fix is that we need to | |
108 | # make Magic a configurable that InteractiveShell does not subclass. |
|
108 | # make Magic a configurable that InteractiveShell does not subclass. | |
109 |
|
109 | |||
110 | class Magic: |
|
110 | class Magic(object): | |
111 | """Magic functions for InteractiveShell. |
|
111 | """Magic functions for InteractiveShell. | |
112 |
|
112 | |||
113 | Shell functions which can be reached as %function_name. All magic |
|
113 | Shell functions which can be reached as %function_name. All magic | |
@@ -127,7 +127,7 b' class Magic:' | |||||
127 | #...................................................................... |
|
127 | #...................................................................... | |
128 | # some utility functions |
|
128 | # some utility functions | |
129 |
|
129 | |||
130 | def __init__(self,shell): |
|
130 | def __init__(self, shell): | |
131 |
|
131 | |||
132 | self.options_table = {} |
|
132 | self.options_table = {} | |
133 | if profile is None: |
|
133 | if profile is None: | |
@@ -3012,7 +3012,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3012 | # jump to bookmark if needed |
|
3012 | # jump to bookmark if needed | |
3013 | else: |
|
3013 | else: | |
3014 | if not os.path.isdir(ps) or opts.has_key('b'): |
|
3014 | if not os.path.isdir(ps) or opts.has_key('b'): | |
3015 | bkms = self.db.get('bookmarks', {}) |
|
3015 | bkms = self.shell.db.get('bookmarks', {}) | |
3016 |
|
3016 | |||
3017 | if bkms.has_key(ps): |
|
3017 | if bkms.has_key(ps): | |
3018 | target = bkms[ps] |
|
3018 | target = bkms[ps] | |
@@ -3049,7 +3049,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3049 |
|
3049 | |||
3050 | if oldcwd != cwd: |
|
3050 | if oldcwd != cwd: | |
3051 | dhist.append(cwd) |
|
3051 | dhist.append(cwd) | |
3052 | self.db['dhist'] = compress_dhist(dhist)[-100:] |
|
3052 | self.shell.db['dhist'] = compress_dhist(dhist)[-100:] | |
3053 | if not 'q' in opts and self.shell.user_ns['_dh']: |
|
3053 | if not 'q' in opts and self.shell.user_ns['_dh']: | |
3054 | print self.shell.user_ns['_dh'][-1] |
|
3054 | print self.shell.user_ns['_dh'][-1] | |
3055 |
|
3055 |
@@ -133,7 +133,7 b' class LineInfo(object):' | |||||
133 | """ |
|
133 | """ | |
134 | if not self._oinfo: |
|
134 | if not self._oinfo: | |
135 | # ip.shell._ofind is actually on the Magic class! |
|
135 | # ip.shell._ofind is actually on the Magic class! | |
136 |
self._oinfo = ip. |
|
136 | self._oinfo = ip._ofind(self.ifun) | |
137 | return self._oinfo |
|
137 | return self._oinfo | |
138 |
|
138 | |||
139 | def __str__(self): |
|
139 | def __str__(self): |
General Comments 0
You need to be logged in to leave comments.
Login now