[Python-checkins] r56787 - sandbox/trunk/import_in_py/zipimport_ sandbox/trunk/import_in_py/zipimport_/__init__.py sandbox/trunk/import_in_py/zipimport_/tests.py sandbox/trunk/import_in_py/zipimport_/zipimport.py

brett.cannon python-checkins at python.org
Tue Aug 7 06:26:50 CEST 2007


Author: brett.cannon
Date: Tue Aug  7 06:26:50 2007
New Revision: 56787

Added:
   sandbox/trunk/import_in_py/zipimport_/
   sandbox/trunk/import_in_py/zipimport_/__init__.py   (contents, props changed)
   sandbox/trunk/import_in_py/zipimport_/tests.py   (contents, props changed)
   sandbox/trunk/import_in_py/zipimport_/zipimport.py   (contents, props changed)
Log:
Begin a re-implementation of zipimport using importlib.


Added: sandbox/trunk/import_in_py/zipimport_/__init__.py
==============================================================================

Added: sandbox/trunk/import_in_py/zipimport_/tests.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/import_in_py/zipimport_/tests.py	Tue Aug  7 06:26:50 2007
@@ -0,0 +1,21 @@
+from zipimport_ import zipimport
+
+from test import test_support
+import unittest
+
+class ZipImportErrorTests(unittest.TestCase):
+
+    """Test ZipImportError."""
+
+    def test_inheritance(self):
+        # Should inherit from ImportError.
+        self.assert_(issubclass(zipimport.ZipImportError, ImportError))
+
+
+
+def test_main():
+    test_support.run_unittest(ZipImportErrorTests)
+
+
+if __name__ == '__main__':
+    test_main()

Added: sandbox/trunk/import_in_py/zipimport_/zipimport.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/import_in_py/zipimport_/zipimport.py	Tue Aug  7 06:26:50 2007
@@ -0,0 +1,42 @@
+"""A re-implementation of zipimport to use importlib."""
+import importlib
+
+import zipfile
+
+
+class ZipImportError(ImportError):
+    pass
+
+
+class zipimporter(object):
+
+    """XXX Might need to implement 'archive', 'prefix' attributes."""
+
+    def __init__(self, archivepath):
+        """Open the specified zip file.
+
+        Meant to be used from sys.path_hooks, meaning that if something other
+        than a zip file is passed in then ZipImportError is raised.
+
+        """
+        if not zipfile.is_zipfile(archivepath):
+            raise ZipImportError("the specified path must be a zip file")
+        self._zip = zipfile.ZipFile(archivepath, 'r')
+
+    def find_module(self, fullname, path=None):
+        raise NotImplementedError
+
+    def get_code(self, fullname):
+        raise NotImplementedError
+
+    def get_data(self, fullname):
+        raise NotImplementedError
+
+    def get_source(self, fullname):
+        raise NotImplementedError
+
+    def is_package(self, fullname):
+        raise NotImplementedError
+
+    def load_module(self, fullname):
+        raise NotImplementedError


More information about the Python-checkins mailing list