Show More
@@ -593,13 +593,29 b' class Inspector(Colorable):' | |||||
593 | else: |
|
593 | else: | |
594 | return dict(defaults, **formatted) |
|
594 | return dict(defaults, **formatted) | |
595 |
|
595 | |||
|
596 | ||||
|
597 | def format_mime(self, bundle): | |||
|
598 | ||||
|
599 | text_plain = bundle['text/plain'] | |||
|
600 | ||||
|
601 | text = '' | |||
|
602 | heads, bodies = list(zip(*text_plain)) | |||
|
603 | _len = max(len(h) for h in heads) | |||
|
604 | ||||
|
605 | for head, body in zip(heads, bodies): | |||
|
606 | delim = '\n' if '\n' in body else ' ' | |||
|
607 | text += self.__head(head+':') + (_len - len(head))*' ' +delim + body +'\n' | |||
|
608 | ||||
|
609 | bundle['text/plain'] = text | |||
|
610 | return bundle | |||
|
611 | ||||
596 | def _get_info(self, obj, oname='', formatter=None, info=None, detail_level=0): |
|
612 | def _get_info(self, obj, oname='', formatter=None, info=None, detail_level=0): | |
597 | """Retrieve an info dict and format it.""" |
|
613 | """Retrieve an info dict and format it.""" | |
598 |
|
614 | |||
599 | info = self._info(obj, oname=oname, info=info, detail_level=detail_level) |
|
615 | info = self._info(obj, oname=oname, info=info, detail_level=detail_level) | |
600 |
|
616 | |||
601 | mime = { |
|
617 | _mime = { | |
602 |
'text/plain': |
|
618 | 'text/plain': [], | |
603 | 'text/html': '', |
|
619 | 'text/html': '', | |
604 | } |
|
620 | } | |
605 |
|
621 | |||
@@ -607,7 +623,7 b' class Inspector(Colorable):' | |||||
607 | field = info[key] |
|
623 | field = info[key] | |
608 | if field is not None: |
|
624 | if field is not None: | |
609 | formatted_field = self._mime_format(field, formatter) |
|
625 | formatted_field = self._mime_format(field, formatter) | |
610 |
bundle['text/plain'] |
|
626 | bundle['text/plain'].append((title, formatted_field['text/plain'])) | |
611 | bundle['text/html'] += '<h1>' + title + '</h1>\n' + formatted_field['text/html'] + '\n' |
|
627 | bundle['text/html'] += '<h1>' + title + '</h1>\n' + formatted_field['text/html'] + '\n' | |
612 |
|
628 | |||
613 | def code_formatter(text): |
|
629 | def code_formatter(text): | |
@@ -617,59 +633,61 b' class Inspector(Colorable):' | |||||
617 | } |
|
633 | } | |
618 |
|
634 | |||
619 | if info['isalias']: |
|
635 | if info['isalias']: | |
620 | append_field(mime, 'Repr', 'string_form') |
|
636 | append_field(_mime, 'Repr', 'string_form') | |
621 |
|
637 | |||
622 | elif info['ismagic']: |
|
638 | elif info['ismagic']: | |
623 | if detail_level > 0: |
|
639 | if detail_level > 0: | |
624 | append_field(mime, 'Source', 'source', code_formatter) |
|
640 | append_field(_mime, 'Source', 'source', code_formatter) | |
625 | else: |
|
641 | else: | |
626 | append_field(mime, 'Docstring', 'docstring', formatter) |
|
642 | append_field(_mime, 'Docstring', 'docstring', formatter) | |
627 | append_field(mime, 'File', 'file') |
|
643 | append_field(_mime, 'File', 'file') | |
628 |
|
644 | |||
629 | elif info['isclass'] or is_simple_callable(obj): |
|
645 | elif info['isclass'] or is_simple_callable(obj): | |
630 | # Functions, methods, classes |
|
646 | # Functions, methods, classes | |
631 | append_field(mime, 'Signature', 'definition', code_formatter) |
|
647 | append_field(_mime, 'Signature', 'definition', code_formatter) | |
632 | append_field(mime, 'Init signature', 'init_definition', code_formatter) |
|
648 | append_field(_mime, 'Init signature', 'init_definition', code_formatter) | |
633 | if detail_level > 0: |
|
649 | if detail_level > 0: | |
634 | append_field(mime, 'Source', 'source', code_formatter) |
|
650 | append_field(_mime, 'Source', 'source', code_formatter) | |
635 | else: |
|
651 | else: | |
636 | append_field(mime, 'Docstring', 'docstring', formatter) |
|
652 | append_field(_mime, 'Docstring', 'docstring', formatter) | |
637 | append_field(mime, 'Init docstring', 'init_docstring', formatter) |
|
653 | append_field(_mime, 'Init docstring', 'init_docstring', formatter) | |
638 |
|
654 | |||
639 | append_field(mime, 'File', 'file') |
|
655 | append_field(_mime, 'File', 'file') | |
640 | append_field(mime, 'Type', 'type_name') |
|
656 | append_field(_mime, 'Type', 'type_name') | |
641 |
|
657 | |||
642 | else: |
|
658 | else: | |
643 | # General Python objects |
|
659 | # General Python objects | |
644 | append_field(mime, 'Type', 'type_name') |
|
660 | append_field(_mime, 'Type', 'type_name') | |
645 |
|
661 | |||
646 | # Base class for old-style instances |
|
662 | # Base class for old-style instances | |
647 | if (not py3compat.PY3) and isinstance(obj, types.InstanceType) and info['base_class']: |
|
663 | if (not py3compat.PY3) and isinstance(obj, types.InstanceType) and info['base_class']: | |
648 | append_field(mime, 'Base Class', 'base_class') |
|
664 | append_field(_mime, 'Base Class', 'base_class') | |
649 |
|
665 | |||
650 | append_field(mime, 'String form', 'string_form') |
|
666 | append_field(_mime, 'String form', 'string_form') | |
651 |
|
667 | |||
652 | # Namespace |
|
668 | # Namespace | |
653 | if info['namespace'] != 'Interactive': |
|
669 | if info['namespace'] != 'Interactive': | |
654 | append_field(mime, 'Namespace', 'namespace') |
|
670 | append_field(_mime, 'Namespace', 'namespace') | |
655 |
|
671 | |||
656 | append_field(mime, 'Length', 'length') |
|
672 | append_field(_mime, 'Length', 'length') | |
657 | append_field(mime, 'File', 'file'), |
|
673 | append_field(_mime, 'File', 'file'), | |
658 | append_field(mime, 'Signature', 'definition', code_formatter) |
|
674 | append_field(_mime, 'Signature', 'definition', code_formatter) | |
659 |
|
675 | |||
660 | # Source or docstring, depending on detail level and whether |
|
676 | # Source or docstring, depending on detail level and whether | |
661 | # source found. |
|
677 | # source found. | |
662 | if detail_level > 0: |
|
678 | if detail_level > 0: | |
663 | append_field(mime, 'Source', 'source', code_formatter) |
|
679 | append_field(_mime, 'Source', 'source', code_formatter) | |
664 | else: |
|
680 | else: | |
665 | append_field(mime, 'Docstring', 'docstring', formatter) |
|
681 | append_field(_mime, 'Docstring', 'docstring', formatter) | |
|
682 | ||||
|
683 | append_field(_mime, 'Class docstring', 'class_docstring', formatter) | |||
|
684 | append_field(_mime, 'Init docstring', 'init_docstring', formatter) | |||
|
685 | append_field(_mime, 'Call signature', 'call_def', code_formatter) | |||
|
686 | append_field(_mime, 'Call docstring', 'call_docstring', formatter) | |||
|
687 | ||||
666 |
|
688 | |||
667 | append_field(mime, 'Class docstring', 'class_docstring', formatter) |
|
|||
668 | append_field(mime, 'Init docstring', 'init_docstring', formatter) |
|
|||
669 | append_field(mime, 'Call signature', 'call_def', code_formatter) |
|
|||
670 | append_field(mime, 'Call docstring', 'call_docstring', formatter) |
|
|||
671 |
|
689 | |||
672 | return mime |
|
690 | return self.format_mime(_mime) | |
673 |
|
691 | |||
674 | def pinfo(self, obj, oname='', formatter=None, info=None, detail_level=0, enable_html_pager=True): |
|
692 | def pinfo(self, obj, oname='', formatter=None, info=None, detail_level=0, enable_html_pager=True): | |
675 | """Show detailed information about an object. |
|
693 | """Show detailed information about an object. |
General Comments 0
You need to be logged in to leave comments.
Login now