Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r61580:442dad67f48e Date: 2013-02-21 16:40 -0800 http://bitbucket.org/pypy/pypy/changeset/442dad67f48e/
Log: kill stupid softspace because it's stupid diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -47,24 +47,11 @@ """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: diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py --- a/pypy/interpreter/main.py +++ b/pypy/interpreter/main.py @@ -95,25 +95,11 @@ """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 diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -1472,43 +1472,20 @@ 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') @@ -1517,7 +1494,6 @@ 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): diff --git a/pypy/interpreter/test/test_interpreter.py b/pypy/interpreter/test/test_interpreter.py --- a/pypy/interpreter/test/test_interpreter.py +++ b/pypy/interpreter/test/test_interpreter.py @@ -308,7 +308,6 @@ 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, " "), diff --git a/pypy/module/__builtin__/test/test_rawinput.py b/pypy/module/__builtin__/test/test_rawinput.py --- a/pypy/module/__builtin__/test/test_rawinput.py +++ b/pypy/module/__builtin__/test/test_rawinput.py @@ -51,52 +51,3 @@ 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" diff --git a/pypy/module/cpyext/pyfile.py b/pypy/module/cpyext/pyfile.py --- a/pypy/module/cpyext/pyfile.py +++ b/pypy/module/cpyext/pyfile.py @@ -81,27 +81,3 @@ 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 - diff --git a/pypy/module/cpyext/test/test_pyfile.py b/pypy/module/cpyext/test/test_pyfile.py --- a/pypy/module/cpyext/test/test_pyfile.py +++ b/pypy/module/cpyext/test/test_pyfile.py @@ -83,19 +83,3 @@ 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" _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit