]> granicus.if.org Git - python/commitdiff
In O_writelines: Replace use of string.joinfields with "".join.
authorJeremy Hylton <jeremy@alum.mit.edu>
Fri, 9 Feb 2001 23:44:22 +0000 (23:44 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Fri, 9 Feb 2001 23:44:22 +0000 (23:44 +0000)
Lib/test/output/test_StringIO
Lib/test/test_StringIO.py
Modules/cStringIO.c

index e2b28931c504ebc7b081e5932c5e227df9a7a700..992d5340d977ecefb5f2959182abf66cec705a34 100644 (file)
@@ -4,6 +4,7 @@ klmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
 
 2
 'abcuvwxyz!'
+'abc'
 'abcdefghij'
 'abcde'
 Caught expected ValueError writing to closed StringIO:
@@ -13,6 +14,7 @@ klmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
 
 2
 'abcuvwxyz!'
+'abc'
 'abcdefghij'
 'abcde'
 Caught expected ValueError writing to closed StringIO:
index ea237cd138a90babb004b9b9c60891745e01ebd3..8d3c85142aa396af01156491b0a5fc77ba9ce9e5 100644 (file)
@@ -14,6 +14,13 @@ def do_test(module):
     f.write('!')
     print `f.getvalue()`
     f.close()
+
+    f = module.StringIO()
+    f.writelines(["a", "b", "c"])
+    f.seek(0)
+    print `f.getvalue()`
+    f.close()
+
     f = module.StringIO()
     f.write(s)
     f.seek(10)
@@ -31,7 +38,6 @@ def do_test(module):
     else:
         print "Failed to catch ValueError writing to closed StringIO."
 
-# Don't bother testing cStringIO without
 import StringIO, cStringIO
 do_test(StringIO)
 do_test(cStringIO)
index 1cb40ea8bdcdc381a9feb650d717084460287e6b..ddf369901a57a602f0e0280e7f8943299290f8ec 100644 (file)
@@ -460,20 +460,23 @@ static char O_writelines__doc__[] =
 static PyObject *
 O_writelines(Oobject *self, PyObject *args) {
         PyObject *tmp = 0;
-        static PyObject *string_joinfields = 0;
+       static PyObject *joiner = NULL;
 
         UNLESS (PyArg_ParseTuple(args, "O:writelines", &args)) return NULL;
 
-        if (!string_joinfields) {
-                UNLESS (tmp = PyImport_ImportModule("string")) return NULL;
-                string_joinfields=PyObject_GetAttrString(tmp, "joinfields");
-                Py_DECREF(tmp);
-                UNLESS (string_joinfields) return NULL;
-        }
+       if (!joiner) {
+               PyObject *empty_string = PyString_FromString("");
+               if (empty_string == NULL)
+                       return NULL;
+               joiner = PyObject_GetAttrString(empty_string, "join");
+               Py_DECREF(empty_string);
+               if (joiner == NULL)
+                       return NULL;
+       }
 
         if (PyObject_Size(args) < 0) return NULL;
 
-        tmp = PyObject_CallFunction(string_joinfields, "Os", args, "");
+        tmp = PyObject_CallFunction(joiner, "O", args);
         UNLESS (tmp) return NULL;
 
         args = Py_BuildValue("(O)", tmp);