summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/abc.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-13 01:09:01 (GMT)
committerBrett Cannon <brett@python.org>2012-04-13 01:09:01 (GMT)
commitbbb6680ee5650ad1096eba0c86286342c3d08468 (patch)
tree2b17a1b8beb11db23edf34adbc5684fadc829139 /Lib/importlib/abc.py
parent79ec55e980d7b205bbc78d44e0892d0ef37d3abb (diff)
downloadcpython-bbb6680ee5650ad1096eba0c86286342c3d08468.zip
cpython-bbb6680ee5650ad1096eba0c86286342c3d08468.tar.gz
cpython-bbb6680ee5650ad1096eba0c86286342c3d08468.tar.bz2
Have importlib take advantage of ImportError's new 'name' and 'path'
attributes.
Diffstat (limited to 'Lib/importlib/abc.py')
-rw-r--r--Lib/importlib/abc.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index 22a7c1a..43e4866 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -207,7 +207,7 @@ class PyLoader(SourceLoader):
DeprecationWarning)
path = self.source_path(fullname)
if path is None:
- raise ImportError
+ raise ImportError(name=fullname)
else:
return path
@@ -235,7 +235,7 @@ class PyPycLoader(PyLoader):
if path is not None:
return path
raise ImportError("no source or bytecode path available for "
- "{0!r}".format(fullname))
+ "{0!r}".format(fullname), name=fullname)
def get_code(self, fullname):
"""Get a code object from source or bytecode."""
@@ -253,7 +253,8 @@ class PyPycLoader(PyLoader):
magic = data[:4]
if len(magic) < 4:
raise ImportError(
- "bad magic number in {}".format(fullname))
+ "bad magic number in {}".format(fullname),
+ name=fullname, path=bytecode_path)
raw_timestamp = data[4:8]
if len(raw_timestamp) < 4:
raise EOFError("bad timestamp in {}".format(fullname))
@@ -262,12 +263,14 @@ class PyPycLoader(PyLoader):
# Verify that the magic number is valid.
if imp.get_magic() != magic:
raise ImportError(
- "bad magic number in {}".format(fullname))
+ "bad magic number in {}".format(fullname),
+ name=fullname, path=bytecode_path)
# Verify that the bytecode is not stale (only matters when
# there is source to fall back on.
if source_timestamp:
if pyc_timestamp < source_timestamp:
- raise ImportError("bytecode is stale")
+ raise ImportError("bytecode is stale", name=fullname,
+ path=bytecode_path)
except (ImportError, EOFError):
# If source is available give it a shot.
if source_timestamp is not None:
@@ -279,12 +282,13 @@ class PyPycLoader(PyLoader):
return marshal.loads(bytecode)
elif source_timestamp is None:
raise ImportError("no source or bytecode available to create code "
- "object for {0!r}".format(fullname))
+ "object for {0!r}".format(fullname),
+ name=fullname)
# Use the source.
source_path = self.source_path(fullname)
if source_path is None:
message = "a source path must exist to load {0}".format(fullname)
- raise ImportError(message)
+ raise ImportError(message, name=fullname)
source = self.get_data(source_path)
code_object = compile(source, source_path, 'exec', dont_inherit=True)
# Generate bytecode and write it out.