Author: Carl Friedrich Bolz <[email protected]>
Branch: space-newtext
Changeset: r88127:a3f02433a915
Date: 2016-11-03 16:57 +0100
http://bitbucket.org/pypy/pypy/changeset/a3f02433a915/

Log:    zipimport

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
@@ -51,21 +51,21 @@
         try:
             w_zipimporter = self.cache[name]
         except KeyError:
-            raise OperationError(space.w_KeyError, space.wrap(name))
+            raise OperationError(space.w_KeyError, space.newtext(name))
         assert isinstance(w_zipimporter, W_ZipImporter)
         w = space.wrap
         w_d = space.newdict()
         for key, info in w_zipimporter.zip_file.NameToInfo.iteritems():
             if ZIPSEP != os.path.sep:
                 key = key.replace(ZIPSEP, os.path.sep)
-            space.setitem(w_d, w(key), space.newtuple([
+            space.setitem(w_d, space.newtext(key), space.newtuple([
                 w(info.filename), w(info.compress_type), w(info.compress_size),
                 w(info.file_size), w(info.file_offset), w(info.dostime),
                 w(info.dosdate), w(info.CRC)]))
         return w_d
 
     def keys(self, space):
-        return space.newlist([space.wrap(s)
+        return space.newlist([space.newtext(s)
                               for s in self.cache.keys()])
 
     def values(self, space):
@@ -75,7 +75,7 @@
 
     def items(self, space):
         w = space.wrap
-        items_w = [space.newtuple([w(key), self.getitem(space, key)])
+        items_w = [space.newtuple([space.newtext(key), self.getitem(space, 
key)])
                    for key in self.cache.keys()]
         return space.newlist(items_w)
 
@@ -126,8 +126,8 @@
 
     def getprefix(self, space):
         if ZIPSEP == os.path.sep:
-            return space.wrap(self.prefix)
-        return space.wrap(self.prefix.replace(ZIPSEP, os.path.sep))
+            return space.newtext(self.prefix)
+        return space.newtext(self.prefix.replace(ZIPSEP, os.path.sep))
 
     def _find_relative_path(self, filename):
         if filename.startswith(self.filename):
@@ -146,16 +146,15 @@
 
     def import_py_file(self, space, modname, filename, buf, pkgpath):
         w = space.wrap
-        w_mod = w(Module(space, w(modname)))
+        w_mod = Module(space, space.newtext(modname))
         real_name = self.filename + os.path.sep + self.corr_zname(filename)
-        space.setattr(w_mod, w('__loader__'), space.wrap(self))
+        space.setattr(w_mod, space.newtext('__loader__'), self)
         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)
-        return importing.exec_code_module(space, w_mod, code_w, w(modname))
+        return importing.exec_code_module(space, w_mod, code_w, 
space.newtext(modname))
 
     def _parse_mtime(self, space, filename):
-        w = space.wrap
         try:
             info = self.zip_file.NameToInfo[filename]
             t = info.date_time
@@ -163,13 +162,15 @@
             return 0
         else:
             w_mktime = space.getattr(space.getbuiltinmodule('time'),
-                                     w('mktime'))
+                                     space.newtext('mktime'))
             # XXX this is incredible fishing around module limitations
             #     in order to compare timestamps of .py and .pyc files
             # we need time.mktime support on rpython level
+            w = space.newint
             all = [w(t[0]), w(t[1]), w(t[2]), w(t[3]), w(t[4]),
                    w(t[5]), w(0), w(1), w(-1)]
-            mtime = int(space.float_w(space.call_function(w_mktime, 
space.newtuple(all))))
+            mtime = int(space.float_w(space.call_function(
+                w_mktime, space.newtuple(all))))
             return mtime
 
     def check_newer_pyfile(self, space, filename, timestamp):
@@ -194,17 +195,16 @@
         return True
 
     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 not self.can_use_pyc(space, filename, magic, timestamp):
             return None
         buf = buf[8:] # XXX ugly copy, should use sequential read instead
-        w_mod = w(Module(space, w(modname)))
+        w_mod = Module(space, space.newtext(modname))
         real_name = self.filename + os.path.sep + self.corr_zname(filename)
-        space.setattr(w_mod, w('__loader__'), space.wrap(self))
+        space.setattr(w_mod, space.newtext('__loader__'), self)
         importing._prepare_module(space, w_mod, real_name, pkgpath)
-        w_result = importing.load_compiled_module(space, w(modname), w_mod,
+        w_result = importing.load_compiled_module(space, 
space.newtext(modname), w_mod,
                                                 filename, magic, timestamp,
                                                 buf)
         return w_result
@@ -223,7 +223,7 @@
         filename = self.make_filename(fullname)
         for _, _, ext in ENUMERATE_EXTS:
             if self.have_modulefile(space, filename + ext):
-                return space.wrap(self)
+                return self
 
     def make_filename(self, fullname):
         startpos = fullname.rfind('.') + 1 # 0 when not found
@@ -245,7 +245,6 @@
 
     @unwrap_spec(fullname=str)
     def load_module(self, space, fullname):
-        w = space.wrap
         filename = self.make_filename(fullname)
         for compiled, is_package, ext in ENUMERATE_EXTS:
             fname = filename + ext
@@ -274,17 +273,16 @@
                                                    buf, pkgpath)
                 except:
                     w_mods = space.sys.get('modules')
-                    space.call_method(w_mods, 'pop', w(fullname), space.w_None)
+                    space.call_method(w_mods, 'pop', space.newtext(fullname), 
space.w_None)
                     raise
         raise oefmt(get_error(space), "can't find module '%s'", fullname)
 
     @unwrap_spec(filename=str)
     def get_data(self, space, filename):
         filename = self._find_relative_path(filename)
-        w = space.wrap
         try:
             data = self.zip_file.read(filename)
-            return w(data)
+            return space.newbytes(data)
         except (KeyError, OSError, BadZipfile):
             raise oefmt(space.w_IOError, "Error reading file")
         except RZlibError as e:
@@ -305,13 +303,13 @@
                     if not self.can_use_pyc(space, filename + ext,
                                             magic, timestamp):
                         continue
-                    code_w = importing.read_compiled_module(
+                    w_code = importing.read_compiled_module(
                         space, filename + ext, source[8:])
                 else:
                     co_filename = self.make_co_filename(filename+ext)
-                    code_w = importing.parse_source_module(
+                    w_code = importing.parse_source_module(
                         space, co_filename, source)
-                return space.wrap(code_w)
+                return w_code
         raise oefmt(get_error(space),
                     "Cannot find source or code for %s in %s",
                     filename, self.name)
@@ -337,8 +335,8 @@
         filename = self.make_filename(fullname)
         for _, is_package, ext in ENUMERATE_EXTS:
             if self.have_modulefile(space, filename + ext):
-                return space.wrap(self.filename + os.path.sep +
-                                  self.corr_zname(filename + ext))
+                return space.newtext(self.filename + os.path.sep +
+                                     self.corr_zname(filename + ext))
         raise oefmt(get_error(space),
                     "Cannot find module %s in %s", filename, self.name)
 
@@ -347,13 +345,13 @@
         filename = self.make_filename(fullname)
         for _, is_package, ext in ENUMERATE_EXTS:
             if self.have_modulefile(space, filename + ext):
-                return space.wrap(is_package)
+                return space.newbool(is_package)
         raise oefmt(get_error(space),
                     "Cannot find module %s in %s", filename, self.name)
 
     def getarchive(self, space):
         space = self.space
-        return space.wrap(self.filename)
+        return space.newtext(self.filename)
 
 @unwrap_spec(name='str0')
 def descr_new_zipimporter(space, w_type, name):
@@ -398,7 +396,7 @@
         prefix = prefix[1:]
     if prefix and not prefix.endswith(ZIPSEP) and not 
prefix.endswith(os.path.sep):
         prefix += ZIPSEP
-    w_result = space.wrap(W_ZipImporter(space, name, filename, zip_file, 
prefix))
+    w_result = W_ZipImporter(space, name, filename, zip_file, prefix)
     zip_cache.set(filename, w_result)
     return w_result
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to