Merged revisions 75529 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75529 | antoine.pitrou | 2009-10-19 19:59:07 +0200 (lun., 19 oct. 2009) | 5 lines

  Issue #7133: SSL objects now support the new buffer API.

  This fixes the test_ssl failure.
........
This commit is contained in:
Antoine Pitrou 2009-11-25 18:55:32 +00:00
parent b742a96c52
commit 7d7aede558
3 changed files with 35 additions and 26 deletions

View File

@ -651,21 +651,23 @@ else:
except Exception as x:
raise support.TestFailed("Unexpected exception: " + str(x))
else:
if connectionchatty:
if support.verbose:
sys.stdout.write(
" client: sending %s...\n" % (repr(indata)))
s.write(indata.encode('ASCII', 'strict'))
outdata = s.read()
if connectionchatty:
if support.verbose:
sys.stdout.write(" client: read %s\n" % repr(outdata))
outdata = str(outdata, 'ASCII', 'strict')
if outdata != indata.lower():
raise support.TestFailed(
"bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
% (repr(outdata[:min(len(outdata),20)]), len(outdata),
repr(indata[:min(len(indata),20)].lower()), len(indata)))
bindata = indata.encode('ASCII', 'strict')
for arg in [bindata, bytearray(bindata), memoryview(bindata)]:
if connectionchatty:
if support.verbose:
sys.stdout.write(
" client: sending %s...\n" % (repr(indata)))
s.write(arg)
outdata = s.read()
if connectionchatty:
if support.verbose:
sys.stdout.write(" client: read %s\n" % repr(outdata))
outdata = str(outdata, 'ASCII', 'strict')
if outdata != indata.lower():
raise support.TestFailed(
"bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
% (repr(outdata[:min(len(outdata),20)]), len(outdata),
repr(indata[:min(len(indata),20)].lower()), len(indata)))
s.write("over\n".encode("ASCII", "strict"))
if connectionchatty:
if support.verbose:

View File

@ -140,6 +140,8 @@ C-API
Library
-------
- Issue #7133: SSL objects now support the new buffer API.
- Issue #1488943: difflib.Differ() doesn't always add hints for tab characters
- Issue #6123: tarfile now opens empty archives correctly and consistently

View File

@ -1146,9 +1146,8 @@ 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;
@ -1161,7 +1160,7 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
return NULL;
}
if (!PyArg_ParseTuple(args, "y#:write", &data, &count))
if (!PyArg_ParseTuple(args, "y*:write", &buf))
return NULL;
/* just in case the blocking state of the socket has been changed */
@ -1173,24 +1172,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;
if (PyErr_CheckSignals()) {
goto error;
}
if (err == SSL_ERROR_WANT_READ) {
sockstate =
@ -1204,19 +1203,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 PyLong_FromLong(len);
else
return PySSL_SetError(self, len, __FILE__, __LINE__);
error:
PyBuffer_Release(&buf);
return NULL;
}
PyDoc_STRVAR(PySSL_SSLwrite_doc,