Show the whole file where an object was defined.
(self, obj, oname='')
| 552 | page.page(self.format(src)) |
| 553 | |
| 554 | def pfile(self, obj, oname=''): |
| 555 | """Show the whole file where an object was defined.""" |
| 556 | |
| 557 | lineno = find_source_lines(obj) |
| 558 | if lineno is None: |
| 559 | self.noinfo('file', oname) |
| 560 | return |
| 561 | |
| 562 | ofile = find_file(obj) |
| 563 | # run contents of file through pager starting at line where the object |
| 564 | # is defined, as long as the file isn't binary and is actually on the |
| 565 | # filesystem. |
| 566 | if ofile is None: |
| 567 | print("Could not find file for object") |
| 568 | elif ofile.endswith((".so", ".dll", ".pyd")): |
| 569 | print("File %r is binary, not printing." % ofile) |
| 570 | elif not os.path.isfile(ofile): |
| 571 | print('File %r does not exist, not printing.' % ofile) |
| 572 | else: |
| 573 | # Print only text files, not extension binaries. Note that |
| 574 | # getsourcelines returns lineno with 1-offset and page() uses |
| 575 | # 0-offset, so we must adjust. |
| 576 | page.page(self.format(openpy.read_py_file(ofile, skip_encoding_cookie=False)), lineno - 1) |
| 577 | |
| 578 | |
| 579 | def _mime_format(self, text:str, formatter=None) -> dict: |
nothing calls this directly
no test coverage detected