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