raise TypeError when bad argument passed to cStringIO.StringIO
This commit is contained in:
parent
394b54d01a
commit
127b2ef2d5
|
@ -579,8 +579,13 @@ newIobject(PyObject *s) {
|
||||||
char *buf;
|
char *buf;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
UNLESS(buf=PyString_AsString(s)) return NULL;
|
if (!PyString_Check(s)) {
|
||||||
UNLESS(-1 != (size=PyString_Size(s))) return NULL;
|
PyErr_Format(PyExc_TypeError, "expected string, %.200s found",
|
||||||
|
s->ob_type->tp_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buf = PyString_AS_STRING(s);
|
||||||
|
size = PyString_GET_SIZE(s);
|
||||||
UNLESS(self = PyObject_NEW(Iobject, &Itype)) return NULL;
|
UNLESS(self = PyObject_NEW(Iobject, &Itype)) return NULL;
|
||||||
Py_INCREF(s);
|
Py_INCREF(s);
|
||||||
self->buf=buf;
|
self->buf=buf;
|
||||||
|
@ -603,7 +608,8 @@ static PyObject *
|
||||||
IO_StringIO(PyObject *self, PyObject *args) {
|
IO_StringIO(PyObject *self, PyObject *args) {
|
||||||
PyObject *s=0;
|
PyObject *s=0;
|
||||||
|
|
||||||
UNLESS(PyArg_ParseTuple(args, "|O:StringIO", &s)) return NULL;
|
if (!PyArg_ParseTuple(args, "|O:StringIO", &s))
|
||||||
|
return NULL;
|
||||||
if(s) return newIobject(s);
|
if(s) return newIobject(s);
|
||||||
return newOobject(128);
|
return newOobject(128);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue