Return the filename that can be used to locate an object's source. Return None if no way can be identified to get the source.
(object)
| 856 | return None |
| 857 | |
| 858 | def getsourcefile(object): |
| 859 | """Return the filename that can be used to locate an object's source. |
| 860 | Return None if no way can be identified to get the source. |
| 861 | """ |
| 862 | filename = getfile(object) |
| 863 | all_bytecode_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:] |
| 864 | if any(filename.endswith(s) for s in all_bytecode_suffixes): |
| 865 | filename = (os.path.splitext(filename)[0] + |
| 866 | importlib.machinery.SOURCE_SUFFIXES[0]) |
| 867 | elif any(filename.endswith(s) for s in |
| 868 | importlib.machinery.EXTENSION_SUFFIXES): |
| 869 | return None |
| 870 | elif filename.endswith(".fwork"): |
| 871 | # Apple mobile framework markers are another type of non-source file |
| 872 | return None |
| 873 | |
| 874 | # return a filename found in the linecache even if it doesn't exist on disk |
| 875 | if filename in linecache.cache: |
| 876 | return filename |
| 877 | if os.path.exists(filename): |
| 878 | return filename |
| 879 | # only return a non-existent filename if the module has a PEP 302 loader |
| 880 | module = getmodule(object, filename) |
| 881 | if getattr(module, '__loader__', None) is not None: |
| 882 | return filename |
| 883 | elif getattr(getattr(module, "__spec__", None), "loader", None) is not None: |
| 884 | return filename |
| 885 | |
| 886 | def getabsfile(object, _filename=None): |
| 887 | """Return an absolute path to the source or compiled file for an object. |
no test coverage detected