[Python-checkins] r57545 - 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:30:26 CEST 2007
Author: brett.cannon
Date: Mon Aug 27 04:30:26 2007
New Revision: 57545
Modified:
sandbox/trunk/import_in_py/zipimport_/tests.py
sandbox/trunk/import_in_py/zipimport_/zipimport.py
Log:
Re-implement get_source.
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:30:26 2007
@@ -238,7 +238,7 @@
FindModule,
GetData,
IsPackage,
- #GetSource,
+ 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:30:26 2007
@@ -132,15 +132,18 @@
def get_source(self, fullname):
"""Get the source code for the specified module, raising ZipImportError
if the module does not exist, or None if only bytecode exists."""
- raise NotImplementedError
- try:
- info = self._path_cache[fullname]
- except KeyError:
- raise ZipImportError("%s is not known" % fullname)
- if info[0] is None:
- return None
- with contextlib.closing(zipfile.ZipFile(self._zip_path)) as zip_:
- return zip_.open(info[0], 'U').read()
+ tail = fullname.rpartition('.')[2]
+ paths = self._check_paths(tail, '__init__')
+ if paths and paths[0]:
+ source_path = paths[0]
+ else:
+ paths = self._check_paths(tail)
+ if paths and paths[0]:
+ source_path = paths[0]
+ else:
+ raise ZipImportError("%s is not known" % fullname)
+ with contextlib.closing(zipfile.ZipFile(self.archive)) as zip_:
+ return zip_.open(source_path, 'U').read()
def is_package(self, fullname):
"""Return True if the module name represents a package, False if it
More information about the Python-checkins
mailing list