Commits

Philip Jenvey committed 9feca11

help translation

  • Participants
  • Parent commits 159f82a
  • Branches py3k

Comments (0)

Files changed (4)

File pypy/module/cpyext/import_.py

         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

File pypy/module/imp/importing.py

                       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)
     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:

File pypy/module/imp/test/test_import.py

         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()

File pypy/module/zipimport/interp_zipimport.py

         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):