]> granicus.if.org Git - python/commitdiff
#2348: add py3k warning for file.softspace.
authorGeorg Brandl <georg@python.org>
Fri, 21 Mar 2008 20:38:24 +0000 (20:38 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 21 Mar 2008 20:38:24 +0000 (20:38 +0000)
Lib/test/test_py3kwarn.py
Misc/NEWS
Objects/fileobject.c

index f030af09f7219d5384a00516ac74df848dea8384..07bcdf97d26e3cec18baf452a30cbcc61ce05e1e 100644 (file)
@@ -108,6 +108,16 @@ class TestPy3KWarnings(unittest.TestCase):
         with catch_warning() as w:
             self.assertWarning(dir(c), w, expected)
 
+    def test_softspace(self):
+        expected = 'file.softspace not supported in 3.x'
+        with file(__file__) as f:
+            with catch_warning() as w:
+                self.assertWarning(f.softspace, w, expected)
+            def set():
+                f.softspace = 0
+            with catch_warning() as w:
+                self.assertWarning(set(), w, expected)
+
 
 def test_main():
     run_unittest(TestPy3KWarnings)
index 83903ef78082110e3f9ab97508b8e15197ae7b4e..615effca66548227c2e6aa47aceea239da07c7b2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2?
 Core and builtins
 -----------------
  
+- Issue #2348: add Py3k warning for file.softspace.
+
 - Issue #2346/#2347: add Py3k warnings for __methods__ and __members__.
 
 - Issue #2358: Add a Py3k warning on sys.exc_clear() usage.
index 9195a24ea113940acee78e6d18efdb4038555c29..0a6ccff52cdd82b0a658d7fd82f928255f1751cb 100644 (file)
@@ -1783,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,
@@ -1829,10 +1827,44 @@ get_newlines(PyFileObject *f, void *closure)
        }
 }
 
+static PyObject *
+get_softspace(PyFileObject *f, void *closure)
+{
+       if (Py_Py3kWarningFlag &&
+           PyErr_Warn(PyExc_DeprecationWarning,
+                      "file.softspace not supported in 3.x") < 0)
+               return NULL;
+       return PyInt_FromLong(f->f_softspace);
+}
+
+static int
+set_softspace(PyFileObject *f, PyObject *value)
+{
+       int new;
+       if (Py_Py3kWarningFlag &&
+           PyErr_Warn(PyExc_DeprecationWarning,
+                      "file.softspace not supported in 3.x") < 0)
+               return -1;
+
+       if (value == NULL) {
+               PyErr_SetString(PyExc_TypeError,
+                               "can't delete softspace attribute");
+               return -1;
+       }
+
+       new = PyInt_AsLong(value);
+       if (new == -1 && PyErr_Occurred())
+               return -1;
+       f->f_softspace = new;
+       return 0;
+}
+
 static PyGetSetDef file_getsetlist[] = {
        {"closed", (getter)get_closed, NULL, "True if the file is closed"},
        {"newlines", (getter)get_newlines, NULL,
         "end-of-line convention used in this file"},
+       {"softspace", (getter)get_softspace, (setter)set_softspace,
+        "flag indicating that a space needs to be printed; used by print"},
        {0},
 };