Commits

Amaury Forgeot d'Arc  committed ca4dcce

zipimport.get_source() returns a unicode string. Test and fix.

  • Participants
  • Parent commits a509478
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/module/zipimport/interp_zipimport.py

             fname = filename + ext
             if self.have_modulefile(space, fname):
                 if not compiled:
-                    return self.get_data(space, fname)
+                    w_data = self.get_data(space, fname)
+                    # XXX CPython does not handle the coding cookie either.
+                    return space.call_method(w_data, "decode",
+                                             space.wrap("utf-8")) 
                 else:
                     found = True
         if found:
+            # We have the module, but no source.
             return space.w_None
         raise operationerrfmt(get_error(space),
             "Cannot find source for %s in %s", filename, self.name)

File pypy/module/zipimport/test/test_zipimport.py

         assert z.get_data(self.zipfile + os.sep + "xxx") == data
         assert z.is_package("xx")
         assert not z.is_package("yy")
-        assert z.get_source("yy") == b'3'
+        assert z.get_source("yy") == '3'
         assert z.get_source('uu') is None
         raises(ImportError, "z.get_source('zz')")
         #assert z.get_code('yy') == py.code.Source('3').compile()
         #assert z.get_code('uu') == self.co
         assert z.get_code('xx')
-        assert z.get_source('xx') == b"5"
+        assert z.get_source('xx') == "5"
         assert z.archive == self.zipfile
         mod = z.load_module('xx')
         assert z.get_filename('xx') == mod.__file__