summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-11-25 18:55:32 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-11-25 18:55:32 (GMT)
commit7d7aede558bc93196a40bd00fd857f57d00dd5bc (patch)
treeb5f8b100bac2a4beee4f45403ba74ddf9da3b264
parentb742a96c523339d640ca9dc3d077ef9b6ec13d8e (diff)
downloadcpython-7d7aede558bc93196a40bd00fd857f57d00dd5bc.zip
cpython-7d7aede558bc93196a40bd00fd857f57d00dd5bc.tar.gz
cpython-7d7aede558bc93196a40bd00fd857f57d00dd5bc.tar.bz2
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. ........
-rw-r--r--Lib/test/test_ssl.py32
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/_ssl.c27
3 files changed, 35 insertions, 26 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 0be5652..383c78a 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -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:
diff --git a/Misc/NEWS b/Misc/NEWS
index 6256c69..70e0e1c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 906138d..dfe2fb0 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -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,