[Python-3000-checkins] r53715 - in python/branches/p3yk: Include/ceval.h Include/fileobject.h Lib/StringIO.py Lib/bsddb/dbrecio.py Lib/code.py Lib/doctest.py Lib/idlelib/PyShell.py Lib/idlelib/run.py Lib/socket.py Lib/test/test_doctest.txt Lib/test/test_file.py Lib/test/test_inspect.py Lib/test/test_softspace.py Modules/bz2module.c Modules/cStringIO.c Objects/fileobject.c Python/ceval.c Python/pythonrun.c Python/sysmodule.c

guido.van.rossum python-3000-checkins at python.org
Sat Feb 10 00:20:23 CET 2007


Author: guido.van.rossum
Date: Sat Feb 10 00:20:19 2007
New Revision: 53715

Removed:
   python/branches/p3yk/Lib/test/test_softspace.py
Modified:
   python/branches/p3yk/Include/ceval.h
   python/branches/p3yk/Include/fileobject.h
   python/branches/p3yk/Lib/StringIO.py
   python/branches/p3yk/Lib/bsddb/dbrecio.py
   python/branches/p3yk/Lib/code.py
   python/branches/p3yk/Lib/doctest.py
   python/branches/p3yk/Lib/idlelib/PyShell.py
   python/branches/p3yk/Lib/idlelib/run.py
   python/branches/p3yk/Lib/socket.py
   python/branches/p3yk/Lib/test/test_doctest.txt
   python/branches/p3yk/Lib/test/test_file.py
   python/branches/p3yk/Lib/test/test_inspect.py
   python/branches/p3yk/Modules/bz2module.c
   python/branches/p3yk/Modules/cStringIO.c
   python/branches/p3yk/Objects/fileobject.c
   python/branches/p3yk/Python/ceval.c
   python/branches/p3yk/Python/pythonrun.c
   python/branches/p3yk/Python/sysmodule.c
Log:
Kill off softspace completely (except in formatter.py which seems to have
a different feature with the same name).
The change to test_doctest.txt reduces the doctest failures to 3.


Modified: python/branches/p3yk/Include/ceval.h
==============================================================================
--- python/branches/p3yk/Include/ceval.h	(original)
+++ python/branches/p3yk/Include/ceval.h	Sat Feb 10 00:20:19 2007
@@ -40,8 +40,6 @@
    flag was set, else return 0. */
 PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
 
-PyAPI_FUNC(int) Py_FlushLine(void);
-
 PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
 PyAPI_FUNC(int) Py_MakePendingCalls(void);
 

Modified: python/branches/p3yk/Include/fileobject.h
==============================================================================
--- python/branches/p3yk/Include/fileobject.h	(original)
+++ python/branches/p3yk/Include/fileobject.h	Sat Feb 10 00:20:19 2007
@@ -13,7 +13,6 @@
 	PyObject *f_name;
 	PyObject *f_mode;
 	int (*f_close)(FILE *);
-	int f_softspace;	/* Flag used by 'print' command */
 	int f_binary;		/* Flag which indicates whether the file is 
 				   open in binary (1) or text (0) mode */
 	char* f_buf;		/* Allocated readahead buffer */
@@ -41,7 +40,6 @@
 PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
 PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
 PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
-PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
 PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
 PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
 

Modified: python/branches/p3yk/Lib/StringIO.py
==============================================================================
--- python/branches/p3yk/Lib/StringIO.py	(original)
+++ python/branches/p3yk/Lib/StringIO.py	Sat Feb 10 00:20:19 2007
@@ -60,7 +60,6 @@
         self.buflist = []
         self.pos = 0
         self.closed = False
-        self.softspace = 0
 
     def __iter__(self):
         return self

Modified: python/branches/p3yk/Lib/bsddb/dbrecio.py
==============================================================================
--- python/branches/p3yk/Lib/bsddb/dbrecio.py	(original)
+++ python/branches/p3yk/Lib/bsddb/dbrecio.py	Sat Feb 10 00:20:19 2007
@@ -39,7 +39,6 @@
         self.len = None
         self.pos = 0
         self.closed = 0
-        self.softspace = 0
 
     def close(self):
         if not self.closed:

Modified: python/branches/p3yk/Lib/code.py
==============================================================================
--- python/branches/p3yk/Lib/code.py	(original)
+++ python/branches/p3yk/Lib/code.py	Sat Feb 10 00:20:19 2007
@@ -12,19 +12,6 @@
 __all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact",
            "compile_command"]
 
