Show the whole file where an object was defined.
(self, obj, oname='')
| 490 | page.page(self.format(src)) |
| 491 | |
| 492 | def pfile(self, obj, oname=''): |
| 493 | """Show the whole file where an object was defined.""" |
| 494 | |
| 495 | lineno = find_source_lines(obj) |
| 496 | if lineno is None: |
| 497 | self.noinfo('file', oname) |
| 498 | return |
| 499 | |
| 500 | ofile = find_file(obj) |
| 501 | # run contents of file through pager starting at line where the object |
| 502 | # is defined, as long as the file isn't binary and is actually on the |
| 503 | # filesystem. |
| 504 | if ofile.endswith(('.so', '.dll', '.pyd')): |
| 505 | print('File %r is binary, not printing.' % ofile) |
| 506 | elif not os.path.isfile(ofile): |
| 507 | print('File %r does not exist, not printing.' % ofile) |
| 508 | else: |
| 509 | # Print only text files, not extension binaries. Note that |
| 510 | # getsourcelines returns lineno with 1-offset and page() uses |
| 511 | # 0-offset, so we must adjust. |
| 512 | page.page(self.format(openpy.read_py_file(ofile, skip_encoding_cookie=False)), lineno - 1) |
| 513 | |
| 514 | |
| 515 | def _mime_format(self, text:str, formatter=None) -> dict: |
nothing calls this directly
no test coverage detected