Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d7aede

Browse files
committed
Merged revisions 75529 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent b742a96 commit 7d7aede

3 files changed

Lines changed: 35 additions & 26 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -651,21 +651,23 @@ def serverParamsTest (certfile, protocol, certreqs, cacertsfile,
651651
except Exception as x:
652652
raise support.TestFailed("Unexpected exception: " + str(x))
653653
else:
654-
if connectionchatty:
655-
if support.verbose:
656-
sys.stdout.write(
657-
" client: sending %s...\n" % (repr(indata)))
658-
s.write(indata.encode('ASCII', 'strict'))
659-
outdata = s.read()
660-
if connectionchatty:
661-
if support.verbose:
662-
sys.stdout.write(" client: read %s\n" % repr(outdata))
663-
outdata = str(outdata, 'ASCII', 'strict')
664-
if outdata != indata.lower():
665-
raise support.TestFailed(
666-
"bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
667-
% (repr(outdata[:min(len(outdata),20)]), len(outdata),
668-
repr(indata[:min(len(indata),20)].lower()), len(indata)))
654+
bindata = indata.encode('ASCII', 'strict')
655+
for arg in [bindata, bytearray(bindata), memoryview(bindata)]:
656+
if connectionchatty:
657+
if support.verbose:
658+
sys.stdout.write(
659+
" client: sending %s...\n" % (repr(indata)))
660+
s.write(arg)
661+
outdata = s.read()
662+
if connectionchatty:
663+
if support.verbose:
664+
sys.stdout.write(" client: read %s\n" % repr(outdata))
665+
outdata = str(outdata, 'ASCII', 'strict')
666+
if outdata != indata.lower():
667+
raise support.TestFailed(
668+
"bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
669+
% (repr(outdata[:min(len(outdata),20)]), len(outdata),
670+
repr(indata[:min(len(indata),20)].lower()), len(indata)))
669671
s.write("over\n".encode("ASCII", "strict"))
670672
if connectionchatty:
671673
if support.verbose:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ C-API
140140
Library
141141
-------
142142

143+
- Issue #7133: SSL objects now support the new buffer API.
144+
143145
- Issue #1488943: difflib.Differ() doesn't always add hints for tab characters
144146

145147
- Issue #6123: tarfile now opens empty archives correctly and consistently

Modules/_ssl.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,8 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
11461146

11471147
static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
11481148
{
1149-
char *data;
1149+
Py_buffer buf;
11501150
int len;
1151-
int count;
11521151
int sockstate;
11531152
int err;
11541153
int nonblocking;
@@ -1161,7 +1160,7 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
11611160
return NULL;
11621161
}
11631162

1164-
if (!PyArg_ParseTuple(args, "y#:write", &data, &count))
1163+
if (!PyArg_ParseTuple(args, "y*:write", &buf))
11651164
return NULL;
11661165

11671166
/* just in case the blocking state of the socket has been changed */
@@ -1173,24 +1172,24 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
11731172
if (sockstate == SOCKET_HAS_TIMED_OUT) {
11741173
PyErr_SetString(PySSLErrorObject,
11751174
"The write operation timed out");
1176-
return NULL;
1175+
goto error;
11771176
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
11781177
PyErr_SetString(PySSLErrorObject,
11791178
"Underlying socket has been closed.");
1180-
return NULL;
1179+
goto error;
11811180
} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
11821181
PyErr_SetString(PySSLErrorObject,
11831182
"Underlying socket too large for select().");
1184-
return NULL;
1183+
goto error;
11851184
}
11861185
do {
11871186
err = 0;
11881187
PySSL_BEGIN_ALLOW_THREADS
1189-
len = SSL_write(self->ssl, data, count);
1188+
len = SSL_write(self->ssl, buf.buf, buf.len);
11901189
err = SSL_get_error(self->ssl, len);
11911190
PySSL_END_ALLOW_THREADS
1192-
if(PyErr_CheckSignals()) {
1193-
return NULL;
1191+
if (PyErr_CheckSignals()) {
1192+
goto error;
11941193
}
11951194
if (err == SSL_ERROR_WANT_READ) {
11961195
sockstate =
@@ -1204,19 +1203,25 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
12041203
if (sockstate == SOCKET_HAS_TIMED_OUT) {
12051204
PyErr_SetString(PySSLErrorObject,
12061205
"The write operation timed out");
1207-
return NULL;
1206+
goto error;
12081207
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
12091208
PyErr_SetString(PySSLErrorObject,
12101209
"Underlying socket has been closed.");
1211-
return NULL;
1210+
goto error;
12121211
} else if (sockstate == SOCKET_IS_NONBLOCKING) {
12131212
break;
12141213
}
12151214
} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
1215+
1216+
PyBuffer_Release(&buf);
12161217
if (len > 0)
12171218
return PyLong_FromLong(len);
12181219
else
12191220
return PySSL_SetError(self, len, __FILE__, __LINE__);
1221+
1222+
error:
1223+
PyBuffer_Release(&buf);
1224+
return NULL;
12201225
}
12211226

12221227
PyDoc_STRVAR(PySSL_SSLwrite_doc,

0 commit comments

Comments
 (0)