]> granicus.if.org Git - python/commitdiff
Kill off softspace completely (except in formatter.py which seems to have
authorGuido van Rossum <guido@python.org>
Fri, 9 Feb 2007 23:20:19 +0000 (23:20 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 9 Feb 2007 23:20:19 +0000 (23:20 +0000)
a different feature with the same name).
The change to test_doctest.txt reduces the doctest failures to 3.

19 files changed:
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 [deleted file]
Modules/bz2module.c
Modules/cStringIO.c
Objects/fileobject.c
Python/ceval.c
Python/pythonrun.c
Python/sysmodule.c

index f4411977fb1da5b341f27de09cd2f41e53d8d560..9c77a85a96987ca95589129186fda25f4aa3aade 100644 (file)
@@ -40,8 +40,6 @@ PyAPI_FUNC(int) PyEval_GetRestricted(void);
    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);
 
index ebbb521d17be986a7e049c5195f2e26270209f82..ee7c4ee4078f28478325a36e02c125219e2b1b59 100644 (file)
@@ -13,7 +13,6 @@ typedef struct {
        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(FILE *) PyFile_AsFile(PyObject *);
 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 *);
 
index a6b0ea4061d93b0ffb6b1d892b747d5e565ba497..189d368f01ef305700df63ab8f859d936dd9b8d4 100644 (file)
@@ -60,7 +60,6 @@ class StringIO:
         self.buflist = []
         self.pos = 0
         self.closed = False
-        self.softspace = 0
 
     def __iter__(self):
         return self
index d439f3255e986248155c4b52ed89d28063af8b28..975a2d9c0a48a5bafe7cf9df7522754472b75c5f 100644 (file)
@@ -39,7 +39,6 @@ class DBRecIO:
         self.len = None
         self.pos = 0
         self.closed = 0
-        self.softspace = 0
 
     def close(self):
         if not self.closed:
index 8532a2eeb9ddc1a6ab7ff72a4981812981bbd308..71827777f5daac37288bc98880e9179eaf88a6ee 100644 (file)
@@ -12,19 +12,6 @@ from codeop import CommandCompiler, compile_command
 __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 @@ class InteractiveInterpreter:
             raise
         except:
             self.showtraceback()
