Amaury Forgeot d'Arc committed bb38217

Convert more applevel code to py3k syntax

Comments (0)

Files changed (2)


     def iter_sentinel(callable_, sentinel):
         if not callable(callable_):
-            raise TypeError, 'iter(v, w): v must be callable'
+            raise TypeError('iter(v, w): v must be callable')
         return iter_generator(callable_, sentinel)
 ''', filename=__file__).interphook("iter_sentinel")


         optitems = options.items()
         for name, value in optitems:
-            print ' %51s: %s' % (name, value)
+            print(' %51s: %s' % (name, value))
     raise SystemExit
 def print_help(*args):
-    print 'usage: %s [options] [-c cmd|-m mod||-] [arg...]' % (
-        sys.executable,)
-    print __doc__.rstrip()
+    print('usage: %s [options] [-c cmd|-m mod||-] [arg...]' % (
+        sys.executable,))
+    print(__doc__.rstrip())
     if 'pypyjit' in sys.builtin_module_names:
-    print
+    print()
     raise SystemExit
 def _print_jit_help():
     items = pypyjit.defaults.items()
     for key, value in items:
-        print '  --jit %s=N %slow-level JIT parameter (default %s)' % (
-            key, ' '*(18-len(key)), value)
-    print '  --jit off                  turn off the JIT'
+        print('  --jit %s=N %slow-level JIT parameter (default %s)' % (
+            key, ' '*(18-len(key)), value))
+    print('  --jit off                  turn off the JIT')
 def print_version(*args):
-    print >> sys.stderr, "Python", sys.version
+    print ("Python", sys.version, file=sys.stderr)
     raise SystemExit
 def set_jit_option(options, jitparam, *args):
     if 'pypyjit' not in sys.builtin_module_names:
-        print >> sys.stderr, ("Warning: No jit support in %s" %
-                              (sys.executable,))
+        print("Warning: No jit support in %s" % (sys.executable,),
+              file=sys.stderr)
         import pypyjit
 def print_error(msg):
-    print >> sys.stderr, msg
-    print >> sys.stderr, 'usage: %s [options]' % (sys.executable,)
-    print >> sys.stderr, 'Try `%s -h` for more information.' % (sys.executable,)
+    print(msg, file=sys.stderr)
+    print('usage: %s [options]' % (sys.executable,), file=sys.stderr)
+    print('Try `%s -h` for more information.' % (sys.executable,), file=sys.stderr)
 def fdopen(fd, mode, bufsize=-1):
         dirname = resolvedirof(search)
         if dirname == search:
             # not found!  let's hope that the compiled-in path is ok
-            print >> sys.stderr, """\
+            print("""\
 debug: WARNING: Library path not found, using compiled-in sys.path.
 debug: WARNING: 'sys.prefix' will not be set.
 debug: WARNING: Make sure the pypy binary is kept inside its tree of files.
-debug: WARNING: It is ok to create a symlink to it from somewhere else."""
+debug: WARNING: It is ok to create a symlink to it from somewhere else.""",
+                  file=sys.stderr)
             newpath = sys.path[:]
         newpath = sys.pypy_initial_path(dirname)
         sys.dont_write_bytecode = bool(sys.flags.dont_write_bytecode)
         if sys.py3kwarning:
-            print >> sys.stderr, (
-                "Warning: pypy does not implement py3k warnings")
+            print("Warning: pypy does not implement py3k warnings",
+                  file=sys.stderr)
 ##    if not we_are_translated():
 ##        for key in sorted(options):
             import site
-            print >> sys.stderr, "'import site' failed"
+            print("'import site' failed", file=sys.stderr)
     readenv = not ignore_environment
     io_encoding = ((readenv and os.getenv("PYTHONIOENCODING"))
             sys.path.insert(0, '')
             def run_it():
-                exec run_command in mainmodule.__dict__
+                exec(run_command, mainmodule.__dict__)
             success = run_toplevel(run_it)
         elif run_module:
             # handle the "-m" command
                         startup =
                     except IOError, e:
-                        print >> sys.stderr, "Could not open PYTHONSTARTUP"
-                        print >> sys.stderr, "IOError:", e
+                        print("Could not open PYTHONSTARTUP", file=sys.stderr)
+                        print("IOError:", e, file=sys.stderr)
                         def run_it():
                             co_python_startup = compile(startup,
-                            exec co_python_startup in mainmodule.__dict__
+                            exec(co_python_startup, mainmodule.__dict__)
                 # Then we need a prompt.
                 inspect = True
                 # If not interactive, just read and execute stdin normally.
                 def run_it():
                     co_stdin = compile(, '<stdin>', 'exec')
-                    exec co_stdin in mainmodule.__dict__
+                    exec(co_stdin, mainmodule.__dict__)
                 mainmodule.__file__ = '<stdin>'
                 success = run_toplevel(run_it)
     return dirname
 def print_banner():
-    print 'Python %s on %s' % (sys.version, sys.platform)
-    print ('Type "help", "copyright", "credits" or '
-           '"license" for more information.')
+    print('Python %s on %s' % (sys.version, sys.platform))
+    print('Type "help", "copyright", "credits" or '
+          '"license" for more information.')
 def entry_point(executable, argv, nanos):
     setup_sys_executable(executable, nanos)
         assert filename.endswith('.pyc')
         assert file is None
         assert module.__name__ == '__main__'
-        print 'in _run_compiled_module'
+        print('in _run_compiled_module')
     def _getimporter(path):
         import os, imp
         if os.path.isdir(path):