##// END OF EJS Templates
Remove next_input nonsense in magic calls (but keep functionality).
Remove next_input nonsense in magic calls (but keep functionality).

File last commit:

r6974:3f192dc6
r6974:3f192dc6
Show More
magic.py
435 lines | 15.9 KiB | text/x-python | PythonLexer
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 # encoding: utf-8
Ville M. Vainio
crlf -> lf
r1032 """Magic functions for InteractiveShell.
Fernando Perez
Remove svn-style $Id marks from docstrings and Release imports....
r1853 """
Ville M. Vainio
crlf -> lf
r1032
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #-----------------------------------------------------------------------------
# Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 # Copyright (C) 2001 Fernando Perez <fperez@colorado.edu>
# Copyright (C) 2008 The IPython Development Team
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Ville M. Vainio
crlf -> lf
r1032 # Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #-----------------------------------------------------------------------------
Ville M. Vainio
crlf -> lf
r1032
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 # Stdlib
Ville M. Vainio
crlf -> lf
r1032 import os
import re
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 import sys
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 import types
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 from getopt import getopt, GetoptError
# Our own
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 from IPython.config.configurable import Configurable
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 from IPython.core import oinspect
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 from IPython.core.error import UsageError
Brian Granger
Massive refactoring of of the core....
r2245 from IPython.core.prefilter import ESC_MAGIC
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 from IPython.external.decorator import decorator
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 from IPython.utils.ipstruct import Struct
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 from IPython.utils.process import arg_split
Fernando Perez
Add all decorators to tag magics....
r6922 from IPython.utils.traitlets import Bool, Dict, Instance
Fernando Perez
Settle on cleaner API for magic registration....
r6936 from IPython.utils.warn import error, warn
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
Fernando Perez
Add all decorators to tag magics....
r6922
# A dict we'll use for each class that has magics, used as temporary storage to
# pass information between the @line/cell_magic method decorators and the
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 # @magics_class class decorator, because the method decorators have no
Fernando Perez
Add all decorators to tag magics....
r6922 # access to the class when they run. See for more details:
# http://stackoverflow.com/questions/2366713/can-a-python-decorator-of-an-instance-method-access-the-class
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 magics = dict(line={}, cell={})
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 magic_kinds = ('line', 'cell')
Fernando Perez
First working version of cell magic support.
r6953 magic_spec = ('line', 'cell', 'line_cell')
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #-----------------------------------------------------------------------------
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 # Utility classes and functions
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #-----------------------------------------------------------------------------
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 class Bunch: pass
Ville M. Vainio
crlf -> lf
r1032 def on_off(tag):
"""Return an ON/OFF string for a 1/0 input. Simple utility function."""
return ['OFF','ON'][tag]
def compress_dhist(dh):
head, tail = dh[:-10], dh[-10:]
newhead = []
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/284660...
r1860 done = set()
Ville M. Vainio
crlf -> lf
r1032 for h in head:
if h in done:
continue
newhead.append(h)
done.add(h)
Bernardo B. Marques
remove all trailling spaces
r4872 return newhead + tail
Fernando Perez
Initial support for %pylab magic to load pylab at runtime....
r2358
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917
Thomas Kluyver
Refine implementation, so that local scope is only used if a function needs it.
r3479 def needs_local_scope(func):
"""Decorator to mark magic functions which need to local scope to run."""
func.needs_local_scope = True
return func
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 #-----------------------------------------------------------------------------
# Class and method decorators for registering magics
#-----------------------------------------------------------------------------
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 def magics_class(cls):
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 cls.registered = True
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 cls.magics = dict(line = magics['line'],
cell = magics['cell'])
magics['line'] = {}
magics['cell'] = {}
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 return cls
Fernando Perez
First working version of cell magic support.
r6953
def record_magic(dct, mtype, mname, func):
Fernando Perez
Clean up magic registration api and make it public.
r6933 if mtype == 'line_cell':
dct['line'][mname] = dct['cell'][mname] = func
else:
dct[mtype][mname] = func
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919
Fernando Perez
First working version of cell magic support.
r6953
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 def validate_type(magic_kind):
if magic_kind not in magic_spec:
raise ValueError('magic_kind must be one of %s, %s given' %
magic_kinds, magic_kind)
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919
Fernando Perez
Add all decorators to tag magics....
r6922
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 def _magic_marker(magic_kind):
validate_type(magic_kind)
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 # This is a closure to capture the magic_kind. We could also use a class,
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 # but it's overkill for just that one bit of state.
def magic_deco(arg):
call = lambda f, *a, **k: f(*a, **k)
if callable(arg):
# "Naked" decorator call (just @foo, no args)
func = arg
name = func.func_name
func.magic_name = name
retval = decorator(call, func)
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 record_magic(magics, magic_kind, name, name)
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 elif isinstance(arg, basestring):
# Decorator called with arguments (@foo('bar'))
name = arg
def mark(func, *a, **kw):
func.magic_name = name
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 record_magic(magics, magic_kind, name, func.func_name)
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 return decorator(call, func)
retval = mark
else:
raise ValueError("Decorator can only be called with "
"string or function")
Fernando Perez
Create decorators for standalone magic functions, as per review.x
r6972 return retval
return magic_deco
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 def _function_magic_marker(magic_kind):
validate_type(magic_kind)
Fernando Perez
Create decorators for standalone magic functions, as per review.x
r6972
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 # This is a closure to capture the magic_kind. We could also use a class,
Fernando Perez
Create decorators for standalone magic functions, as per review.x
r6972 # but it's overkill for just that one bit of state.
def magic_deco(arg):
call = lambda f, *a, **k: f(*a, **k)
# Find get_ipython() in the caller's namespace
caller = sys._getframe(1)
for ns in ['f_locals', 'f_globals', 'f_builtins']:
get_ipython = getattr(caller, ns).get('get_ipython')
if get_ipython is not None:
break
else:
raise('Decorator can only run in context where `get_ipython` exists')
ip = get_ipython()
if callable(arg):
# "Naked" decorator call (just @foo, no args)
func = arg
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 name = func.func_name
ip.register_magic_function(func, magic_kind, name)
Fernando Perez
Create decorators for standalone magic functions, as per review.x
r6972 retval = decorator(call, func)
elif isinstance(arg, basestring):
# Decorator called with arguments (@foo('bar'))
name = arg
def mark(func, *a, **kw):
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 ip.register_magic_function(func, magic_kind, name)
Fernando Perez
Create decorators for standalone magic functions, as per review.x
r6972 return decorator(call, func)
retval = mark
else:
raise ValueError("Decorator can only be called with "
"string or function")
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 return retval
return magic_deco
Fernando Perez
Create decorators for standalone magic functions, as per review.x
r6972 # Create the actual decorators for public use
# These three are used to decorate methods in class definitions
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 line_magic = _magic_marker('line')
cell_magic = _magic_marker('cell')
Fernando Perez
First working version of cell magic support.
r6953 line_cell_magic = _magic_marker('line_cell')
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919
Fernando Perez
Create decorators for standalone magic functions, as per review.x
r6972 # These three decorate standalone functions and perform the decoration
# immediately. They can only run where get_ipython() works
register_line_magic = _function_magic_marker('line')
register_cell_magic = _function_magic_marker('cell')
register_line_cell_magic = _function_magic_marker('line_cell')
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 #-----------------------------------------------------------------------------
# Core Magic classes
#-----------------------------------------------------------------------------
Ville M. Vainio
crlf -> lf
r1032
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 class MagicsManager(Configurable):
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 """Object that handles all magic-related functionality for IPython.
"""
Fernando Perez
Implement magic registration and listing in magics manager.
r6921 # Non-configurable class attributes
Fernando Perez
Fix %pylab magic....
r6949
# A two-level dict, first keyed by magic type, then by magic function, and
# holding the actual callable object as value. This is the dict used for
# magic function dispatch
Fernando Perez
Add all decorators to tag magics....
r6922 magics = Dict
Fernando Perez
Implement magic registration and listing in magics manager.
r6921
Fernando Perez
Fix %pylab magic....
r6949 # A registry of the original objects that we've been given holding magics.
registry = Dict
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
Ville M. Vainio
crlf -> lf
r1032
Fernando Perez
Add all decorators to tag magics....
r6922 auto_magic = Bool
_auto_status = [
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 'Automagic is OFF, % prefix IS needed for magic functions.',
Fernando Perez
Add all decorators to tag magics....
r6922 'Automagic is ON, % prefix IS NOT needed for magic functions.']
MinRK
add %config magic for configuring IPython
r5225
Fernando Perez
Move UserMagics to core.magics
r6957 user_magics = Instance('IPython.core.magics.UserMagics')
Fernando Perez
Fix pylab support and simplify approach to reduce global state in main object.
r6910
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 def __init__(self, shell=None, config=None, user_magics=None, **traits):
super(MagicsManager, self).__init__(shell=shell, config=config,
user_magics=user_magics, **traits)
Fernando Perez
Fix magic decorator logic so we correctly fetch bound instance methods.
r6924 self.magics = dict(line={}, cell={})
Fernando Perez
Fix %pylab magic....
r6949 # Let's add the user_magics to the registry for uniformity, so *all*
# registered magic containers can be found there.
self.registry[user_magics.__class__.__name__] = user_magics
Ville M. Vainio
crlf -> lf
r1032
Fernando Perez
Add all decorators to tag magics....
r6922 def auto_status(self):
"""Return descriptive string with automagic status."""
return self._auto_status[self.auto_magic]
Ville M. Vainio
crlf -> lf
r1032
def lsmagic(self):
Fernando Perez
Implement magic registration and listing in magics manager.
r6921 """Return a dict of currently available magic functions.
The return dict has the keys 'line' and 'cell', corresponding to the
two types of magics we support. Each value is a list of names.
"""
Fernando Perez
Add all decorators to tag magics....
r6922 return self.magics
Fernando Perez
Implement magic registration and listing in magics manager.
r6921
Fernando Perez
Fix magic decorator logic so we correctly fetch bound instance methods.
r6924 def register(self, *magic_objects):
Fernando Perez
Implement magic registration and listing in magics manager.
r6921 """Register one or more instances of Magics.
"""
# Start by validating them to ensure they have all had their magic
# methods registered at the instance level
Fernando Perez
Fix magic decorator logic so we correctly fetch bound instance methods.
r6924 for m in magic_objects:
Fernando Perez
Implement magic registration and listing in magics manager.
r6921 if not m.registered:
raise ValueError("Class of magics %r was constructed without "
"the @register_macics class decorator")
Fernando Perez
Remove unnecessary metaclass and allow registration of magic classes....
r6927 if type(m) is type:
# If we're given an uninstantiated class
m = m(self.shell)
Fernando Perez
Fix %pylab magic....
r6949 # Now that we have an instance, we can register it and update the
# table of callables
self.registry[m.__class__.__name__] = m
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 for mtype in magic_kinds:
Fernando Perez
Fix magic decorator logic so we correctly fetch bound instance methods.
r6924 self.magics[mtype].update(m.magics[mtype])
Fernando Perez
Implement magic registration and listing in magics manager.
r6921
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 def register_function(self, func, magic_kind='line', magic_name=None):
Fernando Perez
Update storemagic extension to new API
r6935 """Expose a standalone function as magic function for ipython.
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 """
Fernando Perez
Clean up magic registration api and make it public.
r6933
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 # Create the new method in the user_magics and register it in the
# global table
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 validate_type(magic_kind)
Fernando Perez
Settle on cleaner API for magic registration....
r6936 magic_name = func.func_name if magic_name is None else magic_name
setattr(self.user_magics, magic_name, func)
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 record_magic(self.magics, magic_kind, magic_name, func)
Fernando Perez
Settle on cleaner API for magic registration....
r6936
Fernando Perez
Update api names as per review discussion.
r6954 def define_magic(self, name, func):
Fernando Perez
Settle on cleaner API for magic registration....
r6936 """Support for deprecated API.
This method exists only to support the old-style definition of magics.
It will eventually be removed. Deliberately not documented further.
"""
meth = types.MethodType(func, self.user_magics)
setattr(self.user_magics, name, meth)
Fernando Perez
First working version of cell magic support.
r6953 record_magic(self.magics, 'line', name, meth)
Fernando Perez
Settle on cleaner API for magic registration....
r6936
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 # Key base class that provides the central functionality for magics.
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 class Magics(object):
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 """Base class for implementing magic functions.
Shell functions which can be reached as %function_name. All magic
functions should accept a string, which they can parse for their own
needs. This can make some functions easier to type, eg `%cd ../`
vs. `%cd("../")`
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919
Classes providing magic functions need to subclass this class, and they
MUST:
- Use the method decorators `@line_magic` and `@cell_magic` to decorate
individual methods as magic functions, AND
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 - Use the class decorator `@magics_class` to ensure that the magic
Fernando Perez
Separate magic code into base file and implementation of magics....
r6919 methods are properly registered at the instance level upon instance
initialization.
See :mod:`magic_functions` for examples of actual implementation classes.
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 """
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 # Dict holding all command-line options for each magic.
options_table = None
Fernando Perez
Fix %run
r6929 # Dict for the mapping of magic names to methods, set by class decorator
magics = None
# Flag to check that the class decorator was properly applied
Fernando Perez
Remove unnecessary metaclass and allow registration of magic classes....
r6927 registered = False
Fernando Perez
Cleaner magics constructor
r6930 # Instance of IPython shell
shell = None
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917
def __init__(self, shell):
if not(self.__class__.registered):
Fernando Perez
Cleaner magics constructor
r6930 raise ValueError('Magics subclass without registration - '
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 'did you forget to apply @magics_class?')
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 self.shell = shell
Fernando Perez
Fix %run
r6929 self.options_table = {}
Fernando Perez
Cleaner magics constructor
r6930 # The method decorators are run when the instance doesn't exist yet, so
# they can only record the names of the methods they are supposed to
# grab. Only now, that the instance exists, can we create the proper
# mapping to bound methods. So we read the info off the original names
# table and replace each method name by the actual bound method.
Fernando Perez
Remove next_input nonsense in magic calls (but keep functionality).
r6974 for mtype in magic_kinds:
Fernando Perez
Cleaner magics constructor
r6930 tab = self.magics[mtype]
# must explicitly use keys, as we're mutating this puppy
for magic_name in tab.keys():
meth_name = tab[magic_name]
Fernando Perez
Remove unnecessary metaclass and allow registration of magic classes....
r6927 if isinstance(meth_name, basestring):
tab[magic_name] = getattr(self, meth_name)
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917
Ville M. Vainio
crlf -> lf
r1032 def arg_err(self,func):
"""Print docstring if incorrect arguments were passed"""
print 'Error in arguments:'
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 print oinspect.getdoc(func)
Ville M. Vainio
crlf -> lf
r1032
Fernando Perez
Fix %run
r6929 def format_latex(self, strng):
Ville M. Vainio
crlf -> lf
r1032 """Format a string for latex inclusion."""
# Characters that need to be escaped for latex:
escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE)
# Magic command names as headers:
Brian Granger
Massive refactoring of of the core....
r2245 cmd_name_re = re.compile(r'^(%s.*?):' % ESC_MAGIC,
Ville M. Vainio
crlf -> lf
r1032 re.MULTILINE)
Bernardo B. Marques
remove all trailling spaces
r4872 # Magic commands
Brian Granger
Massive refactoring of of the core....
r2245 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % ESC_MAGIC,
Ville M. Vainio
crlf -> lf
r1032 re.MULTILINE)
# Paragraph continue
par_re = re.compile(r'\\$',re.MULTILINE)
# The "\n" symbol
newline_re = re.compile(r'\\n')
# Now build the string for output:
#strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
strng)
strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
strng = par_re.sub(r'\\\\',strng)
strng = escape_re.sub(r'\\\1',strng)
strng = newline_re.sub(r'\\textbackslash{}n',strng)
return strng
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 def parse_options(self, arg_str, opt_str, *long_opts, **kw):
Ville M. Vainio
crlf -> lf
r1032 """Parse options passed to an argument string.
The interface is similar to that of getopt(), but it returns back a
Struct with the options as keys and the stripped argument string still
as a string.
arg_str is quoted as a true sys.argv vector by using shlex.split.
This allows us to easily expand variables, glob files, quote
arguments, etc.
Options:
-mode: default 'string'. If given as 'list', the argument string is
returned as a list (split on whitespace) instead of a string.
-list_all: put all option values in lists. Normally only options
appearing more than once are put in a list.
-posix (True): whether to split the input line in POSIX mode or not,
as per the conventions outlined in the shlex module from the
standard library."""
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
crlf -> lf
r1032 # inject default options at the beginning of the input line
Fernando Perez
Fix %run
r6929 caller = sys._getframe(1).f_code.co_name
Ville M. Vainio
crlf -> lf
r1032 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
crlf -> lf
r1032 mode = kw.get('mode','string')
if mode not in ['string','list']:
raise ValueError,'incorrect mode given: %s' % mode
# Get options
list_all = kw.get('list_all',0)
Fernando Perez
Fix argument parsing bug in win32, clean up temp files in %hist doctest.
r2450 posix = kw.get('posix', os.name == 'posix')
MinRK
add strict flag to arg_split, to optionally ignore shlex parse errors...
r5672 strict = kw.get('strict', True)
Ville M. Vainio
crlf -> lf
r1032
# Check if we have more than one argument to warrant extra processing:
odict = {} # Dictionary with options
args = arg_str.split()
if len(args) >= 1:
# If the list of inputs only has 0 or 1 thing in it, there's no
# need to look for options
MinRK
add strict flag to arg_split, to optionally ignore shlex parse errors...
r5672 argv = arg_split(arg_str, posix, strict)
Ville M. Vainio
crlf -> lf
r1032 # Do regular option processing
try:
opts,args = getopt(argv,opt_str,*long_opts)
except GetoptError,e:
Bernardo B. Marques
remove all trailling spaces
r4872 raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
Ville M. Vainio
crlf -> lf
r1032 " ".join(long_opts)))
for o,a in opts:
if o.startswith('--'):
o = o[2:]
else:
o = o[1:]
try:
odict[o].append(a)
except AttributeError:
odict[o] = [odict[o],a]
except KeyError:
if list_all:
odict[o] = [a]
else:
odict[o] = a
# Prepare opts,args for return
opts = Struct(odict)
if mode == 'string':
args = ' '.join(args)
return opts,args
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Add proper initialization of magics to main shell instance....
r6923 def default_option(self, fn, optstr):
Fernando Perez
Major restructuring of magics, breaking them up into separate classes....
r6917 """Make an entry in the options_table for fn, with value optstr"""
if fn not in self.lsmagic():
error("%s is not a magic function" % fn)
self.options_table[fn] = optstr