Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: space-newtext
Changeset: r88262:ea22f9a7e6e7
Date: 2016-11-08 14:38 +0100
http://bitbucket.org/pypy/pypy/changeset/ea22f9a7e6e7/

Log:    imp

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
@@ -61,7 +61,7 @@
     verbose = space.sys.get_flag('verbose')
     if verbose >= level:
         w_stderr = space.sys.get('stderr')
-        space.call_method(w_stderr, "write", space.wrap(message))
+        space.call_method(w_stderr, "write", space.newtext(message))
 
 def file_exists(path):
     """Tests whether the given path is an existing regular file."""
@@ -152,7 +152,6 @@
     return result
 
 def _get_relative_name(space, modulename, level, w_globals):
-    w = space.wrap
     ctxt_w_package = space.finditem_str(w_globals, '__package__')
     ctxt_w_package = jit.promote(ctxt_w_package)
     level = jit.promote(level)
@@ -193,7 +192,7 @@
             else:
                 msg = ("Parent module '%s' not found while handling absolute "
                        "import" % ctxt_package)
-                space.warn(space.wrap(msg), space.w_RuntimeWarning)
+                space.warn(space.newtext(msg), space.w_RuntimeWarning)
 
         rel_modulename = ctxt_package[:dot_position]
         rel_level = rel_modulename.count('.') + 1
@@ -232,15 +231,15 @@
 
         if ctxt_w_path is not None:
             # __path__ is set, so __name__ is already the package name
-            space.setitem(w_globals, w("__package__"), ctxt_w_name)
+            space.setitem(w_globals, space.newtext("__package__"), ctxt_w_name)
         else:
             # Normal module, so work out the package name if any
             last_dot_position = ctxt_name.rfind('.')
             if last_dot_position < 0:
-                space.setitem(w_globals, w("__package__"), space.w_None)
+                space.setitem(w_globals, space.newtext("__package__"), 
space.w_None)
             else:
-                space.setitem(w_globals, w("__package__"),
-                              w(ctxt_name[:last_dot_position]))
+                space.setitem(w_globals, space.newtext("__package__"),
+                              space.newtext(ctxt_name[:last_dot_position]))
 
         if modulename:
             if rel_modulename:
@@ -257,7 +256,6 @@
     modulename = name
     if not modulename and level < 0:
         raise oefmt(space.w_ValueError, "Empty module name")
-    w = space.wrap
 
     if w_fromlist is not None and not space.is_true(w_fromlist):
         w_fromlist = None
@@ -291,7 +289,7 @@
 
     w_mod = absolute_import(space, modulename, 0, w_fromlist, tentative=0)
     if rel_modulename is not None:
-        space.setitem(space.sys.get('modules'), w(rel_modulename), 
space.w_None)
+        space.setitem(space.sys.get('modules'), space.newtext(rel_modulename), 
space.w_None)
     return w_mod
 
 def absolute_import(space, modulename, baselevel, w_fromlist, tentative):
@@ -329,7 +327,7 @@
         w_mod = check_sys_modules_w(space, modulename)
         first = w_mod
         if w_fromlist is not None and w_mod is not None:
-            w_path = try_getattr(space, w_mod, space.wrap('__path__'))
+            w_path = try_getattr(space, w_mod, space.newtext('__path__'))
     else:
         level = 0
         first = None
@@ -344,7 +342,7 @@
             if level == baselevel:
                 first = w_mod
             if w_fromlist is not None:
-                w_path = try_getattr(space, w_mod, space.wrap('__path__'))
+                w_path = try_getattr(space, w_mod, space.newtext('__path__'))
             level += 1
     if w_fromlist is not None:
         # bit artificial code but important to not just unwrap w_fromlist
