[Python-checkins] r70247 - python/branches/py3k/Lib/importlib/_bootstrap.py
brett.cannon
python-checkins at python.org
Sun Mar 8 21:53:50 CET 2009
Author: brett.cannon
Date: Sun Mar 8 21:53:50 2009
New Revision: 70247
Log:
Minor changes to Python source base loader.
Fixed a bug where 'self' was left off a method call. Was masked by the fact the
source/bytecode loader subclass is always used. Cleaned up when the source path
is fetched. Also made sure ImportError is raised when a source path cannot be
found.
Modified:
python/branches/py3k/Lib/importlib/_bootstrap.py
Modified: python/branches/py3k/Lib/importlib/_bootstrap.py
==============================================================================
--- python/branches/py3k/Lib/importlib/_bootstrap.py (original)
+++ python/branches/py3k/Lib/importlib/_bootstrap.py Sun Mar 8 21:53:50 2009
@@ -327,26 +327,30 @@
@module_for_loader
def load_module(self, module):
"""Load a source module."""
- return _load_module(module)
+ return self._load_module(module)
def _load_module(self, module):
"""Initialize a module from source."""
name = module.__name__
- source_path = self.source_path(name)
code_object = self.get_code(module.__name__)
+ # __file__ may have been set by the caller, e.g. bytecode path.
if not hasattr(module, '__file__'):
- module.__file__ = source_path
+ module.__file__ = self.source_path(name)
if self.is_package(name):
module.__path__ = [module.__file__.rsplit(path_sep, 1)[0]]
module.__package__ = module.__name__
if not hasattr(module, '__path__'):
module.__package__ = module.__package__.rpartition('.')[0]
+ module.__loader__ = self
exec(code_object, module.__dict__)
return module
def get_code(self, fullname):
"""Get a code object from 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)
source = self.get_data(source_path)
# Convert to universal newlines.
line_endings = b'\n'
More information about the Python-checkins
mailing list