From: <zy...@us...> - 2008-08-07 21:18:46
|
Revision: 5104 http://jython.svn.sourceforge.net/jython/?rev=5104&view=rev Author: zyasoft Date: 2008-08-07 21:18:44 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Replaces pkgutil.read_code with read_jython_code (diff args); this depends on the actual bytecode storage, so we have to have something specific here. get_loader special cases for the sys module, since Jython doesn't actually implement this as a module (and it appears to be a non-trivial decoupling to make it so with the current PySystemState). This fixes test_runpy. Modified Paths: -------------- branches/asm/Lib/pkgutil.py Modified: branches/asm/Lib/pkgutil.py =================================================================== --- branches/asm/Lib/pkgutil.py 2008-08-07 21:07:09 UTC (rev 5103) +++ branches/asm/Lib/pkgutil.py 2008-08-07 21:18:44 UTC (rev 5104) @@ -8,6 +8,7 @@ import imp import os.path from types import ModuleType +from org.python.core import imp as _imp, BytecodeLoader __all__ = [ 'get_importer', 'iter_importers', 'get_loader', 'find_loader', @@ -15,19 +16,15 @@ 'ImpImporter', 'ImpLoader', 'read_code', 'extend_path', ] -def read_code(stream): - # This helper is needed in order for the PEP 302 emulation to - # correctly handle compiled files - import marshal - magic = stream.read(4) - if magic != imp.get_magic(): - return None +# equivalent to CPythonLib's pkgutil.read_code except that we need +# diff args to pass into our underlying imp implementation, as +# accessed by _imp here - stream.read(4) # Skip timestamp - return marshal.load(stream) +def read_jython_code(fullname, file, filename): + data = _imp.unmarshalCode(filename, file, False) + return BytecodeLoader.makeCode(fullname + "$py", data, filename) - def simplegeneric(func): """Make a trivial single-dispatch generic function""" registry = {} @@ -276,7 +273,7 @@ elif mod_type==imp.PY_COMPILED: self._reopen() try: - self.code = read_code(self.file) + self.code = read_jython_code(fullname, self.file, self.filename) finally: self.file.close() elif mod_type==imp.PKG_DIRECTORY: @@ -451,6 +448,11 @@ if loader is not None: return loader fullname = module.__name__ + elif module_or_name == sys: + # Jython sys is not a real module; fake it here for now since + # making it a module requires a fair amount of decoupling from + # PySystemState + fullname = "sys" else: fullname = module_or_name return find_loader(fullname) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |