diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-17 21:38:37 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-17 21:38:37 (GMT) |
commit | 5e98141f9f576934fe5635c66614f82be1ee0a9a (patch) | |
tree | a3b802f86e36244f1eccf469968ebab80026303d /Modules | |
parent | 9f9193ec375ed0f366b4aabfe210e7fdc3eb6b7d (diff) | |
download | cpython-5e98141f9f576934fe5635c66614f82be1ee0a9a.zip cpython-5e98141f9f576934fe5635c66614f82be1ee0a9a.tar.gz cpython-5e98141f9f576934fe5635c66614f82be1ee0a9a.tar.bz2 |
Issue #5421: Fix misleading error message when one of socket.sendto()'s
arguments has the wrong type. Patch by Nikita Vetoshkin.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/socketmodule.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index b04d246..5e911e0 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2647,17 +2647,28 @@ sock_sendto(PySocketSockObject *s, PyObject *args) Py_buffer pbuf; PyObject *addro; char *buf; - Py_ssize_t len; + Py_ssize_t len, arglen; sock_addr_t addrbuf; int addrlen, n = -1, flags, timeout; flags = 0; - if (!PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro)) { - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "y*iO:sendto", - &pbuf, &flags, &addro)) - return NULL; + arglen = PyTuple_Size(args); + switch (arglen) { + case 2: + PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro); + break; + case 3: + PyArg_ParseTuple(args, "y*iO:sendto", + &pbuf, &flags, &addro); + break; + default: + PyErr_Format(PyExc_TypeError, + "sendto() takes 2 or 3 arguments (%d given)", + arglen); } + if (PyErr_Occurred()) + return NULL; + buf = pbuf.buf; len = pbuf.len; |