Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r53672:9feca115d4d1 Date: 2012-03-14 22:25 -0700 http://bitbucket.org/pypy/pypy/changeset/9feca115d4d1/
Log: help translation diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py --- a/pypy/module/cpyext/import_.py +++ b/pypy/module/cpyext/import_.py @@ -121,5 +121,5 @@ pathname = code.co_filename w_mod = importing.add_module(space, w_name) space.setattr(w_mod, space.wrap('__file__'), space.wrap(pathname)) - importing.exec_code_module(space, w_mod, code) + importing.exec_code_module(space, w_mod, code, pathname) return w_mod diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py --- a/pypy/module/imp/importing.py +++ b/pypy/module/imp/importing.py @@ -860,8 +860,8 @@ space.wrap(space.builtin)) if pathname is not None: w_pathname = get_sourcefile(space, pathname) - if w_pathname is None: - w_pathname = code_w.w_filename + else: + w_pathname = space.wrap(code_w.co_filename) space.setitem(w_dict, space.wrap("__file__"), w_pathname) space.setitem(w_dict, space.wrap("__cached__"), space.wrap(cpathname)) code_w.exec_code(space, w_dict, w_dict) @@ -925,8 +925,9 @@ return result def get_sourcefile(space, filename): - l = len(filename) - if l < 5 or filename[-4:-1].lower() != ".py": + start = len(filename) - 4 + stop = len(filename) - 1 + if not 0 <= start <= stop or filename[start:stop].lower() != ".py": return space.wrap(filename) py = make_source_pathname(filename) if py is None: diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py --- a/pypy/module/imp/test/test_import.py +++ b/pypy/module/imp/test/test_import.py @@ -768,6 +768,29 @@ ret = space.int_w(w_ret) assert ret == 42 + def test_load_compiled_module_nopathname(self): + space = self.space + mtime = 12345 + co = compile('x = 42', '?', 'exec') + cpathname = _testfile(space, 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, + None, + magic, + timestamp, + stream.readall()) + finally: + stream.close() + filename = space.getattr(w_ret, space.wrap('__file__')) + assert space.str_w(filename) == u'?' + def test_parse_source_module(self): space = self.space pathname = _testfilesource() diff --git a/pypy/module/zipimport/interp_zipimport.py b/pypy/module/zipimport/interp_zipimport.py --- a/pypy/module/zipimport/interp_zipimport.py +++ b/pypy/module/zipimport/interp_zipimport.py @@ -150,7 +150,7 @@ importing._prepare_module(space, w_mod, real_name, pkgpath) co_filename = self.make_co_filename(filename) code_w = importing.parse_source_module(space, co_filename, buf) - importing.exec_code_module(space, w_mod, code_w) + importing.exec_code_module(space, w_mod, code_w, co_filename, None) return w_mod def _parse_mtime(self, space, filename): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit