Change read() on SSL socket to return bytes.

This commit is contained in:
Jeremy Hylton 2007-08-04 02:58:42 +00:00
parent 97043c3c02
commit 6252083f5f
1 changed files with 7 additions and 4 deletions

View File

@ -496,7 +496,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|i:read", &len)) if (!PyArg_ParseTuple(args, "|i:read", &len))
return NULL; return NULL;
if (!(buf = PyString_FromStringAndSize((char *) 0, len))) if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
return NULL; return NULL;
/* first check if there are bytes ready to be read */ /* first check if there are bytes ready to be read */
@ -518,7 +518,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
do { do {
err = 0; err = 0;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
count = SSL_read(self->ssl, PyString_AsString(buf), len); count = SSL_read(self->ssl, PyBytes_AS_STRING(buf), len);
err = SSL_get_error(self->ssl, count); err = SSL_get_error(self->ssl, count);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if(PyErr_CheckSignals()) { if(PyErr_CheckSignals()) {
@ -545,12 +545,15 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
return PySSL_SetError(self, count); return PySSL_SetError(self, count);
} }
if (count != len) if (count != len)
_PyString_Resize(&buf, count); if (PyBytes_Resize(buf, count) < 0) {
Py_DECREF(buf);
return NULL;
}
return buf; return buf;
} }
PyDoc_STRVAR(PySSL_SSLread_doc, PyDoc_STRVAR(PySSL_SSLread_doc,
"read([len]) -> string\n\ "read([len]) -> bytes\n\
\n\ \n\
Read up to len bytes from the SSL socket."); Read up to len bytes from the SSL socket.");