-        else:
-            if softspace(sys.stdout, 0):
-                print()
 
     def showsyntaxerror(self, filename=None):
         """Display the syntax error that just occurred.
index 210e8459e5ce1f5cb36bd38a76f169c3823bf2e2..02e200db3d72be0ab1d5f321a230d5b48224e63c 100644 (file)
@@ -240,16 +240,10 @@ class _SpoofOut(StringIO):
         # 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):
index e8284d81fc71bec5e62ef326754bb24d004e8a81..4c16db94020c9a2c63d2ac524094f6fdecbb53f6 100644 (file)
@@ -1223,7 +1223,6 @@ class PyShell(OutputWindow):
             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 @@ class PseudoFile(object):
     def __init__(self, shell, tags, encoding=None):
         self.shell = shell
         self.tags = tags
-        self.softspace = 0
         self.encoding = encoding
 
     def write(self, s):
index fa201a8d21c7c377f608056e91aa3b8cbac64ce1..8a0b926575a8230a10cb8f61091a335392106524 100644 (file)
@@ -190,12 +190,7 @@ def cleanup_traceback(tb, exclude):
         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
index eff47d2bf74a669f21e25f2265a32cf7a5bf1661..2222600721c3a754487ad24488fa5d4da83634cd 100644 (file)
@@ -202,7 +202,7 @@ class _fileobject(object):
     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 @@ class _fileobject(object):
         if bufsize < 0:
             bufsize = self.default_bufsize
         self.bufsize = bufsize
-        self.softspace = False
         if bufsize == 0:
             self._rbufsize = 1
         elif bufsize == 1:
index f8e851e1a5f5a57fce008eaf07b85daedee00324..23446d1d224532578e7dbfbd284e6d0e496649ce 100644 (file)
@@ -9,9 +9,9 @@ already:
 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
index 91f6e76c312431680b5a3661f910ee49962ef4f6..7eb052b3a0eb52459d7d79257a126d2eadcbce0e 100644 (file)
@@ -30,14 +30,10 @@ class AutoFileTests(unittest.TestCase):
     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')
index 071e52196afd420dd54ae198cba50fc3312e466a..296e259f912fc8321362e3ee86c8cb29f1fa260a 100644 (file)
@@ -61,7 +61,6 @@ class TestPredicates(IsTestBase):
         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')
diff --git a/Lib/test/test_softspace.py b/Lib/test/test_softspace.py
deleted file mode 100644 (file)
index c0b4e8f..0000000
+++ /dev/null
@@ -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')
index 3c6daa9eff5084d6fce230d21e28ca3a55f8afaa..9b39442f9df870f4046ad5f11c06fa4a88370cd0 100644 (file)
@@ -102,8 +102,6 @@ typedef struct {
        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 @@ BZ2File_write(BZ2FileObject *self, PyObject *args)
                        goto cleanup;
        }
 
-       self->f_softspace = 0;
-
        Py_BEGIN_ALLOW_THREADS
        BZ2_bzWrite (&bzerror, self->fp, buf, len);
        self->pos += len;
@@ -934,8 +930,6 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
                        }
                }
 
-               self->f_softspace = 0;
-
                /* Since we are releasing the global lock, the
                   following code may *not* execute Python code. */
                Py_BEGIN_ALLOW_THREADS
@@ -1264,18 +1258,6 @@ static PyGetSetDef BZ2File_getset[] = {
 };
 
 
-/* ===================================================================== */
-/* 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. */
 
@@ -1501,7 +1483,7 @@ static PyTypeObject BZ2File_Type = {
         (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*/
index 3f762b09fb02692a388bdd805e3e99fc32370c34..2ed148576c975e92d438fcbc8523d962500d7637 100644 (file)
@@ -57,7 +57,6 @@ typedef struct { /* Subtype of IOobject */
   Py_ssize_t pos, string_size;
 
   Py_ssize_t buf_size;
-  int softspace;
 } Oobject;
 
 /* Declarations for objects of type StringI */
@@ -489,13 +488,6 @@ static struct PyMethodDef O_methods[] = {
   {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 @@ static PyTypeObject Otype = {
   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 @@ newOobject(int  size) {
                 return NULL;
         self->pos=0;
         self->string_size = 0;
-        self->softspace = 0;
 
         self->buf = (char *)malloc(size);
        if (!self->buf) {
index 1e3e57c606f411b8a118dad2f42a6c69f475c6e3..13f64fbe3cf02500104c833d675b9ec18c453f33 100644 (file)
@@ -118,7 +118,6 @@ fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode,
        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 @@ file_write(PyFileObject *f, PyObject *args)
                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 @@ file_writelines(PyFileObject *f, PyObject *seq)
                /* 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 @@ static PyMethodDef file_methods[] = {
 #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 @@ PyTypeObject PyFile_Type = {
        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 @@ PyTypeObject PyFile_Type = {
        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
index 7511bb6a5d8644dea76e7fa998ff11d6804ef6bb..0194687e22e4f94a4337d45348c60df22830af4e 100644 (file)
@@ -3349,17 +3349,6 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
        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. */
index 3aa1295f9ef116321a7f5ddd138f7af6a50c6db8..ec1bc4292d0fdfddefb0f546228b5e75673dc994 100644 (file)
@@ -795,8 +795,6 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
                return -1;
        }
        Py_DECREF(v);
-       if (Py_FlushLine())
-               PyErr_Clear();
        return 0;
 }
 
@@ -883,8 +881,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
                return -1;
        }
        Py_DECREF(v);
-       if (Py_FlushLine())
-               PyErr_Clear();
        return 0;
 }
 
@@ -902,8 +898,6 @@ PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)
                return -1;
        }
        Py_DECREF(v);
-       if (Py_FlushLine())
-               PyErr_Clear();
        return 0;
 }
 
@@ -1018,8 +1012,6 @@ handle_system_exit(void)
        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 @@ PyErr_PrintEx(int set_sys_last_vars)
                                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 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
        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 @@ call_sys_exitfunc(void)
                Py_DECREF(exitfunc);
        }
 
-       if (Py_FlushLine())
-               PyErr_Clear();
 }
 
 static void
@@ -1855,4 +1841,3 @@ PyRun_InteractiveLoop(FILE *f, const char *p)
 #ifdef __cplusplus
 }
 #endif
-
index 3f2d5b7f6e6ba9905af9cf50890edf1f92467fbb..c7d85933963a36224d3c5910b175e86cf31c9a91 100644 (file)
@@ -104,8 +104,6 @@ sys_displayhook(PyObject *self, PyObject *o)
        }
        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 @@ sys_displayhook(PyObject *self, PyObject *o)
        }
        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;