Make read() and certificate() return bytes instead of bytearray instances.
This commit is contained in:
parent
254348e201
commit
f06628b072
@ -977,7 +977,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* this is actually an immutable bytes sequence */
|
/* this is actually an immutable bytes sequence */
|
||||||
retval = PyBytes_FromStringAndSize
|
retval = PyString_FromStringAndSize
|
||||||
((const char *) bytes_buf, len);
|
((const char *) bytes_buf, len);
|
||||||
OPENSSL_free(bytes_buf);
|
OPENSSL_free(bytes_buf);
|
||||||
return retval;
|
return retval;
|
||||||
@ -1281,13 +1281,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
|
|||||||
Py_DECREF(buf);
|
Py_DECREF(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
||||||
/* should contain a zero-length string */
|
count = 0;
|
||||||
if (!buf_passed) {
|
goto done;
|
||||||
PyBytes_Resize(buf, 0);
|
|
||||||
return buf;
|
|
||||||
} else {
|
|
||||||
return PyInt_FromLong(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
@ -1312,12 +1307,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
|
|||||||
(SSL_get_shutdown(self->ssl) ==
|
(SSL_get_shutdown(self->ssl) ==
|
||||||
SSL_RECEIVED_SHUTDOWN))
|
SSL_RECEIVED_SHUTDOWN))
|
||||||
{
|
{
|
||||||
if (!buf_passed) {
|
count = 0;
|
||||||
PyBytes_Resize(buf, 0);
|
goto done;
|
||||||
return buf;
|
|
||||||
} else {
|
|
||||||
return PyInt_FromLong(0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
sockstate = SOCKET_OPERATION_OK;
|
sockstate = SOCKET_OPERATION_OK;
|
||||||
}
|
}
|
||||||
@ -1338,11 +1329,12 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
return PySSL_SetError(self, count, __FILE__, __LINE__);
|
return PySSL_SetError(self, count, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
if (!buf_passed) {
|
if (!buf_passed) {
|
||||||
if (count != len) {
|
PyObject *res = PyString_FromStringAndSize(
|
||||||
PyBytes_Resize(buf, count);
|
PyBytes_AS_STRING(buf), count);
|
||||||
}
|
Py_DECREF(buf);
|
||||||
return buf;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
return PyInt_FromLong(count);
|
return PyInt_FromLong(count);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user