mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
Issue #7133: SSL objects now support the new buffer API.
This fixes the test_ssl failure.
This commit is contained in:
parent
a24db67d47
commit
5ba84910ae
3 changed files with 33 additions and 25 deletions
|
|
@ -662,11 +662,12 @@ else:
|
|||
except Exception, x:
|
||||
raise test_support.TestFailed("Unexpected exception: " + str(x))
|
||||
else:
|
||||
for arg in [indata, bytearray(indata), memoryview(indata)]:
|
||||
if connectionchatty:
|
||||
if test_support.verbose:
|
||||
sys.stdout.write(
|
||||
" client: sending %s...\n" % (repr(indata)))
|
||||
s.write(indata)
|
||||
" client: sending %s...\n" % (repr(arg)))
|
||||
s.write(arg)
|
||||
outdata = s.read()
|
||||
if connectionchatty:
|
||||
if test_support.verbose:
|
||||
|
|
|
|||
|
|
@ -414,6 +414,8 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #7133: SSL objects now support the new buffer API.
|
||||
|
||||
- Issue #7149: urllib fails on OSX in the proxy detection code
|
||||
|
||||
- Issue #7069: Make inspect.isabstract() return a boolean.
|
||||
|
|
|
|||
|
|
@ -1144,14 +1144,13 @@ normal_return:
|
|||
|
||||
static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
|
||||
{
|
||||
char *data;
|
||||
Py_buffer buf;
|
||||
int len;
|
||||
int count;
|
||||
int sockstate;
|
||||
int err;
|
||||
int nonblocking;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#:write", &data, &count))
|
||||
if (!PyArg_ParseTuple(args, "s*:write", &buf))
|
||||
return NULL;
|
||||
|
||||
/* just in case the blocking state of the socket has been changed */
|
||||
|
|
@ -1163,24 +1162,24 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
|
|||
if (sockstate == SOCKET_HAS_TIMED_OUT) {
|
||||
PyErr_SetString(PySSLErrorObject,
|
||||
"The write operation timed out");
|
||||
return NULL;
|
||||
goto error;
|
||||
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
||||
PyErr_SetString(PySSLErrorObject,
|
||||
"Underlying socket has been closed.");
|
||||
return NULL;
|
||||
goto error;
|
||||
} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
|
||||
PyErr_SetString(PySSLErrorObject,
|
||||
"Underlying socket too large for select().");
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
do {
|
||||
err = 0;
|
||||
PySSL_BEGIN_ALLOW_THREADS
|
||||
len = SSL_write(self->ssl, data, count);
|
||||
len = SSL_write(self->ssl, buf.buf, buf.len);
|
||||
err = SSL_get_error(self->ssl, len);
|
||||
PySSL_END_ALLOW_THREADS
|
||||
if (PyErr_CheckSignals()) {
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
sockstate =
|
||||
|
|
@ -1194,19 +1193,25 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
|
|||
if (sockstate == SOCKET_HAS_TIMED_OUT) {
|
||||
PyErr_SetString(PySSLErrorObject,
|
||||
"The write operation timed out");
|
||||
return NULL;
|
||||
goto error;
|
||||
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
||||
PyErr_SetString(PySSLErrorObject,
|
||||
"Underlying socket has been closed.");
|
||||
return NULL;
|
||||
goto error;
|
||||
} else if (sockstate == SOCKET_IS_NONBLOCKING) {
|
||||
break;
|
||||
}
|
||||
} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
|
||||
|
||||
PyBuffer_Release(&buf);
|
||||
if (len > 0)
|
||||
return PyInt_FromLong(len);
|
||||
else
|
||||
return PySSL_SetError(self, len, __FILE__, __LINE__);
|
||||
|
||||
error:
|
||||
PyBuffer_Release(&buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(PySSL_SSLwrite_doc,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue