##// END OF EJS Templates
Lint
Jason Grout -
Show More
@@ -554,44 +554,57 b' class Inspector(Colorable):'
554 def format_mime(self, bundle):
554 def format_mime(self, bundle):
555 """Format a mimebundle being created by _make_info_unformatted into a real mimebundle"""
555 """Format a mimebundle being created by _make_info_unformatted into a real mimebundle"""
556 # Format text/plain mimetype
556 # Format text/plain mimetype
557 if isinstance(bundle['text/plain'], (list, tuple)):
557 if isinstance(bundle["text/plain"], (list, tuple)):
558 # bundle['text/plain'] is a list of (head, formatted body) pairs
558 # bundle['text/plain'] is a list of (head, formatted body) pairs
559 lines = []
559 lines = []
560 _len = max(len(h) for h,_ in bundle['text/plain'])
560 _len = max(len(h) for h, _ in bundle["text/plain"])
561
561
562 for head, body in bundle['text/plain']:
562 for head, body in bundle["text/plain"]:
563 body = body.strip('\n')
563 body = body.strip("\n")
564 delim = '\n' if '\n' in body else ' '
564 delim = "\n" if "\n" in body else " "
565 lines.append(f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}")
565 lines.append(
566 f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}"
567 )
566
568
567 bundle['text/plain'] = '\n'.join(lines)
569 bundle["text/plain"] = "\n".join(lines)
568
570
569 # Format the text/html mimetype
571 # Format the text/html mimetype
570 if isinstance(bundle['text/html'], (list, tuple)):
572 if isinstance(bundle["text/html"], (list, tuple)):
571 # bundle['text/html'] is a list of (head, formatted body) pairs
573 # bundle['text/html'] is a list of (head, formatted body) pairs
572 bundle['text/html'] = '\n'.join((f'<h1>{head}</h1>\n{body}' for (head,body) in bundle['text/html']))
574 bundle["text/html"] = "\n".join(
575 (f"<h1>{head}</h1>\n{body}" for (head, body) in bundle["text/html"])
576 )
573 return bundle
577 return bundle
574
578
575 def _append_info_field(self, bundle, title:str, key:str, info, omit_sections, formatter):
579 def _append_info_field(
580 self, bundle, title: str, key: str, info, omit_sections, formatter
581 ):
576 """Append an info value to the unformatted mimebundle being constructed by _make_info_unformatted"""
582 """Append an info value to the unformatted mimebundle being constructed by _make_info_unformatted"""
577 if title in omit_sections or key in omit_sections:
583 if title in omit_sections or key in omit_sections:
578 return
584 return
579 field = info[key]
585 field = info[key]
580 if field is not None:
586 if field is not None:
581 formatted_field = self._mime_format(field, formatter)
587 formatted_field = self._mime_format(field, formatter)
582 bundle['text/plain'].append((title, formatted_field['text/plain']))
588 bundle["text/plain"].append((title, formatted_field["text/plain"]))
583 bundle['text/html'].append((title, formatted_field['text/html']))
589 bundle["text/html"].append((title, formatted_field["text/html"]))
584
590
585 def _make_info_unformatted(self, info, formatter, detail_level, omit_sections):
591 def _make_info_unformatted(self, info, formatter, detail_level, omit_sections):
586 """Assemble the mimebundle as unformatted lists of information"""
592 """Assemble the mimebundle as unformatted lists of information"""
587 bundle = {
593 bundle = {
588 'text/plain': [],
594 "text/plain": [],
589 'text/html': [],
595 "text/html": [],
590 }
596 }
591
597
592 # A convenience function to simplify calls below
598 # A convenience function to simplify calls below
593 def append_field(bundle, title:str, key:str, formatter=None):
599 def append_field(bundle, title: str, key: str, formatter=None):
594 self._append_info_field(bundle, title=title, key=key, info=info, omit_sections=omit_sections, formatter=formatter)
600 self._append_info_field(
601 bundle,
602 title=title,
603 key=key,
604 info=info,
605 omit_sections=omit_sections,
606 formatter=formatter,
607 )
595
608
596 def code_formatter(text):
609 def code_formatter(text):
597 return {
610 return {
@@ -599,54 +612,54 b' class Inspector(Colorable):'
599 'text/html': pylight(text)
612 'text/html': pylight(text)
600 }
613 }
601
614
602 if info['isalias']:
615 if info["isalias"]:
603 append_field(bundle, 'Repr', 'string_form')
616 append_field(bundle, "Repr", "string_form")
604
617
605 elif info['ismagic']:
618 elif info['ismagic']:
606 if detail_level > 0:
619 if detail_level > 0:
607 append_field(bundle, 'Source', 'source', code_formatter)
620 append_field(bundle, "Source", "source", code_formatter)
608 else:
621 else:
609 append_field(bundle, 'Docstring', 'docstring', formatter)
622 append_field(bundle, "Docstring", "docstring", formatter)
610 append_field(bundle, 'File', 'file')
623 append_field(bundle, "File", "file")
611
624
612 elif info['isclass'] or is_simple_callable(obj):
625 elif info['isclass'] or is_simple_callable(obj):
613 # Functions, methods, classes
626 # Functions, methods, classes
614 append_field(bundle, 'Signature', 'definition', code_formatter)
627 append_field(bundle, "Signature", "definition", code_formatter)
615 append_field(bundle, 'Init signature', 'init_definition', code_formatter)
628 append_field(bundle, "Init signature", "init_definition", code_formatter)
616 append_field(bundle, 'Docstring', 'docstring', formatter)
629 append_field(bundle, "Docstring", "docstring", formatter)
617 if detail_level > 0 and info['source']:
630 if detail_level > 0 and info["source"]:
618 append_field(bundle, 'Source', 'source', code_formatter)
631 append_field(bundle, "Source", "source", code_formatter)
619 else:
632 else:
620 append_field(bundle, 'Init docstring', 'init_docstring', formatter)
633 append_field(bundle, "Init docstring", "init_docstring", formatter)
621
634
622 append_field(bundle, 'File', 'file')
635 append_field(bundle, "File", "file")
623 append_field(bundle, 'Type', 'type_name')
636 append_field(bundle, "Type", "type_name")
624 append_field(bundle, 'Subclasses', 'subclasses')
637 append_field(bundle, "Subclasses", "subclasses")
625
638
626 else:
639 else:
627 # General Python objects
640 # General Python objects
628 append_field(bundle, 'Signature', 'definition', code_formatter)
641 append_field(bundle, "Signature", "definition", code_formatter)
629 append_field(bundle, 'Call signature', 'call_def', code_formatter)
642 append_field(bundle, "Call signature", "call_def", code_formatter)
630 append_field(bundle, 'Type', 'type_name')
643 append_field(bundle, "Type", "type_name")
631 append_field(bundle, 'String form', 'string_form')
644 append_field(bundle, "String form", "string_form")
632
645
633 # Namespace
646 # Namespace
634 if info['namespace'] != 'Interactive':
647 if info["namespace"] != "Interactive":
635 append_field(bundle, 'Namespace', 'namespace')
648 append_field(bundle, "Namespace", "namespace")
636
649
637 append_field(bundle, 'Length', 'length')
650 append_field(bundle, "Length", "length")
638 append_field(bundle, 'File', 'file')
651 append_field(bundle, "File", "file")
639
652
640 # Source or docstring, depending on detail level and whether
653 # Source or docstring, depending on detail level and whether
641 # source found.
654 # source found.
642 if detail_level > 0 and info['source']:
655 if detail_level > 0 and info["source"]:
643 append_field(bundle, 'Source', 'source', code_formatter)
656 append_field(bundle, "Source", "source", code_formatter)
644 else:
657 else:
645 append_field(bundle, 'Docstring', 'docstring', formatter)
658 append_field(bundle, "Docstring", "docstring", formatter)
646
659
647 append_field(bundle, 'Class docstring', 'class_docstring', formatter)
660 append_field(bundle, "Class docstring", "class_docstring", formatter)
648 append_field(bundle, 'Init docstring', 'init_docstring', formatter)
661 append_field(bundle, "Init docstring", "init_docstring", formatter)
649 append_field(bundle, 'Call docstring', 'call_docstring', formatter)
662 append_field(bundle, "Call docstring", "call_docstring", formatter)
650 return bundle
663 return bundle
651
664
652
665
@@ -671,7 +684,9 b' class Inspector(Colorable):'
671 """
684 """
672
685
673 info = self.info(obj, oname=oname, info=info, detail_level=detail_level)
686 info = self.info(obj, oname=oname, info=info, detail_level=detail_level)
674 bundle = self._make_info_unformatted(info, formatter, detail_level=detail_level, omit_sections=omit_sections)
687 bundle = self._make_info_unformatted(
688 info, formatter, detail_level=detail_level, omit_sections=omit_sections
689 )
675 return self.format_mime(bundle)
690 return self.format_mime(bundle)
676
691
677 def pinfo(
692 def pinfo(
General Comments 0
You need to be logged in to leave comments. Login now