[Python-checkins] r57451 - sandbox/trunk/import_in_py/zipimport_/zipimport.py
brett.cannon
python-checkins at python.org
Sat Aug 25 06:11:52 CEST 2007
Author: brett.cannon
Date: Sat Aug 25 06:11:52 2007
New Revision: 57451
Modified:
sandbox/trunk/import_in_py/zipimport_/zipimport.py
Log:
Fix it so that __file__ values are correct (untested).
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 Sat Aug 25 06:11:52 2007
@@ -85,6 +85,14 @@
return self
return None
+ def _resolve_path(self, internal_path):
+ """Return the path to the file, consisting of the zip file and the path
+ within the zip file (if the path is true)."""
+ if internal_path:
+ return os.path.join(self._zip_path, internal_path)
+ else:
+ return internal_path
+
def get_code(self, fullname):
"""Return the code object for the module, raising ZipImportError if the
module is not found."""
@@ -92,8 +100,8 @@
info = self._path_cache[fullname]
except KeyError:
raise ZipImportError('%s is not known' % fullname)
- # XXX Change the paths to start with the path to the zipfile.
- return self._handler(fullname, info[0], info[1])[0]
+ return self._handler(fullname, self._resolve_path(info[0]),
+ self._resolve_path(info[1]))[0]
def get_data(self, pathname):
"""Return the data (raw source or bytecode) for the specified module,
@@ -163,8 +171,8 @@
info = self._path_cache[fullname]
except KeyError:
raise ZipImportError('%s is not known' % fullname)
- # XXX Change paths to be os.path.join(self._path, info[0])
- code_object, path = self._handler(fullname, info[0], info[1])
+ code_object, path = self._handler(fullname, self._resolve_path(info[0]),
+ self._resolve_path(info[1]))
# XXX __path__ needs to start with the zip file.
return importlib.module_init(loader, code_object, fullname, path,
info[2])
More information about the Python-checkins
mailing list