1. Pypy
  2. Untitled project
  3. pypy

Commits

Philip Jenvey  committed 442dad6

kill stupid softspace because it's stupid

  • Participants
  • Parent commits 80cbaa6
  • Branches py3k

Comments (0)

Files changed (7)

File pypy/interpreter/app_main.py

View file
  • Ignore whitespace
     """Calls f() and handles all OperationErrors.
     Intended use is to run the main program or one interactive statement.
     run_protected() handles details like forwarding exceptions to
-    sys.excepthook(), catching SystemExit, printing a newline after
-    sys.stdout if needed, etc.
+    sys.excepthook(), catching SystemExit, etc.
     """
     try:
         # run it
         f(*fargs, **fkwds)
-
-        # we arrive here if no exception is raised.  stdout cosmetics...
-        try:
-            stdout = sys.stdout
-            softspace = stdout.softspace
-        except AttributeError:
-            pass
-            # Don't crash if user defined stdout doesn't have softspace
-        else:
-            if softspace:
-                stdout.write('\n')
-
     except SystemExit as e:
         handle_sys_exit(e)
     except:

File pypy/interpreter/main.py

View file
  • Ignore whitespace
     """Calls f() and handle all OperationErrors.
     Intended use is to run the main program or one interactive statement.
     run_protected() handles details like forwarding exceptions to
-    sys.excepthook(), catching SystemExit, printing a newline after
-    sys.stdout if needed, etc.
+    sys.excepthook(), catching SystemExit, etc.
     """
     try:
         # run it
         f()
-
-        # we arrive here if no exception is raised.  stdout cosmetics...
-        try:
-            w_stdout = space.sys.get('stdout')
-            w_softspace = space.getattr(w_stdout, space.wrap('softspace'))
-        except OperationError, e:
-            if not e.match(space, space.w_AttributeError):
-                raise
-            # Don't crash if user defined stdout doesn't have softspace
-        else:
-            if space.is_true(w_softspace):
-                space.call_method(w_stdout, 'write', space.wrap('\n'))
-
     except OperationError, operationerr:
         operationerr.normalize_exception(space)
         w_type = operationerr.w_type

File pypy/interpreter/pyopcode.py

View file
  • Ignore whitespace
         displayhook(obj)
 
     def print_item_to(x, stream):
-        if file_softspace(stream, False):
-           stream.write(" ")
-
         # give to write() an argument which is either a string or a unicode
         # (and let it deals itself with unicode handling)
         if not isinstance(x, str):
             x = str(x)
         stream.write(x)
 
-        # add a softspace unless we just printed a string which ends in a '\t'
-        # or '\n' -- or more generally any whitespace character but ' '
-        if x:
-            lastchar = x[-1]
-            if lastchar.isspace() and lastchar != ' ':
-                return
-        file_softspace(stream, True)
-
     def print_item(x):
         print_item_to(x, sys_stdout())
 
     def print_newline_to(stream):
         stream.write("\n")
-        file_softspace(stream, False)
 
     def print_newline():
         print_newline_to(sys_stdout())
-
-    def file_softspace(file, newflag):
-        try:
-            softspace = file.softspace
-        except AttributeError:
-            softspace = 0
-        try:
-            file.softspace = newflag
-        except AttributeError:
-            pass
-        return softspace
 ''', filename=__file__)
 
 sys_stdout      = app.interphook('sys_stdout')
 print_item_to   = app.interphook('print_item_to')
 print_newline   = app.interphook('print_newline')
 print_newline_to= app.interphook('print_newline_to')
-file_softspace  = app.interphook('file_softspace')
 
 app = gateway.applevel(r'''
     def find_metaclass(bases, namespace, globals, builtin):

File pypy/interpreter/test/test_interpreter.py

View file
  • Ignore whitespace
             assert out.data == [(str, chr(0xa2)), (str, "\n")]
             del out.data[:]
             del out.encoding
-            # we don't care about softspace anymore
             print("foo\t", "bar\n", "trick", "baz\n")
             assert out.data == [(str, "foo\t"),
                                 (str, " "),

File pypy/module/__builtin__/test/test_rawinput.py

View file
  • Ignore whitespace
         finally:
             sys.stdin = stdin
         assert result == 'foo'
-
-    def test_softspace(self):
-        import sys
-        import io
-        fin = io.StringIO()
-        fout = io.StringIO()
-
-        fin.write("Coconuts\n")
-        fin.seek(0)
-
-        sys_stdin_orig = sys.stdin
-        sys_stdout_orig = sys.stdout
-
-        sys.stdin = fin
-        sys.stdout = fout
-
-        print("test", end='')
-        input("test")
-
-        sys.stdin = sys_stdin_orig
-        sys.stdout = sys_stdout_orig
-
-        fout.seek(0)
-        assert fout.read() == "testtest"
-
-    def test_softspace_carryover(self):
-        import sys
-        import io
-        fin = io.StringIO()
-        fout = io.StringIO()
-
-        fin.write("Coconuts\n")
-        fin.seek(0)
-
-        sys_stdin_orig = sys.stdin
-        sys_stdout_orig = sys.stdout
-
-        sys.stdin = fin
-        sys.stdout = fout
-
-        print("test", end='')
-        input("test")
-        print("test", end='')
-
-        sys.stdin = sys_stdin_orig
-        sys.stdout = sys_stdout_orig
-
-        fout.seek(0)
-        assert fout.read() == "testtesttest"

File pypy/module/cpyext/pyfile.py

View file
  • Ignore whitespace
 def PyFile_Name(space, w_p):
     """Return the name of the file specified by p as a string object."""
     return borrow_from(w_p, space.getattr(w_p, space.wrap("name")))
-
-@cpython_api([PyObject, rffi.INT_real], rffi.INT_real, error=CANNOT_FAIL)
-def PyFile_SoftSpace(space, w_p, newflag):
-    """
-    This function exists for internal use by the interpreter.  Set the
-    softspace attribute of p to newflag and return the previous value.
-    p does not have to be a file object for this function to work
-    properly; any object is supported (thought its only interesting if
-    the softspace attribute can be set).  This function clears any
-    errors, and will return 0 as the previous value if the attribute
-    either does not exist or if there were errors in retrieving it.
-    There is no way to detect errors from this function, but doing so
-    should not be needed."""
-    try:
-        if rffi.cast(lltype.Signed, newflag):
-            w_newflag = space.w_True
-        else:
-            w_newflag = space.w_False
-        oldflag = space.int_w(space.getattr(w_p, space.wrap("softspace")))
-        space.setattr(w_p, space.wrap("softspace"), w_newflag)
-        return oldflag
-    except OperationError, e:
-        return 0
-

File pypy/module/cpyext/test/test_pyfile.py

View file
  • Ignore whitespace
         out, err = capfd.readouterr()
         out = out.replace('\r\n', '\n')
         assert out == "test\n'test\\n'"
-
-    def test_file_softspace(self, space, api, capfd):
-        w_stdout = space.sys.get("stdout")
-        assert api.PyFile_SoftSpace(w_stdout, 1) == 0
-        assert api.PyFile_SoftSpace(w_stdout, 0) == 1
-        
-        api.PyFile_SoftSpace(w_stdout, 1)
-        w_ns = space.newdict()
-        space.exec_("print 1,", w_ns, w_ns)
-        space.exec_("print 2,", w_ns, w_ns)
-        api.PyFile_SoftSpace(w_stdout, 0)
-        space.exec_("print 3", w_ns, w_ns)
-        space.call_method(w_stdout, "flush")
-        out, err = capfd.readouterr()
-        out = out.replace('\r\n', '\n')
-        assert out == " 1 23\n"