-def softspace(file, newvalue):
-    oldvalue = 0
-    try:
-        oldvalue = file.softspace
-    except AttributeError:
-        pass
-    try:
-        file.softspace = newvalue
-    except (AttributeError, TypeError):
-        # "attribute-less object" or "read-only attributes"
-        pass
-    return oldvalue
-
 class InteractiveInterpreter:
     """Base class for InteractiveConsole.
 
@@ -105,9 +92,6 @@
             raise
         except:
             self.showtraceback()
-        else:
-            if softspace(sys.stdout, 0):
-                print()
 
     def showsyntaxerror(self, filename=None):
         """Display the syntax error that just occurred.

Modified: python/branches/p3yk/Lib/doctest.py
==============================================================================
--- python/branches/p3yk/Lib/doctest.py	(original)
+++ python/branches/p3yk/Lib/doctest.py	Sat Feb 10 00:20:19 2007
@@ -240,16 +240,10 @@
         # that a trailing newline is missing.
         if result and not result.endswith("\n"):
             result += "\n"
-        # Prevent softspace from screwing up the next test case, in
-        # case they used print with a trailing comma in an example.
-        if hasattr(self, "softspace"):
-            del self.softspace
         return result
 
-    def truncate(self,   size=None):
+    def truncate(self, size=None):
         StringIO.truncate(self, size)
-        if hasattr(self, "softspace"):
-            del self.softspace
 
 # Worst-case linear-time ellipsis matching.
 def _ellipsis_match(want, got):

Modified: python/branches/p3yk/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/p3yk/Lib/idlelib/PyShell.py	(original)
+++ python/branches/p3yk/Lib/idlelib/PyShell.py	Sat Feb 10 00:20:19 2007
@@ -1223,7 +1223,6 @@
             self.text.insert("end-1c", "\n")
         self.text.mark_set("iomark", "end-1c")
         self.set_line_and_column()
-        sys.stdout.softspace = 0
 
     def write(self, s, tags=()):
         try:
@@ -1242,7 +1241,6 @@
     def __init__(self, shell, tags, encoding=None):
         self.shell = shell
         self.tags = tags
-        self.softspace = 0
         self.encoding = encoding
 
     def write(self, s):

Modified: python/branches/p3yk/Lib/idlelib/run.py
==============================================================================
--- python/branches/p3yk/Lib/idlelib/run.py	(original)
+++ python/branches/p3yk/Lib/idlelib/run.py	Sat Feb 10 00:20:19 2007
@@ -190,12 +190,7 @@
         tb[i] = fn, ln, nm, line
 
 def flush_stdout():
