Show More
@@ -232,19 +232,27 b' class Magics(object):' | |||||
232 | magics = None |
|
232 | magics = None | |
233 | # Flag to check that the class decorator was properly applied |
|
233 | # Flag to check that the class decorator was properly applied | |
234 | registered = False |
|
234 | registered = False | |
|
235 | # Instance of IPython shell | |||
|
236 | shell = None | |||
235 |
|
237 | |||
236 | def __init__(self, shell): |
|
238 | def __init__(self, shell): | |
237 | if not(self.__class__.registered): |
|
239 | if not(self.__class__.registered): | |
238 |
raise ValueError(' |
|
240 | raise ValueError('Magics subclass without registration - ' | |
|
241 | 'did you forget to apply @register_magics?') | |||
239 | self.shell = shell |
|
242 | self.shell = shell | |
240 | self.options_table = {} |
|
243 | self.options_table = {} | |
241 | mtab = dict(line={}, cell={}) |
|
244 | # The method decorators are run when the instance doesn't exist yet, so | |
|
245 | # they can only record the names of the methods they are supposed to | |||
|
246 | # grab. Only now, that the instance exists, can we create the proper | |||
|
247 | # mapping to bound methods. So we read the info off the original names | |||
|
248 | # table and replace each method name by the actual bound method. | |||
242 | for mtype in magic_types: |
|
249 | for mtype in magic_types: | |
243 |
tab = |
|
250 | tab = self.magics[mtype] | |
244 | for magic_name, meth_name in self.magics[mtype].iteritems(): |
|
251 | # must explicitly use keys, as we're mutating this puppy | |
|
252 | for magic_name in tab.keys(): | |||
|
253 | meth_name = tab[magic_name] | |||
245 | if isinstance(meth_name, basestring): |
|
254 | if isinstance(meth_name, basestring): | |
246 | tab[magic_name] = getattr(self, meth_name) |
|
255 | tab[magic_name] = getattr(self, meth_name) | |
247 | self.magics.update(mtab) |
|
|||
248 |
|
256 | |||
249 | def arg_err(self,func): |
|
257 | def arg_err(self,func): | |
250 | """Print docstring if incorrect arguments were passed""" |
|
258 | """Print docstring if incorrect arguments were passed""" |
General Comments 0
You need to be logged in to leave comments.
Login now