def test_pyc_magic_changes(self): py.test.skip("For now, PyPy generates only one kind of .pyc files") # test that the pyc files produced by a space are not reimportable # from another, if they differ in what opcodes they support allspaces = [self.space] for opcodename in self.space.config.objspace.opcodes.getpaths(): key = 'objspace.opcodes.' + opcodename space2 = maketestobjspace(make_config(None, **{key: True})) allspaces.append(space2) for space1 in allspaces: for space2 in allspaces: if space1 is space2: continue pathname = "whatever" mtime = 12345 co = compile('x = 42', '?', 'exec') cpathname = _testfile(importing.get_pyc_magic(space1), mtime, co) w_modulename = space2.wrap('somemodule') stream = streamio.open_file_as_stream(cpathname, "rb") try: w_mod = space2.wrap(Module(space2, w_modulename)) magic = importing._r_long(stream) timestamp = importing._r_long(stream) space2.raises_w(space2.w_ImportError, importing.load_compiled_module, space2, w_modulename, w_mod, cpathname, magic, timestamp, stream.readall()) finally: stream.close()
def _run_compiled_module(space, w_modulename, filename, w_file, w_module): # the function 'imp._run_compiled_module' is a pypy-only extension stream = get_file(space, w_file, filename, "rb") magic = importing._r_long(stream) timestamp = importing._r_long(stream) importing.load_compiled_module(space, w_modulename, w_module, filename, magic, timestamp, stream.readall()) if space.is_w(w_file, space.w_None): stream.close()
def _run_compiled_module(space, w_modulename, filename, w_file, w_module): # the function 'imp._run_compiled_module' is a pypy-only extension stream = get_file(space, w_file, filename, 'rb') magic = importing._r_long(stream) timestamp = importing._r_long(stream) importing.load_compiled_module(space, w_modulename, w_module, filename, magic, timestamp, stream.readall()) if space.is_w(w_file, space.w_None): stream.close()
def _run_compiled_module(space, w_modulename, filename, w_file, w_module, write_paths=True): # the function 'imp._run_compiled_module' is a pypy-only extension stream = get_file(space, w_file, filename, 'rb') magic = importing._r_long(stream) timestamp = importing._r_long(stream) importing.load_compiled_module( space, w_modulename, w_module, filename, magic, timestamp, stream.readall(), write_paths) if space.is_none(w_file): stream.close()
def _run_compiled_module(space, w_modulename, filename, w_file, w_module, check_afterwards=False): # the function 'imp._run_compiled_module' is a pypy-only extension stream = get_file(space, w_file, filename, 'rb') magic = importing._r_long(stream) timestamp = importing._r_long(stream) w_mod = importing.load_compiled_module( space, w_modulename, w_module, filename, magic, timestamp, stream.readall(), check_afterwards=check_afterwards) if space.is_none(w_file): stream.close() return w_mod
def load_compiled(space, w_modulename, w_filename, w_file=None): filename = space.str_w(w_filename) stream = get_file(space, w_file, filename, 'rb') w_mod = space.wrap(Module(space, w_modulename)) importing._prepare_module(space, w_mod, filename, None) magic = importing._r_long(stream) timestamp = importing._r_long(stream) importing.load_compiled_module( space, w_modulename, w_mod, filename, magic, timestamp, stream.readall()) if space.is_w(w_file, space.w_None): stream.close() return w_mod
def test_load_compiled_module(self): space = self.space 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, "rb") try: w_mod = space.wrap(Module(space, w_modulename)) magic = importing._r_long(stream) timestamp = importing._r_long(stream) w_ret = _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 test_long_writes(self): pathname = str(udir.join('test.dat')) stream = streamio.open_file_as_stream(pathname, "wb") try: importing._w_long(stream, 42) importing._w_long(stream, 12312) importing._w_long(stream, 128397198) finally: stream.close() stream = streamio.open_file_as_stream(pathname, "rb") try: res = importing._r_long(stream) assert res == 42 res = importing._r_long(stream) assert res == 12312 res = importing._r_long(stream) assert res == 128397198 finally: stream.close()
def test_load_compiled_module(self): space = self.space 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, "rb") 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