summaryrefslogtreecommitdiffstats
path: root/Modules/_ssl.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2007-08-04 02:58:42 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2007-08-04 02:58:42 (GMT)
commit6252083f5fb107a8de87398d36da5efb5e20144c (patch)
tree5aa6d2a42ab5152ccc22a977b5829abe94a15883 /Modules/_ssl.c
parent97043c3c02d0a531685ce2256eeaf5c4c5d8dc44 (diff)
downloadcpython-6252083f5fb107a8de87398d36da5efb5e20144c.zip
cpython-6252083f5fb107a8de87398d36da5efb5e20144c.tar.gz
cpython-6252083f5fb107a8de87398d36da5efb5e20144c.tar.bz2
Change read() on SSL socket to return bytes.
Diffstat (limited to 'Modules/_ssl.c')
-rw-r--r--Modules/_ssl.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index d0f7115..06aa0be 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -496,7 +496,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|i:read", &len))
return NULL;
- if (!(buf = PyString_FromStringAndSize((char *) 0, len)))
+ if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
return NULL;
/* first check if there are bytes ready to be read */
@@ -518,7 +518,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
do {
err = 0;
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);
Py_END_ALLOW_THREADS
if(PyErr_CheckSignals()) {
@@ -545,12 +545,15 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
return PySSL_SetError(self, count);
}
if (count != len)
- _PyString_Resize(&buf, count);
+ if (PyBytes_Resize(buf, count) < 0) {
+ Py_DECREF(buf);
+ return NULL;
+ }
return buf;
}
PyDoc_STRVAR(PySSL_SSLread_doc,
-"read([len]) -> string\n\
+"read([len]) -> bytes\n\
\n\
Read up to len bytes from the SSL socket.");