-    try:
-        if sys.stdout.softspace:
-            sys.stdout.softspace = 0
-            sys.stdout.write("\n")
-    except (AttributeError, EOFError):
-        pass
+    """XXX How to do this now?"""
 
 def exit():
     """Exit subprocess, possibly after first deleting sys.exitfunc

Modified: python/branches/p3yk/Lib/socket.py
==============================================================================
--- python/branches/p3yk/Lib/socket.py	(original)
+++ python/branches/p3yk/Lib/socket.py	Sat Feb 10 00:20:19 2007
@@ -202,7 +202,7 @@
     default_bufsize = 8192
     name = "<socket>"
 
-    __slots__ = ["mode", "bufsize", "softspace",
+    __slots__ = ["mode", "bufsize",
                  # "closed" is a property, see below
                  "_sock", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf",
                  "_close"]
@@ -213,7 +213,6 @@
         if bufsize < 0:
             bufsize = self.default_bufsize
         self.bufsize = bufsize
-        self.softspace = False
         if bufsize == 0:
             self._rbufsize = 1
         elif bufsize == 1:

Modified: python/branches/p3yk/Lib/test/test_doctest.txt
==============================================================================
--- python/branches/p3yk/Lib/test/test_doctest.txt	(original)
+++ python/branches/p3yk/Lib/test/test_doctest.txt	Sat Feb 10 00:20:19 2007
@@ -9,9 +9,9 @@
 We can make this fail by disabling the blank-line feature.
 
   >>> if 1:
-  ...    print 'a'
-  ...    print
-  ...    print 'b'
+  ...    print('a')
+  ...    print()
+  ...    print('b')
   a
   <BLANKLINE>
   b

Modified: python/branches/p3yk/Lib/test/test_file.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_file.py	(original)
+++ python/branches/p3yk/Lib/test/test_file.py	Sat Feb 10 00:20:19 2007
@@ -30,14 +30,10 @@
     def testAttributes(self):
         # verify expected attributes exist
         f = self.f
-        softspace = f.softspace
         f.name     # merely shouldn't blow up
         f.mode     # ditto
         f.closed   # ditto
 
-        # verify softspace is writable
-        f.softspace = softspace    # merely shouldn't blow up
-
         # verify the others aren't
         for attr in 'name', 'mode', 'closed':
             self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops')

Modified: python/branches/p3yk/Lib/test/test_inspect.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_inspect.py	(original)
+++ python/branches/p3yk/Lib/test/test_inspect.py	Sat Feb 10 00:20:19 2007
@@ -61,7 +61,6 @@
         self.istest(inspect.ismodule, 'mod')
         self.istest(inspect.istraceback, 'tb')
         self.istest(inspect.isdatadescriptor, '__builtin__.file.closed')
-        self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace')
         if hasattr(types, 'GetSetDescriptorType'):
             self.istest(inspect.isgetsetdescriptor,
                         'type(tb.tb_frame).f_locals')

Deleted: /python/branches/p3yk/Lib/test/test_softspace.py
==============================================================================
--- /python/branches/p3yk/Lib/test/test_softspace.py	Sat Feb 10 00:20:19 2007
+++ (empty file)
@@ -1,14 +0,0 @@
-from test import test_support
-import StringIO
-
-# SF bug 480215:  softspace confused in nested print
-f = StringIO.StringIO()
-class C:
-    def __str__(self):
-        print('a', file=f)
-        return 'b'
-
-print(C(), 'c ', 'd\t', 'e', file=f)
-print('f', 'g', file=f)
-# In 2.2 & earlier, this printed ' a\nbc  d\te\nf g\n'
-test_support.vereq(f.getvalue(), 'a\nb c  d\te\nf g\n')

Modified: python/branches/p3yk/Modules/bz2module.c
==============================================================================
--- python/branches/p3yk/Modules/bz2module.c	(original)
+++ python/branches/p3yk/Modules/bz2module.c	Sat Feb 10 00:20:19 2007
@@ -102,8 +102,6 @@
 	char* f_bufend;		/* Points after last occupied position */
 	char* f_bufptr;		/* Current buffer position */
 
-	int f_softspace;	/* Flag used by 'print' command */
-
 	int f_univ_newline;	/* Handle any newline convention */
 	int f_newlinetypes;	/* Types of newlines seen */
 	int f_skipnextlf;	/* Skip next \n */
@@ -813,8 +811,6 @@
 			goto cleanup;
 	}
 
-	self->f_softspace = 0;
-
 	Py_BEGIN_ALLOW_THREADS
 	BZ2_bzWrite (&bzerror, self->fp, buf, len);
 	self->pos += len;
@@ -934,8 +930,6 @@
 			}
 		}
 
-		self->f_softspace = 0;
-
 		/* Since we are releasing the global lock, the
 		   following code may *not* execute Python code. */
 		Py_BEGIN_ALLOW_THREADS
@@ -1265,18 +1259,6 @@
 
 
 /* ===================================================================== */
-/* Members of BZ2File_Type. */
-
-#undef OFF
-#define OFF(x) offsetof(BZ2FileObject, x)
-
-static PyMemberDef BZ2File_members[] = {
-	{"softspace",	T_INT,		OFF(f_softspace), 0,
-	 "flag indicating that a space needs to be printed; used by print"},
-	{NULL}	/* Sentinel */
-};
-
-/* ===================================================================== */
 /* Slot definitions for BZ2File_Type. */
 
 static int
@@ -1501,7 +1483,7 @@
         (getiterfunc)BZ2File_getiter, /*tp_iter*/
         (iternextfunc)BZ2File_iternext, /*tp_iternext*/
         BZ2File_methods,        /*tp_methods*/
-        BZ2File_members,        /*tp_members*/
+        0,		        /*tp_members*/
         BZ2File_getset,         /*tp_getset*/
         0,                      /*tp_base*/
         0,                      /*tp_dict*/

Modified: python/branches/p3yk/Modules/cStringIO.c
==============================================================================
--- python/branches/p3yk/Modules/cStringIO.c	(original)
+++ python/branches/p3yk/Modules/cStringIO.c	Sat Feb 10 00:20:19 2007
@@ -57,7 +57,6 @@
   Py_ssize_t pos, string_size;
 
   Py_ssize_t buf_size;
-  int softspace;
 } Oobject;
 
 /* Declarations for objects of type StringI */
@@ -489,13 +488,6 @@
   {NULL,	 NULL}		/* sentinel */
 };
 
-static PyMemberDef O_memberlist[] = {
-	{"softspace",	T_INT,	offsetof(Oobject, softspace),	0,
-	 "flag indicating that a space needs to be printed; used by print"},
-	 /* getattr(f, "closed") is implemented without this table */
-	{NULL} /* Sentinel */
-};
-
 static void
 O_dealloc(Oobject *self) {
         if (self->buf != NULL)
@@ -536,7 +528,7 @@
   PyObject_SelfIter,		/*tp_iter */
   (iternextfunc)IO_iternext,	/*tp_iternext */
   O_methods,			/*tp_methods */
-  O_memberlist,			/*tp_members */
+  0,				/*tp_members */
   file_getsetlist,		/*tp_getset */
 };
 
@@ -549,7 +541,6 @@
                 return NULL;
         self->pos=0;
         self->string_size = 0;
-        self->softspace = 0;
 
         self->buf = (char *)malloc(size);
 	if (!self->buf) {

Modified: python/branches/p3yk/Objects/fileobject.c
==============================================================================
--- python/branches/p3yk/Objects/fileobject.c	(original)
+++ python/branches/p3yk/Objects/fileobject.c	Sat Feb 10 00:20:19 2007
@@ -118,7 +118,6 @@
 	f->f_mode = PyString_FromString(mode);
 
 	f->f_close = close;
-	f->f_softspace = 0;
 	f->f_binary = strchr(mode,'b') != NULL;
 	f->f_buf = NULL;
 	f->f_univ_newline = (strchr(mode, 'U') != NULL);
@@ -1523,7 +1522,6 @@
 		return err_closed();
 	if (!PyArg_ParseTuple(args, f->f_binary ? "s#" : "t#", &s, &n))
 		return NULL;
-	f->f_softspace = 0;
 	Py_BEGIN_ALLOW_THREADS
 	errno = 0;
 	n2 = fwrite(s, 1, n, f->f_fp);
@@ -1626,7 +1624,6 @@
 		/* Since we are releasing the global lock, the
 		   following code may *not* execute Python code. */
 		Py_BEGIN_ALLOW_THREADS
-		f->f_softspace = 0;
 		errno = 0;
 		for (i = 0; i < j; i++) {
 		    	line = PyList_GET_ITEM(list, i);
@@ -1786,8 +1783,6 @@
 #define OFF(x) offsetof(PyFileObject, x)
 
 static PyMemberDef file_memberlist[] = {
-	{"softspace",	T_INT,		OFF(f_softspace), 0,
-	 "flag indicating that a space needs to be printed; used by print"},
 	{"mode",	T_OBJECT,	OFF(f_mode),	RO,
 	 "file mode ('r', 'U', 'w', 'a', possibly with 'b' or '+' added)"},
 	{"name",	T_OBJECT,	OFF(f_name),	RO,
@@ -2094,8 +2089,7 @@
 	0,					/* tp_call */
 	0,					/* tp_str */
 	PyObject_GenericGetAttr,		/* tp_getattro */
-	/* softspace is writable:  we must supply tp_setattro */
-	PyObject_GenericSetAttr,		/* tp_setattro */
+	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	file_doc,				/* tp_doc */
@@ -2119,42 +2113,6 @@
 	PyObject_Del,                           /* tp_free */
 };
 
-/* Interface for the 'soft space' between print items. */
-
-int
-PyFile_SoftSpace(PyObject *f, int newflag)
-{
-	long oldflag = 0;
-	if (f == NULL) {
-		/* Do nothing */
-	}
-	else if (PyFile_Check(f)) {
-		oldflag = ((PyFileObject *)f)->f_softspace;
-		((PyFileObject *)f)->f_softspace = newflag;
-	}
-	else {
-		PyObject *v;
-		v = PyObject_GetAttrString(f, "softspace");
-		if (v == NULL)
-			PyErr_Clear();
-		else {
-			if (PyInt_CheckExact(v))
-				oldflag = PyInt_AsLong(v);
-			assert(oldflag < INT_MAX);
-			Py_DECREF(v);
-		}
-		v = PyInt_FromLong((long)newflag);
-		if (v == NULL)
-			PyErr_Clear();
-		else {
-			if (PyObject_SetAttrString(f, "softspace", v) != 0)
-				PyErr_Clear();
-			Py_DECREF(v);
-		}
-	}
-	return (int)oldflag;
-}
-
 /* Interfaces to write objects/strings to file-like objects */
 
 int

Modified: python/branches/p3yk/Python/ceval.c
==============================================================================
--- python/branches/p3yk/Python/ceval.c	(original)
+++ python/branches/p3yk/Python/ceval.c	Sat Feb 10 00:20:19 2007
@@ -3349,17 +3349,6 @@
 	return result;
 }
 
-int
-Py_FlushLine(void)
-{
-	PyObject *f = PySys_GetObject("stdout");
-	if (f == NULL)
-		return 0;
-	if (!PyFile_SoftSpace(f, 0))
-		return 0;
-	return PyFile_WriteString("\n", f);
-}
-
 
 /* External interface to call any callable object.
    The arg must be a tuple or NULL. */

Modified: python/branches/p3yk/Python/pythonrun.c
==============================================================================
--- python/branches/p3yk/Python/pythonrun.c	(original)
+++ python/branches/p3yk/Python/pythonrun.c	Sat Feb 10 00:20:19 2007
@@ -795,8 +795,6 @@
 		return -1;
 	}
 	Py_DECREF(v);
-	if (Py_FlushLine())
-		PyErr_Clear();
 	return 0;
 }
 
@@ -883,8 +881,6 @@
 		return -1;
 	}
 	Py_DECREF(v);
-	if (Py_FlushLine())
-		PyErr_Clear();
 	return 0;
 }
 
@@ -902,8 +898,6 @@
 		return -1;
 	}
 	Py_DECREF(v);
-	if (Py_FlushLine())
-		PyErr_Clear();
 	return 0;
 }
 
@@ -1018,8 +1012,6 @@
 	int exitcode = 0;
 
 	PyErr_Fetch(&exception, &value, &tb);
-	if (Py_FlushLine())
-		PyErr_Clear();
 	fflush(stdout);
 	if (value == NULL || value == Py_None)
 		goto done;
@@ -1097,8 +1089,6 @@
 				v2 = Py_None;
 				Py_INCREF(v2);
 			}
-			if (Py_FlushLine())
-				PyErr_Clear();
 			fflush(stdout);
 			PySys_WriteStderr("Error in sys.excepthook:\n");
 			PyErr_Display(exception2, v2, tb2);
@@ -1128,8 +1118,6 @@
 	if (f == NULL)
 		fprintf(stderr, "lost sys.stderr\n");
 	else {
-		if (Py_FlushLine())
-			PyErr_Clear();
 		fflush(stdout);
 		if (tb && tb != Py_None)
 			err = PyTraceBack_Print(tb, f);
@@ -1597,8 +1585,6 @@
 		Py_DECREF(exitfunc);
 	}
 
-	if (Py_FlushLine())
-		PyErr_Clear();
 }
 
 static void
@@ -1855,4 +1841,3 @@
 #ifdef __cplusplus
 }
 #endif
-

Modified: python/branches/p3yk/Python/sysmodule.c
==============================================================================
--- python/branches/p3yk/Python/sysmodule.c	(original)
+++ python/branches/p3yk/Python/sysmodule.c	Sat Feb 10 00:20:19 2007
@@ -104,8 +104,6 @@
 	}
 	if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
 		return NULL;
-	if (Py_FlushLine() != 0)
-		return NULL;
 	outf = PySys_GetObject("stdout");
 	if (outf == NULL) {
 		PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
@@ -113,8 +111,7 @@
 	}
 	if (PyFile_WriteObject(o, outf, 0) != 0)
 		return NULL;
-	PyFile_SoftSpace(outf, 1);
-	if (Py_FlushLine() != 0)
+	if (PyFile_WriteString("\n", outf) != 0)
 		return NULL;
 	if (PyObject_SetAttrString(builtins, "_", o) != 0)
 		return NULL;


More information about the Python-3000-checkins mailing list