def test_load_compiled_module(self): space = self.space pathname = "whatever" mtime = 12345 co = compile('x = 42', '?', 'exec') cpathname = _testfile(importing.get_pyc_magic(space), mtime, co) w_modulename = space.wrap('somemodule') stream = streamio.open_file_as_stream(cpathname, "r") try: w_mod = space.wrap(Module(space, w_modulename)) magic = importing._r_long(stream) timestamp = importing._r_long(stream) w_ret = importing.load_compiled_module(space, w_modulename, w_mod, cpathname, magic, timestamp, stream.readall()) finally: stream.close() assert w_mod is w_ret w_ret = space.getattr(w_mod, space.wrap('x')) ret = space.int_w(w_ret) assert ret == 42
def import_pyc_file(self, space, modname, filename, w_buf, pkgpath): w = space.wrap buf = space.str_w(w_buf) magic = importing._get_long(buf[:4]) timestamp = importing._get_long(buf[4:8]) if self.check_newer_pyfile(space, filename[:-1], timestamp): return self.import_py_file(space, modname, filename[:-1], w_buf, pkgpath) buf = buf[8:] # XXX ugly copy, should use sequential read instead w_mod = w(Module(space, w(modname))) real_name = self.name + os.path.sep + filename importing._prepare_module(space, w_mod, real_name, pkgpath) result = importing.load_compiled_module(space, w(modname), w_mod, filename, magic, timestamp, buf) space.setattr(w_mod, w('__loader__'), space.wrap(self)) return result
def import_pyc_file(self, space, modname, filename, buf, pkgpath): w = space.wrap magic = importing._get_long(buf[:4]) timestamp = importing._get_long(buf[4:8]) if (self.check_newer_pyfile(space, filename[:-1], timestamp) or not self.check_compatible_mtime(space, filename, timestamp)): return self.import_py_file(space, modname, filename[:-1], buf, pkgpath) buf = buf[8:] # XXX ugly copy, should use sequential read instead w_mod = w(Module(space, w(modname))) real_name = self.name + os.path.sep + self.corr_zname(filename) space.setattr(w_mod, w('__loader__'), space.wrap(self)) importing._prepare_module(space, w_mod, real_name, pkgpath) result = importing.load_compiled_module(space, w(modname), w_mod, filename, magic, timestamp, buf) return result