@@ -353,9 +351,9 @@
         if w_path is not None:
             length = space.len_w(w_fromlist)
             if length == 1 and space.eq_w(
-                    space.getitem(w_fromlist, space.wrap(0)),
-                    space.wrap('*')):
-                w_all = try_getattr(space, w_mod, space.wrap('__all__'))
+                    space.getitem(w_fromlist, space.newint(0)),
+                    space.newtext('*')):
+                w_all = try_getattr(space, w_mod, space.newtext('__all__'))
                 if w_all is not None:
                     w_fromlist = w_all
                     length = space.len_w(w_fromlist)
@@ -367,15 +365,13 @@
 
             if w_fromlist is not None:
                 for i in range(length):
-                    w_name = space.getitem(w_fromlist, space.wrap(i))
+                    w_name = space.getitem(w_fromlist, space.newint(i))
                     if try_getattr(space, w_mod, w_name) is None:
                         return None
         return w_mod
     return first
 
 def _absolute_import(space, modulename, baselevel, w_fromlist, tentative):
-    w = space.wrap
-
     if '/' in modulename or '\\' in modulename:
         raise oefmt(space.w_ImportError,
                     "Import by filename is not supported.")
@@ -398,16 +394,16 @@
             first = w_mod
             tentative = 0
         prefix.append(part)
-        w_path = try_getattr(space, w_mod, w('__path__'))
+        w_path = try_getattr(space, w_mod, space.newtext('__path__'))
         level += 1
 
     if w_fromlist is not None:
         if w_path is not None:
             length = space.len_w(w_fromlist)
             if length == 1 and space.eq_w(
-                    space.getitem(w_fromlist, space.wrap(0)),
-                    space.wrap('*')):
-                w_all = try_getattr(space, w_mod, w('__all__'))
+                    space.getitem(w_fromlist, space.newint(0)),
+                    space.newtext('*')):
+                w_all = try_getattr(space, w_mod, space.newtext('__all__'))
                 if w_all is not None:
                     w_fromlist = w_all
                     length = space.len_w(w_fromlist)
@@ -415,7 +411,7 @@
                     w_fromlist = None
             if w_fromlist is not None:
                 for i in range(length):
-                    w_name = space.getitem(w_fromlist, space.wrap(i))
+                    w_name = space.getitem(w_fromlist, space.newint(i))
                     if try_getattr(space, w_mod, w_name) is None:
                         load_part(space, w_path, prefix, space.str0_w(w_name),
                                   w_mod, tentative=1)
@@ -492,7 +488,7 @@
                 raise oefmt(space.w_ImportError, "existing directory")
 
     def find_module_w(self, space, __args__):
