diff options
author | Brett Cannon <brett@python.org> | 2012-05-11 16:58:42 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-05-11 16:58:42 (GMT) |
commit | cb66eb0deca1d5cd232f97c76a215ecaab958d30 (patch) | |
tree | f38497a2e61cf8be225c4e7394961703cea5f66c /Lib/pydoc.py | |
parent | 810c64df8f8bf70a2cb7a626004185616cb88213 (diff) | |
download | cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.zip cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.tar.gz cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.tar.bz2 |
Issue #13959: Deprecate imp.get_suffixes() for new attributes on
importlib.machinery that provide the suffix details for import.
The attributes were not put on imp so as to compartmentalize
everything importlib needs for setting up imports in
importlib.machinery.
This also led to an indirect deprecation of inspect.getmoduleinfo() as
it directly returned imp.get_suffix's returned tuple which no longer
makes sense.
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index b319d11..9c9658c 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -53,6 +53,7 @@ Richard Chamberlain, for the first implementation of textdoc. import builtins import imp +import importlib.machinery import inspect import io import os @@ -220,20 +221,34 @@ def synopsis(filename, cache={}): mtime = os.stat(filename).st_mtime lastupdate, result = cache.get(filename, (None, None)) if lastupdate is None or lastupdate < mtime: - info = inspect.getmoduleinfo(filename) try: file = tokenize.open(filename) except IOError: # module can't be opened, so skip it return None - if info and 'b' in info[2]: # binary modules have to be imported - try: module = imp.load_module('__temp__', file, filename, info[1:]) - except: return None + binary_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:] + binary_suffixes += importlib.machinery.EXTENSION_SUFFIXES[:] + if any(filename.endswith(x) for x in binary_suffixes): + # binary modules have to be imported + file.close() + if any(filename.endswith(x) for x in + importlib.machinery.BYTECODE_SUFFIXES): + loader = importlib.machinery.SourcelessFileLoader('__temp__', + filename) + else: + loader = importlib.machinery.ExtensionFileLoader('__temp__', + filename) + try: + module = loader.load_module('__temp__') + except: + return None result = (module.__doc__ or '').splitlines()[0] del sys.modules['__temp__'] - else: # text modules can be directly examined + else: + # text modules can be directly examined result = source_synopsis(file) file.close() + cache[filename] = (mtime, result) return result |