[Python-checkins] r57164 - sandbox/trunk/import_in_py/_importlib.py
brett.cannon
python-checkins at python.org
Sat Aug 18 00:50:20 CEST 2007
Author: brett.cannon
Date: Sat Aug 18 00:49:59 2007
New Revision: 57164
Modified:
sandbox/trunk/import_in_py/_importlib.py
Log:
Rearrange some code.
Modified: sandbox/trunk/import_in_py/_importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/_importlib.py (original)
+++ sandbox/trunk/import_in_py/_importlib.py Sat Aug 18 00:49:59 2007
@@ -242,6 +242,42 @@
raise ImportError("can only handle directories")
+class ExtensionFileLoader(object):
+
+ """Provide the ability to load an extension module."""
+
+ def __init__(self, path):
+ self._path = path
+
+ def load_module(self, fullname):
+ """Load an extension module."""
+ try:
+ module = imp.load_dynamic(fullname, self._path)
+ module.__loader__ = self
+ return module
+ except:
+ # If an error occurred, don't leave a partially initialized module.
+ if fullname in sys.modules:
+ del sys.modules[fullname]
+ raise
+
+
+class PyFileLoader(object):
+
+ def __init__(self, path):
+ self._path = path
+
+ def load_module(self, fullname):
+ """Load a Python source or bytecode file."""
+ try:
+ return handle_py(self, fullname, self_path, XXX, XXX, XXX)
+ except:
+ # Don't leave a partially initialized module in sys.modules.
+ if fullname in sys.modules:
+ del sys.modules[fullname]
+ raise
+
+
class FileImporter(object):
"""Base class for file importers.
@@ -297,43 +333,6 @@
return None
-class ExtensionFileLoader(object):
-
- """Provide the ability to load an extension module."""
-
- def __init__(self, path):
- self._path = path
-
- def load_module(self, fullname):
- """Load an extension module."""
- try:
- module = imp.load_dynamic(fullname, self._path)
- module.__loader__ = self
- return module
- except:
- # If an error occurred, don't leave a partially initialized module.
- if fullname in sys.modules:
- del sys.modules[fullname]
- raise
-
-
-class PyFileLoader(object):
-
- def __init__(self, path):
- self._path = path
-
- def load_module(self, fullname):
- """Load a Python source or bytecode file."""
- if fullname in sys.modules:
- return sys.modules[fullname]
- try:
- return handle_py(self, fullname, self_path, XXX, XXX, XXX)
- except:
- if fullname in sys.modules:
- del sys.modules[fullname]
- raise
-
-
class ExtensionFileImporter(FileImporter):
"""Importer for extension files."""
More information about the Python-checkins
mailing list