summaryrefslogtreecommitdiffstats
path: root/Lib/imp.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-17 23:14:26 (GMT)
committerBrett Cannon <brett@python.org>2012-04-17 23:14:26 (GMT)
commit64befe939c1da377053f6a410f082db02184c5e2 (patch)
tree884e381d3732ef28eb5b95a71a30bee39e8f6227 /Lib/imp.py
parent273323cf68e8d55c67622412ecf531e359a54e11 (diff)
downloadcpython-64befe939c1da377053f6a410f082db02184c5e2.zip
cpython-64befe939c1da377053f6a410f082db02184c5e2.tar.gz
cpython-64befe939c1da377053f6a410f082db02184c5e2.tar.bz2
Issue #13959: Re-implement imp.load_compiled() in imp.py.
Diffstat (limited to 'Lib/imp.py')
-rw-r--r--Lib/imp.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/Lib/imp.py b/Lib/imp.py
index dc685d0..6a86ba9 100644
--- a/Lib/imp.py
+++ b/Lib/imp.py
@@ -14,7 +14,7 @@ from _imp import (lock_held, acquire_lock, release_lock, reload,
from _imp import (get_magic, get_tag, get_suffixes, cache_from_source,
source_from_cache)
# Should be re-implemented here (and mostly deprecated)
-from _imp import (find_module, load_compiled, NullImporter,
+from _imp import (find_module, NullImporter,
SEARCH_ERROR, PY_SOURCE, PY_COMPILED, C_EXTENSION,
PY_RESOURCE, PKG_DIRECTORY, C_BUILTIN, PY_FROZEN,
PY_CODERESOURCE, IMP_HOOK)
@@ -25,17 +25,17 @@ from importlib import _bootstrap
import os
-class _LoadSourceCompatibility(_bootstrap._SourceFileLoader):
+class _HackedGetData:
- """Compatibility support for implementing load_source()."""
+ """Compatibiilty support for 'file' arguments of various load_*()
+ functions."""
def __init__(self, fullname, path, file=None):
super().__init__(fullname, path)
self.file = file
def get_data(self, path):
- """Gross hack to contort SourceFileLoader to deal w/ load_source()'s bad
- API."""
+ """Gross hack to contort loader to deal w/ load_*()'s bad API."""
if self.file and path == self._path:
with self.file:
# Technically should be returning bytes, but
@@ -48,10 +48,25 @@ class _LoadSourceCompatibility(_bootstrap._SourceFileLoader):
return super().get_data(path)
+class _LoadSourceCompatibility(_HackedGetData, _bootstrap._SourceFileLoader):
+
+ """Compatibility support for implementing load_source()."""
+
+
def load_source(name, pathname, file=None):
return _LoadSourceCompatibility(name, pathname, file).load_module(name)
+class _LoadCompiledCompatibility(_HackedGetData,
+ _bootstrap._SourcelessFileLoader):
+
+ """Compatibility support for implementing load_compiled()."""
+
+
+def load_compiled(name, pathname, file=None):
+ return _LoadCompiledCompatibility(name, pathname, file).load_module(name)
+
+
def load_package(name, path):
if os.path.isdir(path):
extensions = _bootstrap._suffix_list(PY_SOURCE)