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