| 507 | shell = None |
| 508 | |
| 509 | def __init__(self, shell=None, **kwargs): |
| 510 | if not(self.__class__.registered): |
| 511 | raise ValueError('Magics subclass without registration - ' |
| 512 | 'did you forget to apply @magics_class?') |
| 513 | if shell is not None: |
| 514 | if hasattr(shell, 'configurables'): |
| 515 | shell.configurables.append(self) |
| 516 | if hasattr(shell, 'config'): |
| 517 | kwargs.setdefault('parent', shell) |
| 518 | |
| 519 | self.shell = shell |
| 520 | self.options_table = {} |
| 521 | # The method decorators are run when the instance doesn't exist yet, so |
| 522 | # they can only record the names of the methods they are supposed to |
| 523 | # grab. Only now, that the instance exists, can we create the proper |
| 524 | # mapping to bound methods. So we read the info off the original names |
| 525 | # table and replace each method name by the actual bound method. |
| 526 | # But we mustn't clobber the *class* mapping, in case of multiple instances. |
| 527 | class_magics = self.magics |
| 528 | self.magics = {} |
| 529 | for mtype in magic_kinds: |
| 530 | tab = self.magics[mtype] = {} |
| 531 | cls_tab = class_magics[mtype] |
| 532 | for magic_name, meth_name in cls_tab.items(): |
| 533 | if isinstance(meth_name, str): |
| 534 | # it's a method name, grab it |
| 535 | tab[magic_name] = getattr(self, meth_name) |
| 536 | else: |
| 537 | # it's the real thing |
| 538 | tab[magic_name] = meth_name |
| 539 | # Configurable **needs** to be initiated at the end or the config |
| 540 | # magics get screwed up. |
| 541 | super(Magics, self).__init__(**kwargs) |
| 542 | |
| 543 | def arg_err(self,func): |
| 544 | """Print docstring if incorrect arguments were passed""" |