[Python-checkins] r57544 - sandbox/trunk/import_in_py/zipimport_/tests.py sandbox/trunk/import_in_py/zipimport_/zipimport.py
brett.cannon
python-checkins at python.org
Mon Aug 27 04:26:31 CEST 2007
Author: brett.cannon
Date: Mon Aug 27 04:26:31 2007
New Revision: 57544
Modified:
sandbox/trunk/import_in_py/zipimport_/tests.py
sandbox/trunk/import_in_py/zipimport_/zipimport.py
Log:
Re-implement is_package.
Modified: sandbox/trunk/import_in_py/zipimport_/tests.py
==============================================================================
--- sandbox/trunk/import_in_py/zipimport_/tests.py (original)
+++ sandbox/trunk/import_in_py/zipimport_/tests.py Mon Aug 27 04:26:31 2007
@@ -175,6 +175,8 @@
self.assert_(importer.is_package('_pkg'))
importer.find_module('_top_level')
self.assert_(not importer.is_package('_top_level'))
+ pkg_path = os.path.join(zip_path, '_pkg')
+ importer = zipimport.zipimporter(pkg_path)
importer.find_module('_pkg.submodule')
self.assert_(not importer.is_package('_pkg.submodule'))
@@ -235,7 +237,7 @@
ZipImportCreation,
FindModule,
GetData,
- #IsPackage,
+ IsPackage,
#GetSource,
#GetCode,
#LoadModule
Modified: sandbox/trunk/import_in_py/zipimport_/zipimport.py
==============================================================================
--- sandbox/trunk/import_in_py/zipimport_/zipimport.py (original)
+++ sandbox/trunk/import_in_py/zipimport_/zipimport.py Mon Aug 27 04:26:31 2007
@@ -145,10 +145,12 @@
def is_package(self, fullname):
"""Return True if the module name represents a package, False if it
does not."""
- raise NotImplementedError
- try:
- return self._path_cache[fullname][2]
- except KeyError:
+ tail = fullname.rpartition('.')[2]
+ if self._check_paths(tail, '__init__'):
+ return True
+ elif self._check_paths(tail):
+ return False
+ else:
raise ZipImportError("%s is not known" % fullname)
def mod_time(self, name):
More information about the Python-checkins
mailing list