Retrieve an info dict and format it. Parameters ========== obj: any Object to inspect and return info from oname: str (default: ''): Name of the variable pointing to `obj`. formatter: callable info: already compute
(self, obj, oname='', formatter=None, info=None, detail_level=0)
| 567 | return bundle |
| 568 | |
| 569 | def _get_info(self, obj, oname='', formatter=None, info=None, detail_level=0): |
| 570 | """Retrieve an info dict and format it. |
| 571 | |
| 572 | Parameters |
| 573 | ========== |
| 574 | |
| 575 | obj: any |
| 576 | Object to inspect and return info from |
| 577 | oname: str (default: ''): |
| 578 | Name of the variable pointing to `obj`. |
| 579 | formatter: callable |
| 580 | info: |
| 581 | already computed information |
| 582 | detail_level: integer |
| 583 | Granularity of detail level, if set to 1, give more information. |
| 584 | """ |
| 585 | |
| 586 | info = self._info(obj, oname=oname, info=info, detail_level=detail_level) |
| 587 | |
| 588 | _mime = { |
| 589 | 'text/plain': [], |
| 590 | 'text/html': '', |
| 591 | } |
| 592 | |
| 593 | def append_field(bundle, title:str, key:str, formatter=None): |
| 594 | field = info[key] |
| 595 | if field is not None: |
| 596 | formatted_field = self._mime_format(field, formatter) |
| 597 | bundle['text/plain'].append((title, formatted_field['text/plain'])) |
| 598 | bundle['text/html'] += '<h1>' + title + '</h1>\n' + formatted_field['text/html'] + '\n' |
| 599 | |
| 600 | def code_formatter(text): |
| 601 | return { |
| 602 | 'text/plain': self.format(text), |
| 603 | 'text/html': pylight(text) |
| 604 | } |
| 605 | |
| 606 | if info['isalias']: |
| 607 | append_field(_mime, 'Repr', 'string_form') |
| 608 | |
| 609 | elif info['ismagic']: |
| 610 | if detail_level > 0: |
| 611 | append_field(_mime, 'Source', 'source', code_formatter) |
| 612 | else: |
| 613 | append_field(_mime, 'Docstring', 'docstring', formatter) |
| 614 | append_field(_mime, 'File', 'file') |
| 615 | |
| 616 | elif info['isclass'] or is_simple_callable(obj): |
| 617 | # Functions, methods, classes |
| 618 | append_field(_mime, 'Signature', 'definition', code_formatter) |
| 619 | append_field(_mime, 'Init signature', 'init_definition', code_formatter) |
| 620 | append_field(_mime, 'Docstring', 'docstring', formatter) |
| 621 | if detail_level > 0 and info['source']: |
| 622 | append_field(_mime, 'Source', 'source', code_formatter) |
| 623 | else: |
| 624 | append_field(_mime, 'Init docstring', 'init_docstring', formatter) |
| 625 | |
| 626 | append_field(_mime, 'File', 'file') |
no test coverage detected