diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-06-12 15:33:19 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-06-12 15:33:19 (GMT) |
commit | 58641defe45cd8b05c28dea31a8a189d7fb31ce0 (patch) | |
tree | 58a3e0f1f71cf7177e0f9e084df814f2d99ace1f /Lib/doctest.py | |
parent | 554290d9209f0a552093f03e3c8c8e512b2a0efa (diff) | |
download | cpython-58641defe45cd8b05c28dea31a8a189d7fb31ce0.zip cpython-58641defe45cd8b05c28dea31a8a189d7fb31ce0.tar.gz cpython-58641defe45cd8b05c28dea31a8a189d7fb31ce0.tar.bz2 |
Issue #6195: fix doctest to no longer try to read 'source' data from
binary files.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 5fa588d..3d053d9 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -812,20 +812,28 @@ class DocTestFinder: # DocTestFinder._find_lineno to find the line number for a # given object's docstring. try: - file = inspect.getsourcefile(obj) or inspect.getfile(obj) - if module is not None: - # Supply the module globals in case the module was - # originally loaded via a PEP 302 loader and - # file is not a valid filesystem path - source_lines = linecache.getlines(file, module.__dict__) - else: - # No access to a loader, so assume it's a normal - # filesystem path - source_lines = linecache.getlines(file) - if not source_lines: - source_lines = None + file = inspect.getsourcefile(obj) except TypeError: source_lines = None + else: + if not file: + # Check to see if it's one of our special internal "files" + # (see __patched_linecache_getlines). + file = inspect.getfile(obj) + if not file[0]+file[-2:] == '<]>': file = None + if file is None: source_lines = None + else: + if module is not None: + # Supply the module globals in case the module was + # originally loaded via a PEP 302 loader and + # file is not a valid filesystem path + source_lines = linecache.getlines(file, module.__dict__) + else: + # No access to a loader, so assume it's a normal + # filesystem path + source_lines = linecache.getlines(file) + if not source_lines: + source_lines = None # Initialize globals, and merge in extraglobs. if globs is None: |