-        return space.wrap(None)
+        return space.w_None
 
 W_NullImporter.typedef = TypeDef(
     'imp.NullImporter',
@@ -567,7 +563,7 @@
                 else:
                     msg = ("Not importing directory '%s' missing __init__.py" %
                            (filepart,))
-                    space.warn(space.wrap(msg), space.w_ImportWarning)
+                    space.warn(space.newtext(msg), space.w_ImportWarning)
             modtype, suffix, filemode = find_modtype(space, filepart)
             try:
                 if modtype in (PY_SOURCE, PY_COMPILED, C_EXTENSION):
@@ -587,17 +583,16 @@
     return delayed_builtin
 
 def _prepare_module(space, w_mod, filename, pkgdir):
-    w = space.wrap
     space.sys.setmodule(w_mod)
-    space.setattr(w_mod, w('__file__'), space.wrap(filename))
-    space.setattr(w_mod, w('__doc__'), space.w_None)
+    space.setattr(w_mod, space.newtext('__file__'), space.newtext(filename))
+    space.setattr(w_mod, space.newtext('__doc__'), space.w_None)
     if pkgdir is not None:
-        space.setattr(w_mod, w('__path__'), space.newlist([w(pkgdir)]))
+        space.setattr(w_mod, space.newtext('__path__'), 
space.newlist([space.newtext(pkgdir)]))
 
 def add_module(space, w_name):
     w_mod = check_sys_modules(space, w_name)
     if w_mod is None:
-        w_mod = space.wrap(Module(space, w_name))
+        w_mod = Module(space, w_name)
         space.sys.setmodule(w_mod)
     return w_mod
 
@@ -634,7 +629,7 @@
                 if not oe.match(space, space.w_KeyError):
                     raise
         if w_mod is None:
-            w_mod = space.wrap(Module(space, w_modulename))
+            w_mod = Module(space, w_modulename)
         if find_info.modtype == PKG_DIRECTORY:
             pkgdir = find_info.filename
         else:
@@ -653,8 +648,8 @@
                 return load_compiled_module(space, w_modulename, w_mod, 
find_info.filename,
                                      magic, timestamp, 
find_info.stream.readall())
             elif find_info.modtype == PKG_DIRECTORY:
-                w_path = space.newlist([space.wrap(find_info.filename)])
-                space.setattr(w_mod, space.wrap('__path__'), w_path)
+                w_path = space.newlist([space.newtext(find_info.filename)])
+                space.setattr(w_mod, space.newtext('__path__'), w_path)
                 find_info = find_module(space, "__init__", None, "__init__",
                                         w_path, use_loader=False)
                 if find_info is None:
@@ -677,9 +672,8 @@
             raise
 
 def load_part(space, w_path, prefix, partname, w_parent, tentative):
-    w = space.wrap
     modulename = '.'.join(prefix + [partname])
-    w_modulename = w(modulename)
+    w_modulename = space.newtext(modulename)
     w_mod = check_sys_modules(space, w_modulename)
 
     if w_mod is not None:
@@ -693,7 +687,7 @@
             if find_info:
                 w_mod = load_module(space, w_modulename, find_info)
                 if w_parent is not None:
-                    space.setattr(w_parent, space.wrap(partname), w_mod)
+                    space.setattr(w_parent, space.newtext(partname), w_mod)
                 return w_mod
         finally:
             if find_info:
@@ -717,7 +711,7 @@
     if not space.is_w(space.type(w_module), space.type(space.sys)):
         raise oefmt(space.w_TypeError, "reload() argument must be module")
 
-    w_modulename = space.getattr(w_module, space.wrap("__name__"))
+    w_modulename = space.getattr(w_module, space.newtext("__name__"))
     modulename = space.str0_w(w_modulename)
     if not space.is_w(check_sys_modules(space, w_modulename), w_module):
         raise oefmt(space.w_ImportError,
@@ -741,7 +735,7 @@
                 raise oefmt(space.w_ImportError,
                             "reload(): parent %s not in sys.modules",
                             parent_name)
-            w_path = space.getattr(w_parent, space.wrap("__path__"))
+            w_path = space.getattr(w_parent, space.newtext("__path__"))
         else:
             w_path = None
 
@@ -888,10 +882,10 @@
     Execute a code object in the module's dict.  Returns
     'sys.modules[modulename]', which must exist.
     """
-    w_dict = space.getattr(w_mod, space.wrap('__dict__'))
+    w_dict = space.getattr(w_mod, space.newtext('__dict__'))
     space.call_method(w_dict, 'setdefault',
-                      space.wrap('__builtins__'),
-                      space.wrap(space.builtin))
+                      space.newtext('__builtins__'),
+                      space.builtin)
     code_w.exec_code(space, w_dict, w_dict)
 
     if check_afterwards:
@@ -910,7 +904,6 @@
     Load a source module from a given file.  Returns the result
     of sys.modules[modulename], which must exist.
     """
-    w = space.wrap
 
     log_pyverbose(space, 1, "import %s # from %s\n" %
                   (space.str_w(w_modulename), pathname))
@@ -930,7 +923,7 @@
                 stream.close()
             except StreamErrors:
                 pass
-        space.setattr(w_mod, w('__file__'), w(cpathname))
+        space.setattr(w_mod, space.newtext('__file__'), 
space.newtext(cpathname))
     else:
         code_w = parse_source_module(space, pathname, source)
 
@@ -1024,7 +1017,7 @@
     """ Read a code object from a file and check it for validity """
 
     w_marshal = space.getbuiltinmodule('marshal')
-    w_code = space.call_method(w_marshal, 'loads', space.wrap(strbuf))
+    w_code = space.call_method(w_marshal, 'loads', space.newbytes(strbuf))
     if not isinstance(w_code, Code):
         raise oefmt(space.w_ImportError, "Non-code object in %s", cpathname)
     return w_code
@@ -1074,8 +1067,8 @@
     """
     w_marshal = space.getbuiltinmodule('marshal')
     try:
-        w_str = space.call_method(w_marshal, 'dumps', space.wrap(co),
-                                  space.wrap(MARSHAL_VERSION_FOR_PYC))
+        w_str = space.call_method(w_marshal, 'dumps', co,
+                                  space.newint(MARSHAL_VERSION_FOR_PYC))
         strbuf = space.str_w(w_str)
     except OperationError as e:
         if e.async(space):
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -58,7 +58,7 @@
     if not find_info:
         raise oefmt(space.w_ImportError, "No module named %s", name)
 
-    w_filename = space.wrap(find_info.filename)
+    w_filename = space.newtext(find_info.filename)
     stream = find_info.stream
 
     if stream is not None:
@@ -66,13 +66,13 @@
         fileobj.fdopenstream(
             stream, stream.try_to_find_file_descriptor(),
             find_info.filemode, w_filename)
-        w_fileobj = space.wrap(fileobj)
+        w_fileobj = fileobj
     else:
         w_fileobj = space.w_None
     w_import_info = space.newtuple(
-        [space.wrap(find_info.suffix),
-         space.wrap(find_info.filemode),
-         space.wrap(find_info.modtype)])
+        [space.newtext(find_info.suffix),
+         space.newtext(find_info.filemode),
+         space.newint(find_info.modtype)])
     return space.newtuple([w_fileobj, w_filename, w_import_info])
 
 def load_module(space, w_name, w_file, w_filename, w_info):
@@ -99,7 +99,7 @@
 
     stream = get_file(space, w_file, filename, 'U')
 
-    w_mod = space.wrap(Module(space, w_modulename))
+    w_mod = Module(space, w_modulename)
     importing._prepare_module(space, w_mod, filename, None)
 
     w_mod = importing.load_source_module(
@@ -127,7 +127,7 @@
 
 @unwrap_spec(filename='str0')
 def load_compiled(space, w_modulename, filename, w_file=None):
-    w_mod = space.wrap(Module(space, w_modulename))
+    w_mod = Module(space, w_modulename)
     importing._prepare_module(space, w_mod, filename, None)
     return _run_compiled_module(space, w_modulename, filename, w_file, w_mod,
                                 check_afterwards=True)
@@ -140,7 +140,7 @@
     return importing.check_sys_modules(space, w_modulename)
 
 def new_module(space, w_name):
-    return space.wrap(Module(space, w_name, add_package=False))
+    return Module(space, w_name, add_package=False)
 
 def init_builtin(space, w_name):
     name = space.str0_w(w_name)
@@ -157,10 +157,10 @@
 def is_builtin(space, w_name):
     name = space.str0_w(w_name)
     if name not in space.builtin_modules:
-        return space.wrap(0)
+        return space.newint(0)
     if space.finditem(space.sys.get('modules'), w_name) is not None:
-        return space.wrap(-1)   # cannot be initialized again
-    return space.wrap(1)
+        return space.newint(-1)   # cannot be initialized again
+    return space.newint(1)
 
 def is_frozen(space, w_name):
     return space.w_False
@@ -169,7 +169,7 @@
 
 def lock_held(space):
     if space.config.objspace.usemodules.thread:
-        return space.wrap(importing.getimportlock(space).lock_held_by_anyone())
+        return 
space.newbool(importing.getimportlock(space).lock_held_by_anyone())
     else:
         return space.w_False
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to