Commit f06628b0 authored by Guido van Rossum's avatar Guido van Rossum

Make read() and certificate() return bytes instead of bytearray instances.

parent 254348e2
......@@ -977,7 +977,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
return NULL;
}
/* this is actually an immutable bytes sequence */
retval = PyBytes_FromStringAndSize
retval = PyString_FromStringAndSize
((const char *) bytes_buf, len);
OPENSSL_free(bytes_buf);
return retval;
......@@ -1281,13 +1281,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
Py_DECREF(buf);
return NULL;
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
/* should contain a zero-length string */
if (!buf_passed) {
PyBytes_Resize(buf, 0);
return buf;
} else {
return PyInt_FromLong(0);
}
count = 0;
goto done;
}
}
do {
......@@ -1312,12 +1307,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
(SSL_get_shutdown(self->ssl) ==
SSL_RECEIVED_SHUTDOWN))
{
if (!buf_passed) {
PyBytes_Resize(buf, 0);
return buf;
} else {
return PyInt_FromLong(0);
}
count = 0;
goto done;
} else {
sockstate = SOCKET_OPERATION_OK;
}
......@@ -1338,11 +1329,12 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
}
return PySSL_SetError(self, count, __FILE__, __LINE__);
}
done:
if (!buf_passed) {
if (count != len) {
PyBytes_Resize(buf, count);
}
return buf;
PyObject *res = PyString_FromStringAndSize(
PyBytes_AS_STRING(buf), count);
Py_DECREF(buf);
return res;
} else {
return PyInt_FromLong(count);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment