mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
In O_writelines: Replace use of string.joinfields with "".join.
This commit is contained in:
parent
6f8ee59653
commit
cafd495dfe
3 changed files with 20 additions and 9 deletions
|
@ -4,6 +4,7 @@ klmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
|
|
||||||
2
|
2
|
||||||
'abcuvwxyz!'
|
'abcuvwxyz!'
|
||||||
|
'abc'
|
||||||
'abcdefghij'
|
'abcdefghij'
|
||||||
'abcde'
|
'abcde'
|
||||||
Caught expected ValueError writing to closed StringIO:
|
Caught expected ValueError writing to closed StringIO:
|
||||||
|
@ -13,6 +14,7 @@ klmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
|
|
||||||
2
|
2
|
||||||
'abcuvwxyz!'
|
'abcuvwxyz!'
|
||||||
|
'abc'
|
||||||
'abcdefghij'
|
'abcdefghij'
|
||||||
'abcde'
|
'abcde'
|
||||||
Caught expected ValueError writing to closed StringIO:
|
Caught expected ValueError writing to closed StringIO:
|
||||||
|
|
|
@ -14,6 +14,13 @@ def do_test(module):
|
||||||
f.write('!')
|
f.write('!')
|
||||||
print `f.getvalue()`
|
print `f.getvalue()`
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
f = module.StringIO()
|
||||||
|
f.writelines(["a", "b", "c"])
|
||||||
|
f.seek(0)
|
||||||
|
print `f.getvalue()`
|
||||||
|
f.close()
|
||||||
|
|
||||||
f = module.StringIO()
|
f = module.StringIO()
|
||||||
f.write(s)
|
f.write(s)
|
||||||
f.seek(10)
|
f.seek(10)
|
||||||
|
@ -31,7 +38,6 @@ def do_test(module):
|
||||||
else:
|
else:
|
||||||
print "Failed to catch ValueError writing to closed StringIO."
|
print "Failed to catch ValueError writing to closed StringIO."
|
||||||
|
|
||||||
# Don't bother testing cStringIO without
|
|
||||||
import StringIO, cStringIO
|
import StringIO, cStringIO
|
||||||
do_test(StringIO)
|
do_test(StringIO)
|
||||||
do_test(cStringIO)
|
do_test(cStringIO)
|
||||||
|
|
|
@ -460,20 +460,23 @@ static char O_writelines__doc__[] =
|
||||||
static PyObject *
|
static PyObject *
|
||||||
O_writelines(Oobject *self, PyObject *args) {
|
O_writelines(Oobject *self, PyObject *args) {
|
||||||
PyObject *tmp = 0;
|
PyObject *tmp = 0;
|
||||||
static PyObject *string_joinfields = 0;
|
static PyObject *joiner = NULL;
|
||||||
|
|
||||||
UNLESS (PyArg_ParseTuple(args, "O:writelines", &args)) return NULL;
|
UNLESS (PyArg_ParseTuple(args, "O:writelines", &args)) return NULL;
|
||||||
|
|
||||||
if (!string_joinfields) {
|
if (!joiner) {
|
||||||
UNLESS (tmp = PyImport_ImportModule("string")) return NULL;
|
PyObject *empty_string = PyString_FromString("");
|
||||||
string_joinfields=PyObject_GetAttrString(tmp, "joinfields");
|
if (empty_string == NULL)
|
||||||
Py_DECREF(tmp);
|
return NULL;
|
||||||
UNLESS (string_joinfields) return NULL;
|
joiner = PyObject_GetAttrString(empty_string, "join");
|
||||||
|
Py_DECREF(empty_string);
|
||||||
|
if (joiner == NULL)
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyObject_Size(args) < 0) 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;
|
UNLESS (tmp) return NULL;
|
||||||
|
|
||||||
args = Py_BuildValue("(O)", tmp);
|
args = Py_BuildValue("(O)", tmp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue