diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-09 23:44:22 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-09 23:44:22 (GMT) |
commit | cafd495dfed238afdf684ec1cede705bd93bfb5b (patch) | |
tree | 6ed921517d19e5dbca8bac1642521086aaf285b4 | |
parent | 6f8ee59653261731d73f0e16bd3f667db57133bd (diff) | |
download | cpython-cafd495dfed238afdf684ec1cede705bd93bfb5b.zip cpython-cafd495dfed238afdf684ec1cede705bd93bfb5b.tar.gz cpython-cafd495dfed238afdf684ec1cede705bd93bfb5b.tar.bz2 |
In O_writelines: Replace use of string.joinfields with "".join.
-rw-r--r-- | Lib/test/output/test_StringIO | 2 | ||||
-rw-r--r-- | Lib/test/test_StringIO.py | 8 | ||||
-rw-r--r-- | Modules/cStringIO.c | 19 |
3 files changed, 20 insertions, 9 deletions
diff --git a/Lib/test/output/test_StringIO b/Lib/test/output/test_StringIO index e2b2893..992d534 100644 --- a/Lib/test/output/test_StringIO +++ b/Lib/test/output/test_StringIO @@ -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: diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index ea237cd..8d3c851 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -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) diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index 1cb40ea..ddf3699 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -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); |